use of org.apache.sis.test.DependsOnMethod in project sis by apache.
the class TreeNodeChildrenTest method testReadOnlyWithSingletonInCollections.
/**
* Tests read-only operations on a list of properties for a shallow metadata object with singleton
* values in collections.
*/
@Test
@DependsOnMethod("testReadOnlyWithoutCollections")
public void testReadOnlyWithSingletonInCollections() {
final DefaultCitation citation = metadataWithSingletonInCollections();
final TreeNodeChildren children = create(citation, ValueExistencePolicy.NON_EMPTY);
final String[] expected = { "Some title", "First alternate title", "Some edition", "PresentationForm[MAP_DIGITAL]", "Some other details" };
assertEquals("titleProperty", -1, children.titleProperty);
assertFalse("isEmpty()", children.isEmpty());
assertEquals("size()", expected.length, children.size());
assertAllNextEqual(expected, children.iterator());
}
use of org.apache.sis.test.DependsOnMethod in project sis by apache.
the class TreeNodeChildrenTest method testSimplifiable.
/**
* Tests a metadata than can be simplified by displaying a child property value directly as the parent value.
*/
@Test
@DependsOnMethod("testReadOnlyWithoutCollections")
public void testSimplifiable() {
final DefaultCitation citation = metadataSimplifiable();
/*
* DefaultCitation
* └─Date
* ├─Date………………… 2012-01-01
* └─Date type…… Creation
*
* We need to perform the tests on the "Date" node, not on the "DefaultCitation" node.
*/
final TreeTable.Node node = TestUtilities.getSingleton(create(citation, ValueExistencePolicy.COMPACT));
assertEquals("value", 1325376000000L, ((Date) node.getValue(TableColumn.VALUE)).getTime());
final TreeNodeChildren children = (TreeNodeChildren) node.getChildren();
final String[] expected = { // The "Date" node should be omitted because merged with the parent "Date" node.
"DateType[CREATION]" };
assertEquals("titleProperty", 0, children.titleProperty);
assertFalse("isEmpty()", children.isEmpty());
assertEquals("size()", expected.length, children.size());
assertAllNextEqual(expected, children.iterator());
}
use of org.apache.sis.test.DependsOnMethod in project sis by apache.
the class TreeNodeChildrenTest method testAdd.
/**
* Tests the {@link TreeNodeChildren#add(TreeTable.Node)} method.
*/
@Test
@DependsOnMethod("testReadOnlyWithMultiOccurrences")
public void testAdd() {
final DefaultCitation citation = metadataWithMultiOccurrences();
final TreeNodeChildren children = create(citation, ValueExistencePolicy.NON_EMPTY);
assertEquals("titleProperty", -1, children.titleProperty);
final DefaultTreeTable.Node toAdd = new DefaultTreeTable.Node(new DefaultTreeTable(TableColumn.IDENTIFIER, TableColumn.VALUE));
final String[] expected = { "Some title", "First alternate title", "Second alternate title", // After addition
"Third alternate title", // After "addition" (actually change).
"New edition", // After addition
"PresentationForm[IMAGE_DIGITAL]", "PresentationForm[MAP_DIGITAL]", "PresentationForm[MAP_HARDCOPY]", "Some other details" };
toAdd.setValue(TableColumn.IDENTIFIER, "edition");
toAdd.setValue(TableColumn.VALUE, citation.getEdition());
assertFalse("Adding the same value shall be a no-op.", children.add(toAdd));
toAdd.setValue(TableColumn.VALUE, "New edition");
try {
children.add(toAdd);
fail("Setting a different value shall be refused.");
} catch (IllegalStateException e) {
assertTrue(e.getMessage().contains("edition"));
}
// Clears so we are allowed to add.
citation.setEdition(null);
assertTrue("Setting a new value shall be a change.", children.add(toAdd));
toAdd.setValue(TableColumn.IDENTIFIER, "presentationForm");
toAdd.setValue(TableColumn.VALUE, PresentationForm.MAP_DIGITAL);
assertFalse("Adding the same value shall be a no-op.", children.add(toAdd));
toAdd.setValue(TableColumn.VALUE, PresentationForm.IMAGE_DIGITAL);
assertTrue("Adding a new value shall be a change.", children.add(toAdd));
toAdd.setValue(TableColumn.IDENTIFIER, "alternateTitle");
toAdd.setValue(TableColumn.VALUE, "Third alternate title");
assertTrue("Adding a new value shall be a change.", children.add(toAdd));
assertEquals("size()", expected.length, children.size());
assertAllNextEqual(expected, children.iterator());
}
use of org.apache.sis.test.DependsOnMethod in project sis by apache.
the class TreeNodeChildrenTest method testShowAll.
/**
* Tests the children list with the {@link ValueExistencePolicy#ALL}.
*/
@Test
@DependsOnMethod("testReadOnlyWithMultiOccurrences")
public void testShowAll() {
final DefaultCitation citation = metadataWithMultiOccurrences();
final TreeNodeChildren children = create(citation, ValueExistencePolicy.ALL);
final String[] expected = { "Some title", "First alternate title", "Second alternate title", // dates (collection)
null, "Some edition", // edition date
null, // identifiers (collection)
null, // cited responsibly parties (collection)
null, "PresentationForm[MAP_DIGITAL]", "PresentationForm[MAP_HARDCOPY]", // series
null, "Some other details", // ISBN
null, // ISSN
null, // onlineResources (collection)
null, // graphics (collection)
null };
assertEquals("titleProperty", -1, children.titleProperty);
assertFalse("isEmpty()", children.isEmpty());
assertEquals("size()", expected.length, children.size());
assertAllNextEqual(expected, children.iterator());
}
use of org.apache.sis.test.DependsOnMethod in project sis by apache.
the class TreeNodeTest method testNewChild.
/**
* Tests {@link TreeNode#newChild()}.
*/
@Test
@DependsOnMethod("testGetValue")
public void testNewChild() {
final DefaultCitation citation = metadataWithHierarchy();
final TreeNode node = create(citation, Citation.class);
/*
* Ensure that we can not overwrite existing nodes.
*/
TreeTable.Node child = node.newChild();
child.setValue(TableColumn.IDENTIFIER, "title");
try {
child.setValue(TableColumn.VALUE, "A new title");
fail("Attemps to overwrite an existing value shall fail.");
} catch (IllegalStateException e) {
assertTrue(e.getMessage().contains("title"));
}
/*
* Clear the title and try again. This time, it shall work.
*/
citation.setTitle(null);
child = node.newChild();
child.setValue(TableColumn.IDENTIFIER, "title");
child.setValue(TableColumn.VALUE, "A new title");
assertTitleEquals("citation", "A new title", citation);
assertSame(citation.getTitle(), child.getValue(TableColumn.VALUE));
/*
* Try adding a new element in a collection.
* Note that the code below imply a conversion from String to InternationalString.
*/
child = node.newChild();
child.setValue(TableColumn.IDENTIFIER, "alternateTitle");
child.setValue(TableColumn.VALUE, "Third alternate title");
assertEquals(3, citation.getAlternateTitles().size());
assertEquals("Third alternate title", child.getValue(TableColumn.VALUE).toString());
}
Aggregations