use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.
the class PropertyAccessorTest method testSetInAppendMode.
/**
* Tests the {@link PropertyAccessor#set(int, Object, Object, int)} method in
* {@link PropertyAccessor#APPEND} mode. In this mode, new collections
* are added into existing collections instead than replacing them.
* The metadata object created by this test after the merge is:
*
* {@preformat text
* DefaultCitation
* ├─Title……………………………………………………… Added title
* ├─Alternate title (1 of 4)…… Old title 1
* ├─Alternate title (2 of 4)…… Old title 2
* ├─Alternate title (3 of 4)…… New title 1
* └─Alternate title (4 of 4)…… New title 2
* }
*
* @see #testSetCollection()
*/
public void testSetInAppendMode() {
final DefaultCitation instance = new DefaultCitation();
final List<InternationalString> oldTitles = Arrays.<InternationalString>asList(new SimpleInternationalString("Old title 1"), new SimpleInternationalString("Old title 2"));
final List<InternationalString> newTitles = Arrays.<InternationalString>asList(new SimpleInternationalString("New title 1"), new SimpleInternationalString("New title 2"));
final List<InternationalString> merged = new ArrayList<>(oldTitles);
assertTrue(merged.addAll(newTitles));
// Set the title.
instance.setAlternateTitles(oldTitles);
final PropertyAccessor accessor = createPropertyAccessor();
final int titleIndex = accessor.indexOf("title", true);
Object titleChanged = accessor.set(titleIndex, instance, "Added title", APPEND);
// Set the alternate titles.
final int index = accessor.indexOf("alternateTitles", true);
final Object changed = accessor.set(index, instance, newTitles, APPEND);
final Object newValue = accessor.get(index, instance);
// Verify the values.
assertEquals("set(…, APPEND)", Boolean.TRUE, titleChanged);
assertEquals("set(…, APPEND)", Boolean.TRUE, changed);
assertEquals("get(…)", merged, newValue);
assertSame("alternateTitles", newValue, instance.getAlternateTitles());
assertTitleEquals("title", "Added title", instance);
// Test setting again the title to the same value.
titleChanged = accessor.set(titleIndex, instance, "Added title", APPEND);
assertEquals("set(…, APPEND)", Boolean.FALSE, titleChanged);
assertTitleEquals("title", "Added title", instance);
// Test setting the title to a different value.
titleChanged = accessor.set(titleIndex, instance, "Different title", APPEND);
// Operation shall be refused.
assertNull("set(…, APPEND)", titleChanged);
assertTitleEquals("title", "Added title", instance);
}
use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.
the class TreeNodeChildrenTest method metadataWithMultiOccurrences.
/**
* Creates a shallow metadata object with multi-occurrences (i.e. more than one value in collections).
* This method creates the following metadata:
*
* {@preformat text
* DefaultCitation
* ├─Title………………………………………………………… Some title
* ├─Alternate title (1 of 2)……… First alternate title
* ├─Alternate title (2 of 2)……… Second alternate title
* ├─Edition…………………………………………………… Some edition
* ├─Presentation form (1 of 2)… Map digital
* ├─Presentation form (2 of 2)… map hardcopy
* └─Other citation details…………… Some other details
* }
*/
static DefaultCitation metadataWithMultiOccurrences() {
final DefaultCitation citation = metadataWithSingletonInCollections();
assertTrue(citation.getAlternateTitles().add(new SimpleInternationalString("Second alternate title")));
assertTrue(citation.getPresentationForms().add(PresentationForm.MAP_HARDCOPY));
return citation;
}
use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.
the class TreeNodeChildrenTest method metadataWithSingletonInCollections.
/**
* Creates a shallow metadata object with singleton value in collections.
* This method creates the following metadata:
*
* {@preformat text
* DefaultCitation
* ├─Title………………………………………………… Some title
* ├─Alternate title……………………… First alternate title
* ├─Edition…………………………………………… Some edition
* ├─Presentation form………………… Map digital
* └─Other citation details…… Some other details
* }
*/
static DefaultCitation metadataWithSingletonInCollections() {
final DefaultCitation citation = metadataWithoutCollections();
assertTrue(citation.getAlternateTitles().add(new SimpleInternationalString("First alternate title")));
assertTrue(citation.getPresentationForms().add(PresentationForm.MAP_DIGITAL));
return citation;
}
use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.
the class DefaultExtentTest method testIntersect.
/**
* Tests {@link DefaultExtent#intersect(Extent)}.
*/
@Test
public void testIntersect() {
final DefaultGeographicBoundingBox bounds1 = new DefaultGeographicBoundingBox(10, 20, 30, 40);
final DefaultGeographicBoundingBox bounds2 = new DefaultGeographicBoundingBox(16, 18, 31, 42);
final DefaultGeographicBoundingBox clip = new DefaultGeographicBoundingBox(15, 25, 26, 32);
final DefaultGeographicBoundingBox expected1 = new DefaultGeographicBoundingBox(15, 20, 30, 32);
final DefaultGeographicBoundingBox expected2 = new DefaultGeographicBoundingBox(16, 18, 31, 32);
final DefaultExtent e1 = new DefaultExtent("Somewhere", bounds1, null, null);
final DefaultExtent e2 = new DefaultExtent("Somewhere", clip, null, null);
e1.getGeographicElements().add(bounds2);
e1.intersect(e2);
assertEquals("description", "Somewhere", e1.getDescription().toString());
assertFalse("isNil(description)", e1.getDescription() instanceof NilObject);
assertArrayEquals("geographicElements", new DefaultGeographicBoundingBox[] { expected1, expected2 }, e1.getGeographicElements().toArray());
/*
* Change the description and test again. That description should be considered missing
* because we have a mismatch. Also change abounding box in such a way that there is no
* intersection. That bounding box should be omitted.
*/
bounds2.setBounds(8, 12, 33, 35);
e1.setGeographicElements(Arrays.asList(bounds1, bounds2));
e2.setDescription(new SimpleInternationalString("Somewhere else"));
e1.intersect(e2);
assertTrue("isNil(description)", e1.getDescription() instanceof NilObject);
assertArrayEquals("geographicElements", new DefaultGeographicBoundingBox[] { expected1 }, e1.getGeographicElements().toArray());
}
use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.
the class MetadataSourceTest method testSearch.
/**
* Tests {@link MetadataSource#search(Object)}
*
* @param source the instance to test.
* @throws MetadataStoreException if an error occurred while querying the database.
*/
@TestStep
public static void testSearch(final MetadataSource source) throws MetadataStoreException {
final DefaultCitation specification = new DefaultCitation("PNG (Portable Network Graphics) Specification");
specification.setAlternateTitles(Collections.singleton(new SimpleInternationalString("PNG")));
final DefaultFormat format = new DefaultFormat();
format.setFormatSpecificationCitation(specification);
assertEquals("PNG", source.search(format));
specification.setTitle(null);
assertNull(source.search(format));
}
Aggregations