use of org.apache.sis.xml.IdentifierMap in project sis by apache.
the class ModifiableIdentifierMapTest method testGetSpecialized.
/**
* Tests read operations on an {@link IdentifierMap} using specific API.
*/
@Test
public void testGetSpecialized() {
final List<Identifier> identifiers = new ArrayList<>();
final IdentifierMap map = new ModifiableIdentifierMap(identifiers);
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);
assertEquals("myID", map.get(ID));
assertEquals("a1eb6e53-93db-4942-84a6-d9e7fb9db2c7", map.get(UUID));
assertEquals("http://mylink", map.get(HREF));
assertEquals("myID", map.getSpecialized(ID));
assertEquals(URI.create("http://mylink"), map.getSpecialized(HREF));
assertEquals(fromString("a1eb6e53-93db-4942-84a6-d9e7fb9db2c7"), map.getSpecialized(UUID));
}
use of org.apache.sis.xml.IdentifierMap in project sis by apache.
the class ModifiableIdentifierMapTest method testPutSpecialized.
/**
* Tests write operations on an {@link IdentifierMap} using specific API.
*/
@Test
public void testPutSpecialized() {
final List<Identifier> identifiers = new ArrayList<>();
final IdentifierMap map = new ModifiableIdentifierMap(identifiers);
final String myID = "myID";
final java.util.UUID myUUID = fromString("a1eb6e53-93db-4942-84a6-d9e7fb9db2c7");
final URI myURI = URI.create("http://mylink");
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);
assertSame(myID, map.getSpecialized(ID));
assertSame(myUUID, map.getSpecialized(UUID));
assertSame(myURI, map.getSpecialized(HREF));
assertEquals("myID", map.get(ID));
assertEquals("a1eb6e53-93db-4942-84a6-d9e7fb9db2c7", map.get(UUID));
assertEquals("http://mylink", map.get(HREF));
}
use of org.apache.sis.xml.IdentifierMap in project sis by apache.
the class ModifiableIdentifierMapTest method testHRefSubstitution.
/**
* Tests explicitely the special handling of {@code href} values.
*/
@Test
public void testHRefSubstitution() {
final List<Identifier> identifiers = new ArrayList<>();
final IdentifierMap map = new ModifiableIdentifierMap(identifiers);
assertNull(map.put(HREF, "myHREF"));
assertEquals("Shall contain the entry we added.", "myHREF", map.get(HREF));
// Check the XLink object
final XLink link = map.getSpecialized(XLINK);
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("Change in XLink shall be reflected in href.", "myNewHREF", map.get(HREF));
}
use of org.apache.sis.xml.IdentifierMap in project sis by apache.
the class ModifiableIdentifierMapTest method testUUIDs.
/**
* Tests with UUIDs.
*/
@Test
public void testUUIDs() {
final List<Identifier> identifiers = new ArrayList<>();
final IdentifierMap map = new ModifiableIdentifierMap(identifiers);
final java.util.UUID id1 = fromString("434f3107-c6d2-4c8c-bb25-553f68641c5c");
final java.util.UUID id2 = fromString("42924124-032a-4dfe-b06e-113e3cb81cf0");
// Add first UUID.
assertNull(map.putSpecialized(UUID, id1));
// Replace UUID by a new one.
assertSame(id1, map.putSpecialized(UUID, id2));
}
use of org.apache.sis.xml.IdentifierMap in project sis by apache.
the class ModifiableIdentifierMapTest method testDuplicatedAuthorities.
/**
* Tests the handling of duplicated authorities.
*/
@Test
public void testDuplicatedAuthorities() {
final List<Identifier> identifiers = new ArrayList<>();
assertTrue(identifiers.add(new IdentifierMapEntry(ID, "myID1")));
assertTrue(identifiers.add(new IdentifierMapEntry(UUID, "myUUID")));
assertTrue(identifiers.add(new IdentifierMapEntry(ID, "myID2")));
final IdentifierMap map = new ModifiableIdentifierMap(identifiers);
assertEquals("Duplicated authorities shall be filtered.", 2, map.size());
assertEquals("Duplicated authorities shall still exist.", 3, identifiers.size());
assertEquals("myID1", map.get(ID));
assertEquals("myUUID", map.get(UUID));
final Iterator<Citation> it = map.keySet().iterator();
assertTrue(it.hasNext());
assertSame(ID, it.next());
it.remove();
assertTrue(it.hasNext());
assertSame(UUID, it.next());
assertFalse("Duplicated authority shall have been removed.", it.hasNext());
assertEquals(1, identifiers.size());
assertEquals(1, map.size());
}
Aggregations