Author: desruisseaux
Date: Tue Dec 4 11:08:53 2012
New Revision: 1416884
URL: http://svn.apache.org/viewvc?rev=1416884&view=rev
Log:
Added a few tests.
Modified:
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/jaxb/IdentifierMapAdapterTest.java
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/jaxb/IdentifierMapWithSpecialCasesTest.java
Modified:
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/jaxb/IdentifierMapAdapterTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/jaxb/IdentifierMapAdapterTest.java?rev=1416884&r1=1416883&r2=1416884&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/jaxb/IdentifierMapAdapterTest.java
(original)
+++
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/jaxb/IdentifierMapAdapterTest.java
Tue Dec 4 11:08:53 2012
@@ -44,7 +44,8 @@ import static org.apache.sis.xml.Identif
public strictfp class IdentifierMapAdapterTest extends TestCase {
/**
* Creates the {@link IdentifierMapAdapter} instance to test for the given
identifiers.
- * Subclasses will override this method.
+ * This {@code IdentifierMapAdapterTest} class creates {@link
IdentifierMapAdapter} instances.
+ * Subclasses will override this method in order to create instances of
the class to test.
*
* @param identifiers The identifiers to wrap in an {@code
IdentifierMapAdapter}.
* @return The {@code IdentifierMapAdapter} to test.
@@ -56,6 +57,8 @@ public strictfp class IdentifierMapAdapt
/**
* Asserts that the content of the given map is equals to the given
content, represented
* as a string. Subclasses can override this method in order to alter the
expected string.
+ * This is needed when, using the "special case rules", {@code "href"}
have been replaced
+ * be {@code "xlink:href"}.
*
* @param expected The expected content.
* @return The map to compare with the expected content.
@@ -87,8 +90,8 @@ public strictfp class IdentifierMapAdapt
/*
* Add two entries, then verify the map content.
*/
- identifiers.add(new IdentifierMapEntry(ID, "myID"));
- identifiers.add(new IdentifierMapEntry(UUID, "myUUID"));
+ assertTrue(identifiers.add(new IdentifierMapEntry(ID, "myID")));
+ assertTrue(identifiers.add(new IdentifierMapEntry(UUID, "myUUID")));
assertFalse ("After add, map shall not be empty.", map.isEmpty());
assertEquals("After add, map shall not be empty.", 2, map.size());
assertEquals("After add, map shall not be empty.", 2,
identifiers.size());
@@ -160,9 +163,9 @@ public strictfp class IdentifierMapAdapt
final java.util.UUID myUUID =
fromString("a1eb6e53-93db-4942-84a6-d9e7fb9db2c7");
final URI myURI = URI.create("http://mylink");
- map.putSpecialized(ID, myID);
- map.putSpecialized(UUID, myUUID);
- map.putSpecialized(HREF, myURI);
+ assertNull(map.putSpecialized(ID, myID));
+ assertNull(map.putSpecialized(UUID, myUUID));
+ assertNull(map.putSpecialized(HREF, myURI));
assertMapEquals("{gml:id=âmyIDâ,"
+ " gco:uuid=âa1eb6e53-93db-4942-84a6-d9e7fb9db2c7â,"
+ " xlink:href=âhttp://mylinkâ}", map);
@@ -183,9 +186,9 @@ public strictfp class IdentifierMapAdapt
final List<Identifier> identifiers = new ArrayList<>();
final IdentifierMap map = create(identifiers);
- map.put(ID, "myID");
- map.put(UUID, "a1eb6e53-93db-4942-84a6-d9e7fb9db2c7");
- map.put(HREF, "http://mylink");
+ assertNull(map.put(ID, "myID"));
+ assertNull(map.put(UUID, "a1eb6e53-93db-4942-84a6-d9e7fb9db2c7"));
+ assertNull(map.put(HREF, "http://mylink"));
assertMapEquals("{gml:id=âmyIDâ,"
+ " gco:uuid=âa1eb6e53-93db-4942-84a6-d9e7fb9db2c7â,"
+ " xlink:href=âhttp://mylinkâ}", map);
@@ -204,9 +207,9 @@ public strictfp class IdentifierMapAdapt
@Test
public void testDuplicatedAuthorities() {
final List<Identifier> identifiers = new ArrayList<>();
- identifiers.add(new IdentifierMapEntry(ID, "myID1"));
- identifiers.add(new IdentifierMapEntry(UUID, "myUUID"));
- identifiers.add(new IdentifierMapEntry(ID, "myID2"));
+ assertTrue(identifiers.add(new IdentifierMapEntry(ID, "myID1")));
+ assertTrue(identifiers.add(new IdentifierMapEntry(UUID, "myUUID")));
+ assertTrue(identifiers.add(new IdentifierMapEntry(ID, "myID2")));
final IdentifierMap map = create(identifiers);
assertEquals("Duplicated authorities shall be filtered.", 2,
map.size());
@@ -237,8 +240,8 @@ public strictfp class IdentifierMapAdapt
final List<Identifier> identifiers = new ArrayList<>();
final Map<Citation,String> map = create(identifiers);
- identifiers.add(new IdentifierMapEntry(ID, "myID"));
- identifiers.add(new IdentifierMapEntry(UUID, "myUUID"));
+ assertTrue(identifiers.add(new IdentifierMapEntry(ID, "myID")));
+ assertTrue(identifiers.add(new IdentifierMapEntry(UUID, "myUUID")));
final Map<Citation,String> copy = assertSerializedEquals(map);
assertNotSame(map, copy);
Modified:
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/jaxb/IdentifierMapWithSpecialCasesTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/jaxb/IdentifierMapWithSpecialCasesTest.java?rev=1416884&r1=1416883&r2=1416884&view=diff
==============================================================================
---
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/jaxb/IdentifierMapWithSpecialCasesTest.java
(original)
+++
sis/branches/JDK7/sis-utility/src/test/java/org/apache/sis/internal/jaxb/IdentifierMapWithSpecialCasesTest.java
Tue Dec 4 11:08:53 2012
@@ -21,6 +21,7 @@ import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.UUID;
import org.opengis.metadata.Identifier;
import org.opengis.metadata.citation.Citation;
import org.apache.sis.xml.IdentifierMap;
@@ -49,7 +50,7 @@ public final strictfp class IdentifierMa
private static final String TO_REPLACE = "xlink:href=â";
/**
- * Creates the {@link IdentifierMapAdapter} instance to test for the given
identifiers.
+ * Creates the {@link IdentifierMapWithSpecialCases} instance to test for
the given identifiers.
*
* @param identifiers The identifiers to wrap in an {@code
IdentifierMapAdapter}.
* @return The {@code IdentifierMapAdapter} to test.
@@ -60,8 +61,9 @@ public final strictfp class IdentifierMa
}
/**
- * Replaces the {@code xlink:href} value by the {@link XLink#toString()}
value
- * before to compare with the map content.
+ * Replaces the {@code xlink:href} value by the {@link XLink#toString()}
value before
+ * to compare with the map content. This is needed because the "special
case rules"
+ * cause the {@code "href"} identifier to be replaced by {@code
"xlink:href"}.
*/
@Override
void assertMapEquals(String expected, final Map<Citation,String> map) {
@@ -91,19 +93,42 @@ public final strictfp class IdentifierMa
* Tests explicitely the special handling of {@code href} values.
*/
@Test
- public void testSpecialCases() {
+ public void testHRefSubstitution() {
final List<Identifier> identifiers = new ArrayList<>();
final IdentifierMap map = create(identifiers);
- map.put(IdentifierSpace.HREF, "myHREF");
- assertEquals("myHREF", map.get(IdentifierSpace.HREF));
+ assertNull(map.put(IdentifierSpace.HREF, "myHREF"));
+ assertEquals("Shall contain the entry we added.", "myHREF",
map.get(IdentifierSpace.HREF));
// Check the XLink object
final XLink link = map.getSpecialized(IdentifierSpace.XLINK);
- assertEquals("myHREF", String.valueOf(link.getHRef()));
- assertEquals(link.toString(), getSingleton(identifiers).getCode());
+ assertEquals("Added href shall be stored as XLink attribute.",
"myHREF", String.valueOf(link.getHRef()));
+ assertEquals("Identifier list shall contain the XLink.",
link.toString(), getSingleton(identifiers).getCode());
// Modidfy the XLink object directly
link.setHRef(URI.create("myNewHREF"));
- assertEquals("myNewHREF", map.get(IdentifierSpace.HREF));
+ assertEquals("Change in XLink shall be reflected in href.",
"myNewHREF", map.get(IdentifierSpace.HREF));
+ }
+
+ /**
+ * Tests the binding of UUID.
+ */
+ @Test
+ public void testUUIDs() {
+ final String object = "IdentifiedObject";
+ final List<Identifier> identifiers = new ArrayList<>();
+ final IdentifierMap map = new
IdentifierMapWithSpecialCases(identifiers, object);
+ final UUID id1 =
UUID.fromString("434f3107-c6d2-4c8c-bb25-553f68641c5c");
+ final UUID id2 =
UUID.fromString("42924124-032a-4dfe-b06e-113e3cb81cf0");
+
+ // Add first UUID.
+ assertNull("Shall not contain UUID before put.", UUIDs.lookup(id1));
+ assertNull(map.putSpecialized(IdentifierSpace.UUID, id1));
+ assertSame("Object sholl be associated to UUID.", object,
UUIDs.lookup(id1));
+
+ // Replace UUID by a new one.
+ assertNull("Shall not contain UUID before put.", UUIDs.lookup(id2));
+ assertSame(id1, map.putSpecialized(IdentifierSpace.UUID, id2));
+ assertNull("Shall not contain the removed UUID.", UUIDs.lookup(id1));
+ assertSame("Object sholl be associated to UUID.", object,
UUIDs.lookup(id2));
}
}