use of org.apache.sis.metadata.iso.citation.DefaultCitation in project sis by apache.
the class PropertyAccessorTest method testSet.
/**
* Tests the {@link PropertyAccessor#set(int, Object, Object, int)} method
* with a value to be stored <cite>as-is</cite> (without conversion).
* The metadata object created by this test is:
*
* {@preformat text
* DefaultCitation
* ├─Title………………………… Some title
* ├─Identifier
* │ ├─Code………………… Some ISBN code
* │ └─Authority
* │ └─Title…… ISBN
* └─ISBN…………………………… Some ISBN code
* }
*/
@Test
@DependsOnMethod("testGet")
public void testSet() {
final DefaultCitation instance = new DefaultCitation();
final PropertyAccessor accessor = createPropertyAccessor();
Object newValue;
int index;
newValue = new SimpleInternationalString("Some title");
index = accessor.indexOf("title", true);
assertNull("title", accessor.set(index, instance, newValue, RETURN_PREVIOUS));
assertSame("title", newValue, accessor.get(index, instance));
assertSame("title", newValue, instance.getTitle());
newValue = "Some ISBN code";
index = accessor.indexOf("ISBN", true);
assertNull("ISBN", accessor.set(index, instance, newValue, RETURN_PREVIOUS));
assertSame("ISBN", newValue, accessor.get(index, instance));
assertSame("ISBN", newValue, instance.getISBN());
}
use of org.apache.sis.metadata.iso.citation.DefaultCitation in project sis by apache.
the class PropertyAccessorTest method testSetIntoCollection.
/**
* Tests the {@link PropertyAccessor#set(int, Object, Object, int)} method
* when adding elements in a collection, with or without conversion of type.
*/
private static void testSetIntoCollection(final boolean conversion) {
final String text1 = "An other title";
final String text2 = "Yet an other title";
final InternationalString title1 = new SimpleInternationalString(text1);
final InternationalString title2 = new SimpleInternationalString(text2);
final DefaultCitation instance = new DefaultCitation("Ignored title");
final PropertyAccessor accessor = createPropertyAccessor();
final int index = accessor.indexOf("alternateTitles", true);
// Insert the first value. Old collection shall be empty.
Object oldValue = accessor.set(index, instance, conversion ? text1 : title1, RETURN_PREVIOUS);
assertInstanceOf("alternateTitles", Collection.class, oldValue);
assertTrue("alternateTitles", ((Collection<?>) oldValue).isEmpty());
// Insert the second value. Old collection shall contain the first value.
oldValue = accessor.set(index, instance, conversion ? text2 : title2, RETURN_PREVIOUS);
assertInstanceOf("alternateTitles", Collection.class, oldValue);
oldValue = getSingleton((Collection<?>) oldValue);
assertSame("alternateTitles", text1, oldValue.toString());
if (!conversion) {
assertSame("InternationalString should have been stored as-is.", title1, oldValue);
}
// Check final collection content.
final List<InternationalString> expected = Arrays.asList(title1, title2);
assertEquals("alternateTitles", expected, accessor.get(index, instance));
assertTitleEquals("title", "Ignored title", instance);
}
use of org.apache.sis.metadata.iso.citation.DefaultCitation in project sis by apache.
the class PrunerTest method testPrune.
/**
* Tests the {@link ModifiableMetadata#prune()} method.
*/
@Test
@DependsOnMethod("testIsEmpty")
public void testPrune() {
metadata.setMetadataIdentifier(new SimpleIdentifier(null, "A file identifiers", false));
identification.setCitation(new DefaultCitation("A citation title"));
assertFalse(isNullOrEmpty(metadata.getMetadataIdentifier()));
assertFalse(isNullOrEmpty(identification.getCitation()));
assertEquals(1, metadata.getIdentificationInfo().size());
assertEquals(1, identification.getExtents().size());
assertEquals(1, extent.getGeographicElements().size());
assertFalse(metadata.isEmpty());
metadata.prune();
assertFalse(isNullOrEmpty(metadata.getMetadataIdentifier()));
assertFalse(isNullOrEmpty(identification.getCitation()));
assertEquals(1, metadata.getIdentificationInfo().size());
assertEquals(0, identification.getExtents().size());
assertEquals(0, extent.getGeographicElements().size());
assertFalse(metadata.isEmpty());
metadata.setMetadataIdentifier(new SimpleIdentifier(null, " ", false));
identification.setCitation(new DefaultCitation(" "));
assertNotNull(metadata.getMetadataIdentifier());
metadata.prune();
assertNull(metadata.getMetadataIdentifier());
assertNull(identification.getCitation());
assertTrue(metadata.getIdentificationInfo().isEmpty());
assertTrue(identification.getExtents().isEmpty());
assertTrue(extent.getGeographicElements().isEmpty());
assertTrue(metadata.isEmpty());
}
use of org.apache.sis.metadata.iso.citation.DefaultCitation in project sis by apache.
the class PrunerTest method testIsEmpty.
/**
* Tests the {@link AbstractMetadata#isEmpty()} method.
*/
@Test
public void testIsEmpty() {
/*
* Initially empty tree, or tree with only empty element.
*/
assertTrue("GeographicBoundingBox", bbox.isEmpty());
assertTrue("Extent", extent.isEmpty());
assertTrue("Scale", scale.isEmpty());
assertTrue("DataIdentification", identification.isEmpty());
assertTrue("Metadata", metadata.isEmpty());
/*
* Set a non-empty identification info.
*/
identification.setCitation(new DefaultCitation("A citation title"));
assertTrue("GeographicBoundingBox", bbox.isEmpty());
assertTrue("Extent", extent.isEmpty());
assertTrue("Scale", scale.isEmpty());
assertFalse("DataIdentification", identification.isEmpty());
assertFalse("Metadata", metadata.isEmpty());
/*
* Set a non-empty metadata info.
*/
metadata.setMetadataIdentifier(new SimpleIdentifier(null, "A file identifiers", false));
assertTrue("GeographicBoundingBox", bbox.isEmpty());
assertTrue("Extent", extent.isEmpty());
assertTrue("Scale", scale.isEmpty());
assertFalse("DataIdentification", identification.isEmpty());
assertFalse("Metadata", metadata.isEmpty());
/*
* Set an empty string in an element.
*/
identification.setCitation(new DefaultCitation(" "));
assertTrue("GeographicBoundingBox", bbox.isEmpty());
assertTrue("Extent", extent.isEmpty());
assertTrue("Scale", scale.isEmpty());
assertTrue("DataIdentification", identification.isEmpty());
assertFalse("Metadata", metadata.isEmpty());
/*
* Set a representative fraction.
*/
scale.setDenominator(1000);
assertTrue("GeographicBoundingBox", bbox.isEmpty());
assertTrue("Extent", extent.isEmpty());
assertFalse("Scale", scale.isEmpty());
assertFalse("DataIdentification", identification.isEmpty());
assertFalse("Metadata", metadata.isEmpty());
/*
* Set an empty string in an element.
*/
scale.setScale(Double.NaN);
metadata.setMetadataIdentifier(new SimpleIdentifier(null, " ", false));
assertTrue("Scale", scale.isEmpty());
assertTrue("DataIdentification", identification.isEmpty());
assertTrue("Metadata", metadata.isEmpty());
}
use of org.apache.sis.metadata.iso.citation.DefaultCitation in project sis by apache.
the class TreeNodeChildrenTest method testRemoveWithSingletonInCollections.
/**
* Tests the {@link Iterator#remove()} operation on a list of properties with
* collections containing only one element.
*/
@Test
@DependsOnMethod({ "testRemoveWithoutCollections", "testReadOnlyWithSingletonInCollections" })
public void testRemoveWithSingletonInCollections() {
final DefaultCitation citation = metadataWithSingletonInCollections();
final TreeNodeChildren children = create(citation, ValueExistencePolicy.NON_EMPTY);
assertEquals("titleProperty", -1, children.titleProperty);
testRemove(TestUtilities.createRandomNumberGenerator(), children);
}
Aggregations