Search in sources :

Example 1 with IdentifierMap

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));
}
Also used : Identifier(org.opengis.metadata.Identifier) IdentifierMap(org.apache.sis.xml.IdentifierMap) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 2 with IdentifierMap

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));
}
Also used : Identifier(org.opengis.metadata.Identifier) IdentifierMap(org.apache.sis.xml.IdentifierMap) ArrayList(java.util.ArrayList) UUID.fromString(java.util.UUID.fromString) UUID(java.util.UUID) URI(java.net.URI) Test(org.junit.Test)

Example 3 with IdentifierMap

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));
}
Also used : Identifier(org.opengis.metadata.Identifier) IdentifierMap(org.apache.sis.xml.IdentifierMap) ArrayList(java.util.ArrayList) XLink(org.apache.sis.xml.XLink) Test(org.junit.Test)

Example 4 with IdentifierMap

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));
}
Also used : Identifier(org.opengis.metadata.Identifier) IdentifierMap(org.apache.sis.xml.IdentifierMap) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Test(org.junit.Test)

Example 5 with IdentifierMap

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());
}
Also used : Identifier(org.opengis.metadata.Identifier) IdentifierMap(org.apache.sis.xml.IdentifierMap) ArrayList(java.util.ArrayList) Citation(org.opengis.metadata.citation.Citation) Test(org.junit.Test)

Aggregations

IdentifierMap (org.apache.sis.xml.IdentifierMap)7 Test (org.junit.Test)6 Identifier (org.opengis.metadata.Identifier)6 ArrayList (java.util.ArrayList)5 UUID (java.util.UUID)2 URI (java.net.URI)1 UUID.fromString (java.util.UUID.fromString)1 SpecializedIdentifier (org.apache.sis.internal.jaxb.SpecializedIdentifier)1 DefaultIdentifier (org.apache.sis.metadata.iso.DefaultIdentifier)1 IdentifiedObject (org.apache.sis.xml.IdentifiedObject)1 ReferenceResolver (org.apache.sis.xml.ReferenceResolver)1 XLink (org.apache.sis.xml.XLink)1 Citation (org.opengis.metadata.citation.Citation)1