sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1615109 [4/4] - in /sis/branches/JDK6: ./ core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/code/ core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gml/ core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/met...
Date Fri, 01 Aug 2014 14:19:19 GMT
Copied: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/xml/LegacyCodes.java
(from r1615101, sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/LegacyCodes.java)
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/xml/LegacyCodes.java?p2=sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/xml/LegacyCodes.java&p1=sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/LegacyCodes.java&r1=1615101&r2=1615109&rev=1615109&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-utility/src/main/java/org/apache/sis/xml/LegacyCodes.java [UTF-8]
(original)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/xml/LegacyCodes.java [UTF-8]
Fri Aug  1 14:19:16 2014
@@ -50,14 +50,16 @@ final class LegacyCodes {
     static final Map<String,String> IANA_TO_LEGACY, LEGACY_TO_IANA;
     static {
         final Properties codes = new Properties();
-        try (InputStream in = Metadata.class.getResourceAsStream("2003/charset-codes.properties"))
{
+        final InputStream in = Metadata.class.getResourceAsStream("2003/charset-codes.properties");
+        try {
             codes.load(in);
+            in.close();
         } catch (IOException e) {
             Logging.unexpectedException(ValueConverter.class, "toCharset[Code]", e);
         }
         final int capacity = Containers.hashMapCapacity(codes.size());
-        IANA_TO_LEGACY = new HashMap<>(capacity);
-        LEGACY_TO_IANA = new HashMap<>(capacity);
+        IANA_TO_LEGACY = new HashMap<String,String>(capacity);
+        LEGACY_TO_IANA = new HashMap<String,String>(capacity);
         for (final Map.Entry<Object,Object> entry : codes.entrySet()) {
             final String legacy = ((String) entry.getKey()).intern();
             final String name   = ((String) entry.getValue()).intern();

Modified: sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/xml/ValueConverter.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/xml/ValueConverter.java?rev=1615109&r1=1615108&r2=1615109&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/xml/ValueConverter.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/main/java/org/apache/sis/xml/ValueConverter.java
[UTF-8] Fri Aug  1 14:19:16 2014
@@ -23,6 +23,8 @@ import java.net.MalformedURLException;
 import java.util.MissingResourceException;
 import java.util.Locale;
 import java.util.UUID;
+import java.nio.charset.Charset;
+import java.nio.charset.IllegalCharsetNameException;
 import javax.measure.unit.Unit;
 import org.apache.sis.measure.Units;
 import org.apache.sis.util.Locales;
@@ -63,7 +65,7 @@ import static org.apache.sis.util.CharSe
  *
  * @author Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.07)
- * @version 0.4
+ * @version 0.5
  * @module
  */
 public class ValueConverter {
@@ -179,6 +181,69 @@ public class ValueConverter {
     }
 
     /**
+     * Converts the given character set to a code.
+     *
+     * <p>The default implementation first invokes {@link Charset#name()}. Then if
marshalling to ISO 19139:2007,
+     * this method converts the <a href="http://www.iana.org/assignments/character-sets">IANA</a>
name to a
+     * ISO 19115:2003 {@code MD_CharacterSetCode} using the following equivalence table:</p>
+     *
+     * <table class="sis">
+     *   <caption>IANA to ISO 19115:2003 character set code</caption>
+     *   <tr>
+     *     <td><table class="compact" summary="IANA to ISO 19115:2003">
+     *       <tr><td style="width: 90px"><b>IANA</b></td><td><b>ISO
19115:2003</b></td></tr>
+     *       <tr><td>{@code ISO-8859-1}</td>  <td>{@code 8859part1}</td></tr>
+     *       <tr><td>{@code ISO-8859-2}</td>  <td>{@code 8859part2}</td></tr>
+     *       <tr><td>{@code ISO-8859-3}</td>  <td>{@code 8859part3}</td></tr>
+     *       <tr><td>{@code ISO-8859-4}</td>  <td>{@code 8859part4}</td></tr>
+     *       <tr><td>{@code ISO-8859-5}</td>  <td>{@code 8859part5}</td></tr>
+     *       <tr><td>{@code ISO-8859-6}</td>  <td>{@code 8859part6}</td></tr>
+     *       <tr><td>{@code ISO-8859-7}</td>  <td>{@code 8859part7}</td></tr>
+     *       <tr><td>{@code ISO-8859-8}</td>  <td>{@code 8859part8}</td></tr>
+     *       <tr><td>{@code ISO-8859-9}</td>  <td>{@code 8859part9}</td></tr>
+     *       <tr><td>{@code ISO-8859-10}</td> <td>{@code 8859part10}</td></tr>
+     *       <tr><td>{@code ISO-8859-11}</td> <td>{@code 8859part11}</td></tr>
+     *       <tr><td>{@code ISO-8859-12}</td> <td>{@code 8859part12}</td></tr>
+     *       <tr><td>{@code ISO-8859-13}</td> <td>{@code 8859part13}</td></tr>
+     *       <tr><td>{@code ISO-8859-14}</td> <td>{@code 8859part14}</td></tr>
+     *       <tr><td>{@code ISO-8859-15}</td> <td>{@code 8859part15}</td></tr>
+     *       <tr><td>{@code ISO-8859-16}</td> <td>{@code 8859part16}</td></tr>
+     *     </table></td>
+     *     <td class="sep"><table class="compact" summary="IANA to ISO 19115:2003">
+     *       <tr><td style="width: 90px"><b>IANA</b></td><td><b>ISO
19115:2003</b></td></tr>
+     *       <tr><td>{@code UCS-2}</td>     <td>{@code ucs2}</td></tr>
+     *       <tr><td>{@code UCS-4}</td>     <td>{@code ucs4}</td></tr>
+     *       <tr><td>{@code UTF-7}</td>     <td>{@code utf7}</td></tr>
+     *       <tr><td>{@code UTF-8}</td>     <td>{@code utf8}</td></tr>
+     *       <tr><td>{@code UTF-16}</td>    <td>{@code utf16}</td></tr>
+     *       <tr><td>{@code JIS_X0201}</td> <td>{@code jis}</td></tr>
+     *       <tr><td>{@code Shift_JIS}</td> <td>{@code shiftJIS}</td></tr>
+     *       <tr><td>{@code EUC-JP}</td>    <td>{@code eucJP}</td></tr>
+     *       <tr><td>{@code US-ASCII}</td>  <td>{@code usAscii}</td></tr>
+     *       <tr><td>{@code EBCDIC}</td>    <td>{@code ebcdic}</td></tr>
+     *       <tr><td>{@code EUC-KR}</td>    <td>{@code eucKR}</td></tr>
+     *       <tr><td>{@code Big5}</td>      <td>{@code big5}</td></tr>
+     *       <tr><td>{@code GB2312}</td>    <td>{@code GB2312}</td></tr>
+     *     </table></td>
+     *   </tr>
+     * </table>
+     *
+     * @param  context Context (GML version, locale, <i>etc.</i>) of the (un)marshalling
process.
+     * @param  value The locale to convert to a character set code, or {@code null}.
+     * @return The country code, or {@code null} if the given value was null.
+     *
+     * @see Charset#name()
+     *
+     * @since 0.5
+     */
+    public String toCharsetCode(final MarshalContext context, final Charset value) {
+        if (value != null) {
+            return LegacyCodes.fromIANA(value.name());
+        }
+        return null;
+    }
+
+    /**
      * Converts the given string to a locale. The string is the language code either as the
2
      * letters or the 3 letters ISO code. It can optionally be followed by the {@code '_'}
      * character and the country code (again either as 2 or 3 letters), optionally followed
@@ -206,6 +271,36 @@ public class ValueConverter {
     }
 
     /**
+     * Converts the given string to a character set. The string can be either a
+     * <a href="http://www.iana.org/assignments/character-sets">IANA</a> identifier,
+     * or one of the ISO 19115:2003 {@code MD_CharacterSetCode} identifier.
+     *
+     * @param  context Context (GML version, locale, <i>etc.</i>) of the (un)marshalling
process.
+     * @param  value The string to convert to a character set, or {@code null}.
+     * @return The converted character set, or {@code null} if the given value was null or
empty, or
+     *         if an exception was thrown and {@code exceptionOccured(…)} returned {@code
true}.
+     * @throws IllegalCharsetNameException If the given string can not be converted to a
character set.
+     *
+     * @see Charset#forName(String)
+     *
+     * @since 0.5
+     */
+    public Charset toCharset(final MarshalContext context, String value) throws IllegalCharsetNameException
{
+        value = trimWhitespaces(value);
+        if (value != null && !value.isEmpty()) {
+            value = LegacyCodes.toIANA(value);
+            try {
+                return Charset.forName(value);
+            } catch (IllegalCharsetNameException e) {
+                if (!exceptionOccured(context, value, String.class, Charset.class, e)) {
+                    throw e;
+                }
+            }
+        }
+        return null;
+    }
+
+    /**
      * Converts the given string to a unit. The default implementation is as below, omitting
      * the check for null value and the call to {@link #exceptionOccured exceptionOccured(…)}
      * in case of error:

Modified: sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gml/TimePeriodTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gml/TimePeriodTest.java?rev=1615109&r1=1615101&r2=1615109&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gml/TimePeriodTest.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/internal/jaxb/gml/TimePeriodTest.java
[UTF-8] Fri Aug  1 14:19:16 2014
@@ -71,7 +71,7 @@ public final strictfp class TimePeriodTe
      */
     @BeforeClass
     public static void createMarshallerPool() throws JAXBException {
-        final Map<String,Object> properties = new HashMap<>(4);
+        final Map<String,Object> properties = new HashMap<String,Object>(4);
         assertNull(properties.put(XML.LOCALE, Locale.FRANCE));
         assertNull(properties.put(XML.TIMEZONE, "CET"));
         pool = new MarshallerPool(JAXBContext.newInstance(TimeInstant.class, TimePeriod.class),
properties);

Modified: sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/test/mock/MetadataMock.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/test/mock/MetadataMock.java?rev=1615109&r1=1615108&r2=1615109&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/test/mock/MetadataMock.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/test/mock/MetadataMock.java
[UTF-8] Fri Aug  1 14:19:16 2014
@@ -19,6 +19,7 @@ package org.apache.sis.test.mock;
 import java.util.Date;
 import java.util.Locale;
 import java.util.Collection;
+import java.nio.charset.Charset;
 import javax.xml.bind.annotation.XmlElement;
 import javax.xml.bind.annotation.XmlRootElement;
 import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
@@ -31,7 +32,6 @@ import org.opengis.metadata.citation.Res
 import org.opengis.metadata.constraint.Constraints;
 import org.opengis.metadata.content.ContentInformation;
 import org.opengis.metadata.distribution.Distribution;
-import org.opengis.metadata.identification.CharacterSet;
 import org.opengis.metadata.identification.Identification;
 import org.opengis.metadata.maintenance.MaintenanceInformation;
 import org.opengis.metadata.maintenance.ScopeCode;
@@ -100,7 +100,7 @@ public final strictfp class MetadataMock
      * @return {@code null}.
      */
     @Override
-    public CharacterSet getCharacterSet() {
+    public Charset getCharacterSet() {
         return null;
     }
 

Modified: sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java?rev=1615109&r1=1615108&r2=1615109&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/test/suite/UtilityTestSuite.java
[UTF-8] Fri Aug  1 14:19:16 2014
@@ -125,6 +125,7 @@ import org.junit.BeforeClass;
     // XML most basic types.
     org.apache.sis.xml.XLinkTest.class,
     org.apache.sis.xml.NilReasonTest.class,
+    org.apache.sis.xml.LegacyCodesTest.class,
     org.apache.sis.xml.ValueConverterTest.class,
     org.apache.sis.xml.OGCNamespacePrefixMapperTest.class,
     org.apache.sis.xml.MarshallerPoolTest.class,
@@ -135,6 +136,7 @@ import org.junit.BeforeClass;
     org.apache.sis.internal.jaxb.gco.MeasureTest.class,
     org.apache.sis.internal.jaxb.gco.PropertyTypeTest.class,
     org.apache.sis.internal.jaxb.gmd.LanguageCodeTest.class,
+    org.apache.sis.internal.jaxb.gml.TimePeriodTest.class,
     org.apache.sis.util.iso.NameMarshallingTest.class
 })
 public final strictfp class UtilityTestSuite extends TestSuite {

Modified: sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java?rev=1615109&r1=1615108&r2=1615109&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/util/iso/NameMarshallingTest.java
[UTF-8] Fri Aug  1 14:19:16 2014
@@ -24,6 +24,7 @@ import org.opengis.util.TypeName;
 import org.opengis.util.LocalName;
 import org.opengis.util.GenericName;
 import org.opengis.util.NameFactory;
+import org.opengis.util.NameSpace;
 import org.apache.sis.internal.system.DefaultFactories;
 import org.apache.sis.xml.Namespaces;
 import org.apache.sis.xml.MarshallerPool;
@@ -42,7 +43,7 @@ import static org.apache.sis.test.Assert
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.3 (derived from geotk-3.00)
- * @version 0.3
+ * @version 0.5
  * @module
  */
 @DependsOn(DefaultNameFactoryTest.class)
@@ -97,7 +98,7 @@ public final strictfp class NameMarshall
                 "</gml:IO_IdentifiedObject>\n";
         final String actual = marshal(name);
         assertXmlEquals(expected, actual, "xmlns:*");
-        assertEquals(name, unmarshall(actual));
+        assertEquals(name, unmarshall(expected));
     }
 
     /**
@@ -120,7 +121,31 @@ public final strictfp class NameMarshall
                 "</gml:IO_IdentifiedObject>\n";
         final String actual = marshal(name);
         assertXmlEquals(expected, actual, "xmlns:*");
-        assertEquals(name, unmarshall(actual));
+        assertEquals(name, unmarshall(expected));
+    }
+
+    /**
+     * Tests XML of a {@link LocalName} with a scope.
+     *
+     * @throws JAXBException Should not happen.
+     */
+    @Test
+    @DependsOnMethod("testLocalName")
+    public void testLocalNameWithScope() throws JAXBException {
+        final NameFactory factory = DefaultFactories.SIS_NAMES;
+        final NameSpace scope = factory.createNameSpace(factory.createLocalName(null, "A
code space"), null);
+        final LocalName name = factory.createLocalName(scope, "A name in a scope");
+        assertEquals("A name in a scope", name.toString());
+        final String expected =
+                "<gml:IO_IdentifiedObject xmlns:gml=\"" + Namespaces.GML + '"' +
+                                        " xmlns:gco=\"" + Namespaces.GCO + "\">\n" +
+                "  <gml:alias>\n" +
+                "    <gco:LocalName codeSpace=\"A code space\">A name in a scope</gco:LocalName>\n"
+
+                "  </gml:alias>\n" +
+                "</gml:IO_IdentifiedObject>\n";
+        final String actual = marshal(name);
+        assertXmlEquals(expected, actual, "xmlns:*");
+        assertEquals(name, unmarshall(expected));
     }
 
     /**
@@ -146,7 +171,7 @@ public final strictfp class NameMarshall
                 "</gml:IO_IdentifiedObject>\n";
         final String actual = marshal(name);
         assertXmlEquals(expected, actual, "xmlns:*");
-        assertEquals(name, unmarshall(actual));
+        assertEquals(name, unmarshall(expected));
     }
 
     /**
@@ -168,7 +193,7 @@ public final strictfp class NameMarshall
                 "</gml:IO_IdentifiedObject>\n";
         final String actual = marshal(name);
         assertXmlEquals(expected, actual, "xmlns:*");
-        assertEquals(name, unmarshall(actual));
+        assertEquals(name, unmarshall(expected));
     }
 
     /**

Modified: sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/util/iso/TypesTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/util/iso/TypesTest.java?rev=1615109&r1=1615108&r2=1615109&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/util/iso/TypesTest.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/util/iso/TypesTest.java
[UTF-8] Fri Aug  1 14:19:16 2014
@@ -26,7 +26,6 @@ import org.opengis.metadata.citation.Add
 import org.opengis.metadata.citation.Citation;
 import org.opengis.metadata.citation.OnLineFunction;
 import org.opengis.metadata.content.ImagingCondition;
-import org.opengis.metadata.identification.CharacterSet;
 import org.opengis.metadata.service.ParameterDirection;
 import org.opengis.referencing.datum.Datum;
 import org.opengis.referencing.cs.AxisDirection;
@@ -131,12 +130,12 @@ public final strictfp class TypesTest ex
      */
     @Test
     public void testGetDescription() {
-        final InternationalString description = Types.getDescription(CharacterSet.class);
-        assertEquals("Name of the character coding standard used in the resource.",
+        final InternationalString description = Types.getDescription(OnLineFunction.class);
+        assertEquals("Function performed by the resource.",
                 description.toString(Locale.ROOT));
-        assertEquals("Name of the character coding standard used in the resource.",
+        assertEquals("Function performed by the resource.",
                 description.toString(Locale.ENGLISH));
-        assertEquals("Jeu de caractères.",
+        assertEquals("Fonctionnalité offerte par la ressource.",
                 description.toString(Locale.FRENCH));
     }
 
@@ -156,12 +155,12 @@ public final strictfp class TypesTest ex
      */
     @Test
     public void testGetCodeDescription() {
-        final InternationalString description = Types.getDescription(CharacterSet.ISO_8859_1);
-        assertEquals("ISO/IEC 8859-1, Information technology - 8-bit single byte coded graphic
character sets - Part 1 : Latin alphabet No.1.",
+        final InternationalString description = Types.getDescription(OnLineFunction.DOWNLOAD);
+        assertEquals("Online instructions for transferring data from one storage device or
system to another.",
                 description.toString(Locale.ROOT));
-        assertEquals("ISO/IEC 8859-1, Information technology - 8-bit single byte coded graphic
character sets - Part 1 : Latin alphabet No.1.",
+        assertEquals("Online instructions for transferring data from one storage device or
system to another.",
                 description.toString(Locale.ENGLISH));
-        assertEquals("ISO/IEC 8859-1, alphabet latin 1.",
+        assertEquals("Transfert de la ressource d'un système à un autre.",
                 description.toString(Locale.FRENCH));
     }
 
@@ -172,7 +171,7 @@ public final strictfp class TypesTest ex
     public void testGetListName() {
         assertEquals("SV_ParameterDirection",   Types.getListName(ParameterDirection.IN_OUT));
         assertEquals("CS_AxisDirection",        Types.getListName(AxisDirection     .NORTH));
-        assertEquals("MD_CharacterSetCode",     Types.getListName(CharacterSet      .UTF_8));
+        assertEquals("CI_OnLineFunctionCode",   Types.getListName(OnLineFunction    .DOWNLOAD));
         assertEquals("MD_ImagingConditionCode", Types.getListName(ImagingCondition  .BLURRED_IMAGE));
     }
 
@@ -183,7 +182,7 @@ public final strictfp class TypesTest ex
     public void testGetCodeName() {
         assertEquals("in/out",       Types.getCodeName(ParameterDirection.IN_OUT));
         assertEquals("north",        Types.getCodeName(AxisDirection     .NORTH));
-        assertEquals("utf8",         Types.getCodeName(CharacterSet      .UTF_8));
+        assertEquals("download",     Types.getCodeName(OnLineFunction    .DOWNLOAD));
         assertEquals("blurredImage", Types.getCodeName(ImagingCondition  .BLURRED_IMAGE));
     }
 
@@ -193,7 +192,7 @@ public final strictfp class TypesTest ex
     @Test
     public void testGetCodeLabel() {
         assertEquals("North",         Types.getCodeLabel(AxisDirection   .NORTH));
-        assertEquals("UTF-8",         Types.getCodeLabel(CharacterSet    .UTF_8));
+        assertEquals("Download",      Types.getCodeLabel(OnLineFunction  .DOWNLOAD));
         assertEquals("Blurred image", Types.getCodeLabel(ImagingCondition.BLURRED_IMAGE));
     }
 

Modified: sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/xml/ValueConverterTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/xml/ValueConverterTest.java?rev=1615109&r1=1615108&r2=1615109&view=diff
==============================================================================
--- sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/xml/ValueConverterTest.java
[UTF-8] (original)
+++ sis/branches/JDK6/core/sis-utility/src/test/java/org/apache/sis/xml/ValueConverterTest.java
[UTF-8] Fri Aug  1 14:19:16 2014
@@ -17,10 +17,14 @@
 package org.apache.sis.xml;
 
 import java.util.Locale;
+import org.apache.sis.test.DependsOn;
 import org.apache.sis.test.TestCase;
 import org.junit.Test;
 
-import static org.apache.sis.test.Assert.*;
+import static org.junit.Assert.*;
+
+// Branch-dependent imports
+import org.apache.sis.internal.jdk7.StandardCharsets;
 
 
 /**
@@ -28,9 +32,10 @@ import static org.apache.sis.test.Assert
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @since   0.4
- * @version 0.4
+ * @version 0.5
  * @module
  */
+@DependsOn(LegacyCodesTest.class)
 public final strictfp class ValueConverterTest extends TestCase {
     /**
      * Tests {@link ValueConverter#toLanguageCode(MarshalContext, Locale)}.
@@ -66,4 +71,26 @@ public final strictfp class ValueConvert
         assertEquals("JP", ValueConverter.DEFAULT.toCountryCode(null, Locale.JAPAN));
         assertNull  (      ValueConverter.DEFAULT.toCountryCode(null, Locale.JAPANESE));
     }
+
+    /**
+     * Tests {@link ValueConverter#toCharsetCode(MarshalContext, Charset)}.
+     */
+    @Test
+    public void testToCharsetCode() {
+        assertEquals("utf8",      ValueConverter.DEFAULT.toCharsetCode(null, StandardCharsets.UTF_8));
+        assertEquals("utf16",     ValueConverter.DEFAULT.toCharsetCode(null, StandardCharsets.UTF_16));
+        assertEquals("8859part1", ValueConverter.DEFAULT.toCharsetCode(null, StandardCharsets.ISO_8859_1));
+    }
+
+    /**
+     * Tests {@link ValueConverter#toCharset(MarshalContext, String)}.
+     */
+    @Test
+    public void testToCharset() {
+        assertEquals(StandardCharsets.UTF_8,      ValueConverter.DEFAULT.toCharset(null,
"utf8"));
+        assertEquals(StandardCharsets.UTF_8,      ValueConverter.DEFAULT.toCharset(null,
"UTF-8"));
+        assertEquals(StandardCharsets.UTF_16,     ValueConverter.DEFAULT.toCharset(null,
"utf16"));
+        assertEquals(StandardCharsets.ISO_8859_1, ValueConverter.DEFAULT.toCharset(null,
"8859part1"));
+        assertEquals(StandardCharsets.ISO_8859_1, ValueConverter.DEFAULT.toCharset(null,
"ISO-8859-1"));
+    }
 }

Modified: sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreTest.java?rev=1615109&r1=1615108&r2=1615109&view=diff
==============================================================================
--- sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreTest.java
[UTF-8] (original)
+++ sis/branches/JDK6/storage/sis-storage/src/test/java/org/apache/sis/internal/storage/xml/XMLStoreTest.java
[UTF-8] Fri Aug  1 14:19:16 2014
@@ -23,7 +23,6 @@ import org.opengis.metadata.citation.Rol
 import org.opengis.metadata.citation.OnLineFunction;
 import org.opengis.metadata.citation.OnlineResource;
 import org.opengis.metadata.citation.ResponsibleParty;
-import org.opengis.metadata.identification.CharacterSet;
 import org.apache.sis.xml.Namespaces;
 import org.apache.sis.storage.StorageConnector;
 import org.apache.sis.storage.DataStoreException;
@@ -33,6 +32,9 @@ import org.junit.Test;
 import static org.junit.Assert.*;
 import static org.apache.sis.test.TestUtilities.getSingleton;
 
+// Branch-dependent imports
+import org.apache.sis.internal.jdk7.StandardCharsets;
+
 
 /**
  * Tests {@link XMLStore}.
@@ -103,7 +105,7 @@ public final strictfp class XMLStoreTest
         final OnlineResource resource = party.getContactInfo().getOnlineResource();
 
         assertEquals(Locale.ENGLISH,              metadata.getLanguage());
-        assertEquals(CharacterSet.UTF_8,          metadata.getCharacterSet());
+        assertEquals(StandardCharsets.UTF_8,      metadata.getCharacterSet());
         assertEquals(Role.PRINCIPAL_INVESTIGATOR, party.getRole());
         assertEquals("Apache SIS",                String.valueOf(party.getOrganisationName()));
         assertEquals("http://sis.apache.org",     String.valueOf(resource.getLinkage()));



Mime
View raw message