Search in sources :

Example 1 with IdentifiedObjectMock

use of org.apache.sis.test.mock.IdentifiedObjectMock in project sis by apache.

the class NameMarshallingTest method unmarshal.

/**
 * Converse of {@link #marshal(GenericName)}.
 */
private GenericName unmarshal(final String xml) throws JAXBException {
    final Unmarshaller unmarshaller = pool.acquireUnmarshaller();
    final Object value = unmarshal(unmarshaller, xml);
    pool.recycle(unmarshaller);
    return ((IdentifiedObjectMock) value).alias;
}
Also used : IdentifiedObjectMock(org.apache.sis.test.mock.IdentifiedObjectMock) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 2 with IdentifiedObjectMock

use of org.apache.sis.test.mock.IdentifiedObjectMock in project sis by apache.

the class NameMarshallingTest method marshal.

/**
 * Returns the XML representation of the given name, wrapped
 * in a mock {@code <gml:IO_IdentifiedObject>} element.
 */
private String marshal(final GenericName name) throws JAXBException {
    if (pool == null) {
        pool = new MarshallerPool(JAXBContext.newInstance(IdentifiedObjectMock.class), null);
    }
    final Marshaller marshaller = pool.acquireMarshaller();
    marshaller.setProperty(XML.METADATA_VERSION, VERSION_2007);
    final String xml = marshal(marshaller, new IdentifiedObjectMock(null, name));
    pool.recycle(marshaller);
    return xml;
}
Also used : IdentifiedObjectMock(org.apache.sis.test.mock.IdentifiedObjectMock) Marshaller(javax.xml.bind.Marshaller) MarshallerPool(org.apache.sis.xml.MarshallerPool)

Example 3 with IdentifiedObjectMock

use of org.apache.sis.test.mock.IdentifiedObjectMock in project sis by apache.

the class IdentifiedObjectsTest method testIsHeuristicMatchForName.

/**
 * Tests {@link IdentifiedObjects#isHeuristicMatchForName(IdentifiedObject, String)}.
 */
@Test
public void testIsHeuristicMatchForName() {
    final NameFactory factory = DefaultFactories.forBuildin(NameFactory.class);
    final GenericName name = factory.createGenericName(null, "myScope", "myName");
    // Intentional trailing space.
    IdentifiedObjectMock object = new IdentifiedObjectMock("myCode ", name);
    // Test the code.
    assertFalse(isHeuristicMatchForName(object, "other"));
    assertTrue(isHeuristicMatchForName(object, "myCode"));
    assertTrue(isHeuristicMatchForName(object, " my_code "));
    assertFalse(isHeuristicMatchForName(object, "testmyCode"));
    assertFalse(isHeuristicMatchForName(object, "other:myCode"));
    assertFalse(isHeuristicMatchForName(object, "test"));
    assertFalse(isHeuristicMatchForName(null, "myCode"));
    // Test the alias.
    assertTrue(isHeuristicMatchForName(object, "myName"));
    assertTrue(isHeuristicMatchForName(object, " My_name "));
    assertFalse(isHeuristicMatchForName(object, "myScope"));
    assertFalse(isHeuristicMatchForName(object, "other:myName"));
    assertFalse(isHeuristicMatchForName(object, "myScope:other"));
    assertFalse(isHeuristicMatchForName(object, "other:myScope:myName"));
    // Test non-letter and non-digits characters.
    object = new IdentifiedObjectMock("Mercator (1SP)", name);
    assertTrue(isHeuristicMatchForName(object, "Mercator (1SP)"));
    assertTrue(isHeuristicMatchForName(object, "Mercator_1SP"));
    assertFalse(isHeuristicMatchForName(object, "Mercator_2SP"));
    // Test diacritical signs
    object = new IdentifiedObjectMock("RĂ©union", name);
    assertTrue(isHeuristicMatchForName(object, "RĂ©union"));
    assertTrue(isHeuristicMatchForName(object, "Reunion"));
}
Also used : IdentifiedObjectMock(org.apache.sis.test.mock.IdentifiedObjectMock) GenericName(org.opengis.util.GenericName) NameFactory(org.opengis.util.NameFactory) Test(org.junit.Test)

Aggregations

IdentifiedObjectMock (org.apache.sis.test.mock.IdentifiedObjectMock)3 Marshaller (javax.xml.bind.Marshaller)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 MarshallerPool (org.apache.sis.xml.MarshallerPool)1 Test (org.junit.Test)1 GenericName (org.opengis.util.GenericName)1 NameFactory (org.opengis.util.NameFactory)1