sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1702210 - in /sis/branches/JDK8/core: sis-metadata/src/test/java/org/apache/sis/internal/jaxb/code/ sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/ sis-utility/src/test/java/org/apache/sis/internal/jaxb/gmd/ sis-utility/src/tes...
Date Thu, 10 Sep 2015 10:20:09 GMT
Author: desruisseaux
Date: Thu Sep 10 10:20:09 2015
New Revision: 1702210

URL: http://svn.apache.org/r1702210
Log:
Bug fix: unmarshalling of Enum value was lost if the name contains more than one word (SIS-297).

Added:
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gmd/EnumAdapterTest.java
      - copied, changed from r1702023, sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/code/EnumMarshallingTest.java
Modified:
    sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/code/EnumMarshallingTest.java
    sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/EnumAdapter.java
    sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java

Modified: sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/code/EnumMarshallingTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/code/EnumMarshallingTest.java?rev=1702210&r1=1702209&r2=1702210&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/code/EnumMarshallingTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/code/EnumMarshallingTest.java
[UTF-8] Thu Sep 10 10:20:09 2015
@@ -17,6 +17,8 @@
 package org.apache.sis.internal.jaxb.code;
 
 import java.util.Arrays;
+import java.util.EnumSet;
+import java.util.Collection;
 import javax.xml.bind.JAXBException;
 import org.opengis.metadata.identification.TopicCategory;
 import org.apache.sis.metadata.iso.identification.DefaultDataIdentification;
