sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1495602 - in /sis/branches/JDK7/core/sis-utility/src: main/java/org/apache/sis/internal/jaxb/ main/java/org/apache/sis/internal/jaxb/gco/ main/java/org/apache/sis/internal/jaxb/gmd/ test/java/org/apache/sis/internal/jaxb/ test/java/org/apa...
Date Fri, 21 Jun 2013 21:22:45 GMT
Author: desruisseaux
Date: Fri Jun 21 21:22:44 2013
New Revision: 1495602

URL: http://svn.apache.org/r1495602
Log:
Add tests.

Added:
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/XmlUtilitiesTest.java
  (with props)
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/MeasureTest.java
  (with props)
Modified:
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java
    sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListProxy.java
    sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java?rev=1495602&r1=1495601&r2=1495602&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/Context.java
[UTF-8] Fri Jun 21 21:22:44 2013
@@ -266,6 +266,7 @@ public final class Context extends Marsh
     /**
      * Returns the base URL of ISO 19139 (or other standards) schemas.
      * The valid values are documented in the {@link org.apache.sis.xml.XML#SCHEMAS} property.
+     * If the returned value is not empty, then this method guarantees it ends with {@code
'/'}.
      *
      * {@note This method is static for the convenience of performing the check for null
context.}
      *
@@ -273,19 +274,25 @@ public final class Context extends Marsh
      * @param  key One of the value documented in the "<cite>Map key</cite>"
column of
      *         {@link org.apache.sis.xml.XML#SCHEMAS}.
      * @param  defaultSchema The value to return if no schema is found for the given key.
-     * @return The base URL of the schema, or {@code null} if none were specified.
+     * @return The base URL of the schema, or an empty buffer if none were specified.
      */
