You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2013/07/03 17:21:49 UTC
svn commit: r1499441 - in /sis/branches/JDK7/core/sis-metadata/src:
main/java/org/apache/sis/metadata/iso/
test/java/org/apache/sis/metadata/iso/ test/java/org/apache/sis/test/suite/
Author: desruisseaux
Date: Wed Jul 3 15:21:49 2013
New Revision: 1499441
URL: http://svn.apache.org/r1499441
Log:
Bug fix in construction of localized remarks.
Added:
sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/ImmutableIdentifierTest.java (with props)
Modified:
sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java?rev=1499441&r1=1499440&r2=1499441&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/ImmutableIdentifier.java [UTF-8] Wed Jul 3 15:21:49 2013
@@ -301,15 +301,7 @@ public class ImmutableIdentifier impleme
final Locale locale = Locales.parseSuffix(REMARKS_KEY, key);
if (locale != null) {
if (localized == null) {
- if (remarks instanceof DefaultInternationalString) {
- localized = (DefaultInternationalString) remarks;
- } else {
- localized = new DefaultInternationalString();
- if (remarks instanceof CharSequence) { // String or InternationalString.
- localized.add(Locale.ROOT, remarks.toString());
- remarks = null;
- }
- }
+ localized = new DefaultInternationalString();
}
localized.add(locale, (String) value);
}
@@ -319,9 +311,12 @@ public class ImmutableIdentifier impleme
* both as InternationalString and as String for some locales (which is a weird
* usage...), then current implementation discards the later with a warning.
*/
- if (localized != null && !localized.getLocales().isEmpty()) {
+ if (localized != null) {
if (remarks == null) {
remarks = localized;
+ } else if (remarks instanceof SimpleInternationalString) {
+ localized.add(Locale.ROOT, remarks.toString());
+ remarks = localized;
} else {
Logging.log(ImmutableIdentifier.class, "<init>",
Messages.getResources(null).getLogRecord(Level.WARNING, Messages.Keys.LocalesDiscarded));
Added: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/ImmutableIdentifierTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/ImmutableIdentifierTest.java?rev=1499441&view=auto
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/ImmutableIdentifierTest.java (added)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/ImmutableIdentifierTest.java [UTF-8] Wed Jul 3 15:21:49 2013
@@ -0,0 +1,133 @@
+/*
+ * 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.metadata.iso;
+
+import java.util.Map;
+import java.util.HashMap;
+import java.util.Locale;
+import org.opengis.parameter.InvalidParameterValueException;
+import org.apache.sis.metadata.iso.citation.DefaultCitation;
+import org.apache.sis.util.iso.SimpleInternationalString;
+import org.apache.sis.test.DependsOnMethod;
+import org.apache.sis.test.TestCase;
+import org.opengis.test.Validators;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+import static org.opengis.referencing.ReferenceIdentifier.*;
+
+
+/**
+ * Tests {@link ImmutableIdentifier}.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.3 (derived from geotk-2.2)
+ * @version 0.3
+ * @module
+ */
+public final strictfp class ImmutableIdentifierTest extends TestCase {
+ /**
+ * Returns the properties map to be used in argument to test methods.
+ */
+ private static Map<String,Object> properties() {
+ final Map<String,Object> properties = new HashMap<>();
+ assertNull(properties.put(CODE_KEY, "This is a code"));
+ assertNull(properties.put(AUTHORITY_KEY, "This is an authority"));
+ assertNull(properties.put(VERSION_KEY, "This is a version"));
+ assertNull(properties.put("dummy", "Doesn't matter"));
+ assertNull(properties.put("remarks", "There is remarks"));
+ assertNull(properties.put("remarks_fr", "Voici des remarques"));
+ assertNull(properties.put("remarks_fr_CA", "Pareil"));
+ return properties;
+ }
+
+ /**
+ * Tests the constructor with only {@link String} values, including localized remarks.
+ */
+ @Test
+ public void testConstructorWithStringValues() {
+ final Map<String,Object> properties = properties();
+ final ImmutableIdentifier identifier = new ImmutableIdentifier(properties);
+ Validators.validate(identifier);
+
+ assertEquals(CODE_KEY, "This is a code", identifier.getCode());
+ assertEquals(AUTHORITY_KEY, "This is an authority", identifier.getAuthority().getTitle().toString());
+ assertEquals(VERSION_KEY, "This is a version", identifier.getVersion());
+ assertEquals("remarks", "There is remarks", identifier.getRemarks().toString(Locale.ENGLISH));
+ assertEquals("remarks_fr", "Voici des remarques", identifier.getRemarks().toString(Locale.FRENCH));
+ assertEquals("remarks_fr_CA", "Pareil", identifier.getRemarks().toString(Locale.CANADA_FRENCH));
+ assertEquals("remarks_fr_BE", "Voici des remarques", identifier.getRemarks().toString(new Locale("fr", "BE")));
+ }
+
+ /**
+ * Tests the constructor with the {@code "remarks"} attribute as an {@link InternationalString}.
+ */
+ @Test
+ @DependsOnMethod("testConstructorWithStringValues")
+ public void testConstructorWithInternationalString() {
+ final Map<String,Object> properties = properties();
+ assertNotNull(properties.put("remarks", new SimpleInternationalString("Overwritten remarks")));
+ final ImmutableIdentifier identifier = new ImmutableIdentifier(properties);
+ Validators.validate(identifier);
+
+ assertEquals(CODE_KEY, "This is a code", identifier.getCode());
+ assertEquals(AUTHORITY_KEY, "This is an authority", identifier.getAuthority().getTitle().toString());
+ assertEquals(VERSION_KEY, "This is a version", identifier.getVersion());
+ assertEquals("remarks", "Overwritten remarks", identifier.getRemarks().toString(Locale.ENGLISH));
+ assertEquals("remarks_fr", "Voici des remarques", identifier.getRemarks().toString(Locale.FRENCH));
+ assertEquals("remarks_fr_CA", "Pareil", identifier.getRemarks().toString(Locale.CANADA_FRENCH));
+ }
+
+ /**
+ * Tests the constructor with the {@code "authority"} attribute as a {@link DefaultCitation}.
+ * This test also opportunistically test mixed-case key.
+ */
+ @Test
+ @DependsOnMethod("testConstructorWithStringValues")
+ public void testConstructorWithCitation() {
+ final Map<String,Object> properties = properties();
+ assertNotNull(properties.remove(AUTHORITY_KEY));
+ assertNull(properties.put("AutHOrITY", new DefaultCitation("An other authority")));
+ final ImmutableIdentifier identifier = new ImmutableIdentifier(properties);
+ Validators.validate(identifier);
+
+ assertEquals(CODE_KEY, "This is a code", identifier.getCode());
+ assertEquals(AUTHORITY_KEY, "An other authority", identifier.getAuthority().getTitle().toString());
+ assertEquals(VERSION_KEY, "This is a version", identifier.getVersion());
+ assertEquals("remarks", "There is remarks", identifier.getRemarks().toString(Locale.ENGLISH));
+ assertEquals("remarks_fr", "Voici des remarques", identifier.getRemarks().toString(Locale.FRENCH));
+ assertEquals("remarks_fr_CA", "Pareil", identifier.getRemarks().toString(Locale.CANADA_FRENCH));
+ }
+
+ /**
+ * Tests the constructor with an argument of the wrong type.
+ */
+ @Test
+ @DependsOnMethod("testConstructorWithStringValues")
+ public void testConstructorWithWrongType() {
+ final Map<String,Object> properties = properties();
+ assertNotNull(properties.put(AUTHORITY_KEY, Locale.CANADA));
+ try {
+ final ImmutableIdentifier identifier = new ImmutableIdentifier(properties);
+ fail(identifier.toString());
+ } catch (InvalidParameterValueException e) {
+ // This is the expected exception
+ final String message = e.getMessage();
+ assertTrue(message, message.contains(AUTHORITY_KEY));
+ }
+ }
+}
Propchange: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/ImmutableIdentifierTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/ImmutableIdentifierTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified: sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java?rev=1499441&r1=1499440&r2=1499441&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java [UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/test/java/org/apache/sis/test/suite/MetadataTestSuite.java [UTF-8] Wed Jul 3 15:21:49 2013
@@ -53,6 +53,7 @@ import org.junit.BeforeClass;
org.apache.sis.metadata.MetadataStandardTest.class,
org.apache.sis.metadata.PrunerTest.class,
org.apache.sis.metadata.AbstractMetadataTest.class,
+ org.apache.sis.metadata.iso.ImmutableIdentifierTest.class,
org.apache.sis.metadata.iso.AllMetadataTest.class,
// XML marshalling.