sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1497130 - in /sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis: test/mock/IdentifiedObjectMock.java test/mock/package-info.java test/suite/UtilityTestSuite.java util/iso/NameMarshallingTest.java
Date Wed, 26 Jun 2013 22:03:57 GMT
Author: desruisseaux
Date: Wed Jun 26 22:03:57 2013
New Revision: 1497130

URL: http://svn.apache.org/r1497130
Log:
Test GenericName marshalling.

Added:
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/IdentifiedObjectMock.java
  (with props)
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java
  (with props)
Modified:
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/package-info.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java

Added: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/IdentifiedObjectMock.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/IdentifiedObjectMock.java?rev=1497130&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/IdentifiedObjectMock.java
(added)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/IdentifiedObjectMock.java
[UTF-8] Wed Jun 26 22:03:57 2013
@@ -0,0 +1,118 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.test.mock;
+
+import java.util.Set;
+import java.util.Collection;
+import java.util.Collections;
+import org.opengis.util.GenericName;
+import org.opengis.util.InternationalString;
+import org.opengis.referencing.IdentifiedObject;
+import org.opengis.referencing.ReferenceIdentifier;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+import org.apache.sis.internal.jaxb.gco.GO_GenericName;
+
+
+/**
+ * A dummy implementation of {@link IdentifiedObject} with minimal XML (un)marshalling capability.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3
+ * @version 0.3
+ * @module
+ */
+@XmlType(name = "IdentifiedObjectType")
+@XmlRootElement(name = "IO_IdentifiedObject")
+public final strictfp class IdentifiedObjectMock implements IdentifiedObject {
+    /**
+     * The alias to (un)marshal to XML
+     */
+    @XmlElement
+    @XmlJavaTypeAdapter(GO_GenericName.class)
+    public GenericName alias;
+
+    /**
+     * Creates an initially empty identified object.
+     * This constructor is required by JAXB.
+     */
+    public IdentifiedObjectMock() {
+    }
+
+    /**
+     * Creates an initially empty identified object of the given alias.
+     * Callers are free to assign new value to the {@link #alias} field directly.
+     *
+     * @param alias The initial {@link #alias} value (can be {@code null}).
+     */
+    public IdentifiedObjectMock(final GenericName alias) {
+        this.alias = alias;
+    }
+
+    /**
+     * Returns the name (currently null).
+     *
+     * @return The name of this object.
+     */
+    @Override
+    public ReferenceIdentifier getName() {
+        return null;
+    }
+
+    /**
+     * Returns {@link #alias} in an unmodifiable collection.
+     *
+     * @return {@link #alias} singleton.
+     */
+    @Override
+    public Collection<GenericName> getAlias() {
+        return Collections.singleton(alias);
+    }
+
+    /**
+     * Returns the identifiers (currently null).
+     *
+     * @return The identifiers of this object.
+     */
+    @Override
+    public Set<ReferenceIdentifier> getIdentifiers() {
+        return null;
+    }
+
+    /**
+     * Returns the remarks (currently null).
+     *
+     * @return The remarks associated to this object.
+     */
+    @Override
+    public InternationalString getRemarks() {
+        return null;
+    }
+
+    /**
+     * Returns the WKT representation (currently none).
+     *
+     * @return The WLK representation of this object.
+     * @throws UnsupportedOperationException If there is no WKT representation.
+     */
+    @Override
+    public String toWKT() throws UnsupportedOperationException {
+        throw new UnsupportedOperationException();
+    }
+}

Propchange: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/IdentifiedObjectMock.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/IdentifiedObjectMock.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/package-info.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/package-info.java?rev=1497130&r1=1497129&r2=1497130&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/package-info.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/mock/package-info.java
[UTF-8] Wed Jun 26 22:03:57 2013
@@ -17,10 +17,32 @@
 
 /**
  * Provides objects that simulate the behavior of complex or unavailable real objects.
+ * Mocks are often used as a replacement for objects to be defined only in dependant modules.
+ *
+ * <p>Objects defined in this package are only for SIS testing purpose any many change
+ * in any future version without notice.</p>
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3
  * @version 0.3
  * @module
  */
+@XmlSchema(elementFormDefault = XmlNsForm.QUALIFIED, namespace = Namespaces.GML, xmlns =
{
+    @XmlNs(prefix = "gml", namespaceURI = Namespaces.GML),
+    @XmlNs(prefix = "gco", namespaceURI = Namespaces.GCO)
+})
+@XmlAccessorType(XmlAccessType.NONE)
+@XmlJavaTypeAdapters({
+    @XmlJavaTypeAdapter(GO_GenericName.class)
+})
 package org.apache.sis.test.mock;
+
+import javax.xml.bind.annotation.XmlNs;
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlSchema;
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters;
+import org.apache.sis.internal.jaxb.gco.GO_GenericName;
+import org.apache.sis.xml.Namespaces;

Modified: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1497130&r1=1497129&r2=1497130&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] Wed Jun 26 22:03:57 2013
@@ -118,7 +118,8 @@ import org.junit.BeforeClass;
     org.apache.sis.internal.jaxb.IdentifierMapWithSpecialCasesTest.class,
     org.apache.sis.internal.jaxb.gco.StringAdapterTest.class,
     org.apache.sis.internal.jaxb.gco.MeasureTest.class,
