Search in sources :

Example 71 with DependsOnMethod

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());
}
Also used : DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 72 with DependsOnMethod

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());
}
Also used : DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) TreeTable(org.apache.sis.util.collection.TreeTable) DefaultTreeTable(org.apache.sis.util.collection.DefaultTreeTable) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 73 with DependsOnMethod

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());
}
Also used : DefaultTreeTable(org.apache.sis.util.collection.DefaultTreeTable) DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 74 with DependsOnMethod

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());
}
Also used : DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 75 with DependsOnMethod

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());
}
Also used : DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) TreeTable(org.apache.sis.util.collection.TreeTable) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Aggregations

DependsOnMethod (org.apache.sis.test.DependsOnMethod)298 Test (org.junit.Test)296 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)27 ProjectedCRS (org.opengis.referencing.crs.ProjectedCRS)23 DefaultCitation (org.apache.sis.metadata.iso.citation.DefaultCitation)21 CoordinateOperation (org.opengis.referencing.operation.CoordinateOperation)21 Rectangle (java.awt.Rectangle)19 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)19 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)18 GeographicCRS (org.opengis.referencing.crs.GeographicCRS)15 Random (java.util.Random)11 Matrix (org.opengis.referencing.operation.Matrix)11 HashMap (java.util.HashMap)10 IdentifiedObject (org.opengis.referencing.IdentifiedObject)8 ReferenceIdentifier (org.opengis.referencing.ReferenceIdentifier)8 MathTransform (org.opengis.referencing.operation.MathTransform)8 DefaultFeatureType (org.apache.sis.feature.DefaultFeatureType)7 DefaultFeatureTypeTest (org.apache.sis.feature.DefaultFeatureTypeTest)7 DirectPosition2D (org.apache.sis.geometry.DirectPosition2D)7 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)7