@@ -32,22 +34,24 @@ import static org.apache.sis.test.Assert
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.5
- * @version 0.5
+ * @version 0.6
  * @module
  */
 public final strictfp class EnumMarshallingTest extends XMLTestCase {
     /**
-     * Tests marshaling of a code list which is not in the list of standard codes.
+     * Tests (un)marshaling of an enumeration.
      *
-     * @throws JAXBException If an error occurred while marshaling the XML.
+     * @throws JAXBException If an error occurred while (un)marshaling the XML.
      */
     @Test
-    public void testEnums() throws JAXBException {
-        final DefaultDataIdentification id = new DefaultDataIdentification();
-        id.setTopicCategories(Arrays.asList(
+    public void testTopicCategories() throws JAXBException {
+        final Collection<TopicCategory> expected = Arrays.asList(
                 TopicCategory.OCEANS,
                 TopicCategory.ENVIRONMENT,
-                TopicCategory.HEALTH));
+                TopicCategory.IMAGERY_BASE_MAPS_EARTH_COVER);   // We need to test at least
one enum with many words.
+
+        final DefaultDataIdentification id = new DefaultDataIdentification();
+        id.setTopicCategories(expected);
 
         final String xml = marshal(id);
         assertXmlEquals(
@@ -56,12 +60,18 @@ public final strictfp class EnumMarshall
                 "    <gmd:MD_TopicCategoryCode>environment</gmd:MD_TopicCategoryCode>\n"
+
                 "  </gmd:topicCategory>\n" +
                 "  <gmd:topicCategory>\n" +
-                "    <gmd:MD_TopicCategoryCode>health</gmd:MD_TopicCategoryCode>\n"
+
+                "    <gmd:MD_TopicCategoryCode>imageryBaseMapsEarthCover</gmd:MD_TopicCategoryCode>\n"
+
                 "  </gmd:topicCategory>\n" +
                 "  <gmd:topicCategory>\n" +
                 "    <gmd:MD_TopicCategoryCode>oceans</gmd:MD_TopicCategoryCode>\n"
+
                 "  </gmd:topicCategory>\n" +
                 "</gmd:MD_DataIdentification>",
                 xml, "xmlns:*");
+        /*
+         * Unmarshall the above XML and verify that we find all the topic categories.
+         */
+        final Collection<TopicCategory> unmarshalled = unmarshal(DefaultDataIdentification.class,
xml).getTopicCategories();
+        assertInstanceOf("topicCategory", EnumSet.class, unmarshalled);
+        assertSetEquals(expected, unmarshalled);
     }
 }

Modified: sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/EnumAdapter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/EnumAdapter.java?rev=1702210&r1=1702209&r2=1702210&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/EnumAdapter.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/EnumAdapter.java
[UTF-8] Thu Sep 10 10:20:09 2015
@@ -54,7 +54,7 @@ public abstract class EnumAdapter<ValueT
      * @param  value The text in the XML element.
      * @return The presumed enumeration constant name.
      */
-    protected static String name(String value) {
+    protected static String name(final String value) {
         /*
          * Replace space ! " # $ % & ' ( ) * + , - . / punction characters by '_'.
          * For example this replace "in/out" by "IN_OUT" in ParameterDirection.
@@ -62,12 +62,20 @@ public abstract class EnumAdapter<ValueT
          * Note: we do not use codepoint API because this method is mostly for
          * GeoAPI programmatic constant names, which are written in English.
          */
-        final char[] ca = value.toCharArray();
-        for (int i=0; i<ca.length; i++) {
-            final char c = ca[i];
-            ca[i] = (c >= '0') ? Character.toUpperCase(c) : '_';
+        final int length = value.length();
+        final StringBuilder buffer = new StringBuilder(length);
+        for (int i=0; i<length; i++) {
+            char c = value.charAt(i);
+            if (c < '0') {
+                c = '_';
+            } else if (!Character.isUpperCase(c)) {
+                c = Character.toUpperCase(c);
+            } else if (i != 0) {
+                buffer.append('_');
+            }
+            buffer.append(c);
         }
-        return String.valueOf(ca);
+        return buffer.toString();
     }
 
     /**

Copied: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gmd/EnumAdapterTest.java
(from r1702023, sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/code/EnumMarshallingTest.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gmd/EnumAdapterTest.java?p2=sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gmd/EnumAdapterTest.java&p1=sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/code/EnumMarshallingTest.java&r1=1702023&r2=1702210&rev=1702210&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/test/java/org/apache/sis/internal/jaxb/code/EnumMarshallingTest.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gmd/EnumAdapterTest.java
[UTF-8] Thu Sep 10 10:20:09 2015
@@ -14,13 +14,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.sis.internal.jaxb.code;
+package org.apache.sis.internal.jaxb.gmd;
 
-import java.util.Arrays;
-import javax.xml.bind.JAXBException;
-import org.opengis.metadata.identification.TopicCategory;
-import org.apache.sis.metadata.iso.identification.DefaultDataIdentification;
-import org.apache.sis.xml.Namespaces;
 import org.apache.sis.test.XMLTestCase;
 import org.junit.Test;
 
@@ -28,40 +23,22 @@ import static org.apache.sis.test.Assert
 
 
 /**
- * Tests the XML marshaling of {@code Enum}.
+ * Tests the {@link EnumAdapter} class.
  *
  * @author  Martin Desruisseaux (Geomatys)
- * @since   0.5
- * @version 0.5
+ * @since   0.6
+ * @version 0.6
  * @module
  */
-public final strictfp class EnumMarshallingTest extends XMLTestCase {
+public final strictfp class EnumAdapterTest extends XMLTestCase {
     /**
-     * Tests marshaling of a code list which is not in the list of standard codes.
-     *
-     * @throws JAXBException If an error occurred while marshaling the XML.
+     * Tests the {@link EnumAdapter#name(String)} method.
      */
     @Test
-    public void testEnums() throws JAXBException {
-        final DefaultDataIdentification id = new DefaultDataIdentification();
-        id.setTopicCategories(Arrays.asList(
-                TopicCategory.OCEANS,
-                TopicCategory.ENVIRONMENT,
-                TopicCategory.HEALTH));
-
-        final String xml = marshal(id);
-        assertXmlEquals(
-                "<gmd:MD_DataIdentification xmlns:gmd=\"" + Namespaces.GMD + "\">\n"
+
-                "  <gmd:topicCategory>\n" +
-                "    <gmd:MD_TopicCategoryCode>environment</gmd:MD_TopicCategoryCode>\n"
+
-                "  </gmd:topicCategory>\n" +
-                "  <gmd:topicCategory>\n" +
-                "    <gmd:MD_TopicCategoryCode>health</gmd:MD_TopicCategoryCode>\n"
+
-                "  </gmd:topicCategory>\n" +
-                "  <gmd:topicCategory>\n" +
-                "    <gmd:MD_TopicCategoryCode>oceans</gmd:MD_TopicCategoryCode>\n"
+
-                "  </gmd:topicCategory>\n" +
-                "</gmd:MD_DataIdentification>",
-                xml, "xmlns:*");
+    public void testEnumAdapterName() {
+        assertEquals("IN_OUT",                        EnumAdapter.name("in/out"));
+        assertEquals("OCEANS",                        EnumAdapter.name("oceans"));
+        assertEquals("ENVIRONMENT",                   EnumAdapter.name("environment"));
+        assertEquals("IMAGERY_BASE_MAPS_EARTH_COVER", EnumAdapter.name("imageryBaseMapsEarthCover"));
     }
 }

Modified: sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1702210&r1=1702209&r2=1702210&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] Thu Sep 10 10:20:09 2015
@@ -142,6 +142,7 @@ 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.PropertyTypeTest.class,
+    org.apache.sis.internal.jaxb.gmd.EnumAdapterTest.class,
     org.apache.sis.internal.jaxb.gmd.LanguageCodeTest.class,
     org.apache.sis.internal.jaxb.gml.TimePeriodTest.class,
     org.apache.sis.internal.jaxb.gml.MeasureTest.class,



Mime
View raw message