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;
}
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;
}
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"));
}
Aggregations