-    public static String schema(final Context context, final String key, final String defaultSchema)
{
+    public static StringBuilder schema(final Context context, final String key, String defaultSchema)
{
+        final StringBuilder buffer = new StringBuilder(128);
         if (context != null) {
             final Map<String,String> schemas = context.schemas;
             if (schemas != null) {
                 final String schema = schemas.get(key);
                 if (schema != null) {
-                    return schema;
+                    defaultSchema = schema;
                 }
             }
         }
-        return defaultSchema;
+        buffer.append(defaultSchema);
+        final int length = buffer.length();
+        if (length != 0 && buffer.charAt(length - 1) != '/') {
+            buffer.append('/');
+        }
+        return buffer;
     }
 
     /**

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java?rev=1495602&r1=1495601&r2=1495602&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gco/Measure.java
[UTF-8] Fri Jun 21 21:22:44 2013
@@ -100,8 +100,8 @@ public final class Measure {
         } else if (unit.equals(NonSI.PIXEL)) {
             symbol = "pixel";
         } else {
-            symbol = CodeListProxy.schema(Context.schema(Context.current(), "gmd", CodeListProxy.DEFAULT_SCHEMA),
-                            "resources/uom", "gmxUom.xml", "xpointer(//*[@gml:id='" + unit
+ "'])");
+            symbol = Context.schema(Context.current(), "gmd", CodeListProxy.DEFAULT_SCHEMA)
+                    .append("resources/uom/gmxUom.xml#xpointer(//*[@gml:id='").append(unit).append("'])").toString();
         }
         return symbol;
     }

Modified: sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListProxy.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListProxy.java?rev=1495602&r1=1495601&r2=1495602&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListProxy.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/internal/jaxb/gmd/CodeListProxy.java
[UTF-8] Fri Jun 21 21:22:44 2013
@@ -50,21 +50,8 @@ public final class CodeListProxy {
     public static final String DEFAULT_SCHEMA = "http://schemas.opengis.net/iso/19139/20070417/";
 
     /**
-     * Returns the URL to given code list in the given XML file.
-     *
-     * @param  context    The current (un)marshalling context, or {@code null} if none.
-     * @param  file       The XML file, either {@code "gmxCodelists.xml"} or {@code "ML_gmxCodelists.xml"}.
-     * @param  identifier The UML identifier of the code list.
-     * @return The URL to the given code list in the given schema.
-     */
-    private static String schema(final Context context, final String file, final String identifier)
{
-        return schema(Context.schema(context, "gmd", DEFAULT_SCHEMA),
-                "resources/Codelist", file, identifier);
-    }
-
-    /**
-     * Returns the URL to a given code list in the given XML file. This method concatenates
-     * the base schema URL with the given directory, file and identifier.
+     * Returns the URL to a given code list in the given XML file.
+     * This method concatenates the base schema URL with the given file and identifier.
      * Some examples of strings returned by this method are:
      *
      * <ul>
@@ -73,23 +60,14 @@ public final class CodeListProxy {
      *   <li>{@code "http://schemas.opengis.net/iso/19139/20070417/resources/Codelist/gmxCodelists.xml#CI_OnLineFunctionCode"}</li>
      * </ul>
      *
-     * @param  schema     The schema, typically as a result of a call to
-     *                    {@link Context#schema(Context, String, String)}.
-     * @param  directory  The directory to concatenate, for example {@code "resources/uom"}
-     *                    or {@code "resources/Codelist"} (<strong>no trailing {@code
'/'}</strong>).
-     * @param  file       The XML file, for example {@code "gmxUom.xml"}, {@code "gmxCodelists.xml"}
-     *                    or {@code "ML_gmxCodelists.xml"} (<strong>no trailing {@code
'#'}</strong>).
+     * @param  context    The current (un)marshalling context, or {@code null} if none.
+     * @param  file       The XML file, either {@code "gmxCodelists.xml"} or {@code "ML_gmxCodelists.xml"}.
      * @param  identifier The UML identifier of the code list.
      * @return The URL to the given code list in the given schema.
      */
-    public static String schema(final String schema, final String directory, final String
file, final String identifier) {
-        final StringBuilder buffer = new StringBuilder(128);
-        buffer.append(schema);
-        final int length = buffer.length();
-        if (length != 0 && buffer.charAt(length - 1) != '/') {
-            buffer.append('/');
-        }
-        return buffer.append(directory).append('/').append(file).append('#').append(identifier).toString();
+    private static String schema(final Context context, final String file, final String identifier)
{
+        return Context.schema(context, "gmd", DEFAULT_SCHEMA).append("resources/Codelist/")
+                .append(file).append('#').append(identifier).toString();
     }
 
     /**

Added: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/XmlUtilitiesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/XmlUtilitiesTest.java?rev=1495602&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/XmlUtilitiesTest.java
(added)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/XmlUtilitiesTest.java
[UTF-8] Fri Jun 21 21:22:44 2013
@@ -0,0 +1,55 @@
+/*
+ * 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.internal.jaxb;
+
+import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
+import javax.xml.datatype.XMLGregorianCalendar;
+import javax.xml.datatype.DatatypeConfigurationException;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+import static javax.xml.datatype.DatatypeConstants.FIELD_UNDEFINED;
+
+
+/**
+ * Test {@link XmlUtilities}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-3.17)
+ * @version 0.3
+ * @module
+ */
+public final strictfp class XmlUtilitiesTest extends TestCase {
+    /**
+     * Tests the {@link XmlUtilities#toXML} method.
+     * This test arbitrarily uses the CET timezone.
+     *
+     * @throws DatatypeConfigurationException Should never happen.
+     */
+    @Test
+    public void testToXML() throws DatatypeConfigurationException {
+        final Context context = new Context(0, Locale.FRENCH, TimeZone.getTimeZone("CET"),
null, null, null, null, null);
+        final XMLGregorianCalendar cal = XmlUtilities.toXML(context, new Date(1230786000000L));
+        assertEquals("2009-01-01T06:00:00.000+01:00", cal.toString());
+
+        cal.setMillisecond(FIELD_UNDEFINED);
+        assertEquals("2009-01-01T06:00:00+01:00", cal.toString());
+    }
+}

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

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

Added: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/MeasureTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/MeasureTest.java?rev=1495602&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/MeasureTest.java
(added)
+++ sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/MeasureTest.java
[UTF-8] Fri Jun 21 21:22:44 2013
@@ -0,0 +1,59 @@
+/*
+ * 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.internal.jaxb.gco;
+
+import java.net.URISyntaxException;
+import javax.measure.unit.SI;
+import javax.measure.unit.NonSI;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+
+/**
+ * Test {@link Measure}.
+ *
+ * @author  Martin Desruisseaux (Geomatys)
+ * @since   0.3 (derived from geotk-3.10)
+ * @version 0.3
+ * @module
+ */
+public final strictfp class MeasureTest extends TestCase {
+    /**
+     * Tests the {@link Measure#setUOM(String)}.
+     *
+     * @throws URISyntaxException Should not happen.
+     */
+    @Test
+    public void testSetUOM() throws URISyntaxException {
+        final Measure measure = new Measure();
+        measure.setUOM("http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#m");
+        assertEquals(SI.METRE, measure.unit);
+        assertEquals("http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='m'])",
measure.getUOM());
+
+        measure.unit = null;
+        measure.setUOM("../uom/ML_gmxUom.xsd#xpointer(//*[@gml:id='deg'])");
+        assertEquals(NonSI.DEGREE_ANGLE, measure.unit);
+        assertEquals("http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='deg'])",
measure.getUOM());
+
+        measure.unit = null;
+        measure.setUOM("http://my.big.org/units/kg");
+        assertEquals(SI.KILOGRAM, measure.unit);
+        assertEquals("http://schemas.opengis.net/iso/19139/20070417/resources/uom/gmxUom.xml#xpointer(//*[@gml:id='kg'])",
measure.getUOM());
+    }
+}

Propchange: sis/branches/JDK7/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gco/MeasureTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

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

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=1495602&r1=1495601&r2=1495602&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] Fri Jun 21 21:22:44 2013
@@ -113,9 +113,11 @@ import org.junit.BeforeClass;
     org.apache.sis.xml.NilReasonTest.class,
     org.apache.sis.xml.OGCNamespacePrefixMapperTest.class,
     org.apache.sis.xml.MarshallerPoolTest.class,
+    org.apache.sis.internal.jaxb.XmlUtilitiesTest.class,
     org.apache.sis.internal.jaxb.IdentifierMapAdapterTest.class,
     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
 })
 public final strictfp class UtilityTestSuite extends TestSuite {



Mime
View raw message