-    org.apache.sis.internal.jaxb.gco.PropertyTypeTest.class
+    org.apache.sis.internal.jaxb.gco.PropertyTypeTest.class,
+    org.apache.sis.util.iso.NameMarshallingTest.class
 })
 public final strictfp class UtilityTestSuite extends TestSuite {
     /**

Added: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java?rev=1497130&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java
(added)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java
[UTF-8] Wed Jun 26 22:03:57 2013
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.util.iso;
+
+import java.io.StringWriter;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import org.opengis.util.GenericName;
+import org.opengis.util.NameFactory;
+import org.apache.sis.internal.system.DefaultFactories;
+import org.apache.sis.xml.MarshallerPool;
+import org.apache.sis.test.mock.IdentifiedObjectMock;
+import org.apache.sis.test.XMLTestCase;
+import org.apache.sis.test.DependsOn;
+import org.junit.AfterClass;
+import org.junit.Test;
+
+import static org.apache.sis.test.Assert.*;
+
+
+/**
+ * Tests the XML marshalling of generic names.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-3.00)
+ * @version 0.3
+ * @module
+ */
+@DependsOn(DefaultNameFactoryTest.class)
+public final strictfp class NameMarshallingTest extends XMLTestCase {
+    /**
+     * The JAXB context, created when first needed.
+     */
+    private static MarshallerPool pool;
+
+    /**
+     * Returns the XML representation of the given name, wrapped
+     * in a mock {@code <gml:IO_IdentifiedObject>} element.
+     */
+    private static String marshall(final GenericName name) throws JAXBException {
+        if (pool == null) {
+            pool = new MarshallerPool(JAXBContext.newInstance(IdentifiedObjectMock.class),
null);
+        }
+        final Marshaller marshaller = pool.acquireMarshaller();
+        final StringWriter out = new StringWriter();
+        marshaller.marshal(new IdentifiedObjectMock(name), out);
+        pool.recycle(marshaller);
+        return out.toString();
+    }
+
+    /**
+     * Tests XML of a {@link org.opengis.util.LocalName}.
+     *
+     * @throws JAXBException Should not happen.
+     */
+    @Test
+    public void testLocalName() throws JAXBException {
+        final NameFactory factory = DefaultFactories.NAMES;
+        final GenericName name = factory.createLocalName(null, "An ordinary local name");
+        assertEquals("An ordinary local name", name.toString());
+        final String expected =
+                "<gml:IO_IdentifiedObject>\n" +
+                "  <gml:alias>\n" +
+                "    <gco:LocalName>An ordinary local name</gco:LocalName>\n"
+
+                "  </gml:alias>\n" +
+                "</gml:IO_IdentifiedObject>\n";
+        final String actual = marshall(name);
+        assertXmlEquals(expected, actual, "xmlns:*", "xsi:schemaLocation");
+    }
+
+    /**
+     * Tests XML of a {@link org.opengis.util.LocalName} with {@code &} symbol.
+     *
+     * @throws JAXBException Should not happen.
+     */
+    @Test
+    public void testLocalNameWithAmp() throws JAXBException {
+        final NameFactory factory = DefaultFactories.NAMES;
+        final GenericName name = factory.createLocalName(null, "A name with & and >
and <.");
+        assertEquals("A name with & and > and <.", name.toString());
+        final String expected =
+                "<gml:IO_IdentifiedObject>\n" +
+                "  <gml:alias>\n" +
+                "      <gco:LocalName>A name with &amp; and &gt; and &lt;.</gco:LocalName>\n"
+
+                "  </gml:alias>\n" +
+                "</gml:IO_IdentifiedObject>\n";
+        final String actual = marshall(name);
+        assertXmlEquals(expected, actual, "xmlns:*", "xsi:schemaLocation");
+    }
+
+    /**
+     * Tests XML of a {@link org.opengis.util.TypeName}.
+     *
+     * @throws JAXBException Should not happen.
+     */
+    @Test
+    public void testTypeName() throws JAXBException {
+        final NameFactory factory = DefaultFactories.NAMES;
+        final GenericName name = factory.createTypeName(null, "An other local name");
+        assertEquals("An other local name", name.toString());
+        final String expected =
+                "<gml:IO_IdentifiedObject>\n" +
+                "  <gml:alias>\n" +
+                "    <gco:TypeName>\n" +
+                "      <gco:aName>\n" +
+                "        <gco:CharacterString>An other local name</gco:CharacterString>\n"
+
+                "      </gco:aName>\n" +
+                "    </gco:TypeName>\n" +
+                "  </gml:alias>\n" +
+                "</gml:IO_IdentifiedObject>\n";
+        final String actual = marshall(name);
+        assertXmlEquals(expected, actual, "xmlns:*", "xsi:schemaLocation");
+    }
+
+    /**
+     * Tests XML of a {@link org.opengis.util.ScopedName}.
+     *
+     * @throws JAXBException Should not happen.
+     */
+    @Test
+    @org.junit.Ignore("Expected XML seems wrong.")
+    public void testScopedName() throws JAXBException {
+        final NameFactory factory = DefaultFactories.NAMES;
+        final GenericName name = factory.createGenericName(null, "myScope","myName");
+        assertEquals("myScope:myName", name.toString());
+        final String expected =
+                "<gml:IO_IdentifiedObject>\n" +
+                "  <gml:alias>\n" +
+                "    <gco:ScopedName>\n" +
+                "      <gco:parsedName>myScope</gco:parsedName>\n" +
+                "      <gco:parsedName>myName</gco:parsedName>\n" +
+                "    </gco:ScopedName>\n" +
+                "  </gml:alias>\n" +
+                "</gml:IO_IdentifiedObject>\n";
+        final String actual = marshall(name);
+        assertXmlEquals(expected, actual, "xmlns:*", "xsi:schemaLocation");
+    }
+
+    /**
+     * Invoked by JUnit after the execution of every tests in order to dispose
+     * the {@link MarshallerPool} instance used internally by this class.
+     */
+    @AfterClass
+    public static void disposeMarshallerPool() {
+        pool = null;
+    }
+}

Propchange: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain;charset=UTF-8



Mime
View raw message