Search in sources :

Example 6 with DefaultCitation

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

Example 7 with DefaultCitation

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);
}
Also used : InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) Collection(java.util.Collection) IdentifiedObject(org.opengis.referencing.IdentifiedObject) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString)

Example 8 with DefaultCitation

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

Example 9 with DefaultCitation

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());
}
Also used : DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) SimpleIdentifier(org.apache.sis.internal.simple.SimpleIdentifier) Test(org.junit.Test)

Example 10 with DefaultCitation

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

Aggregations

DefaultCitation (org.apache.sis.metadata.iso.citation.DefaultCitation)65 Test (org.junit.Test)35 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)32 DependsOnMethod (org.apache.sis.test.DependsOnMethod)21 InternationalString (org.opengis.util.InternationalString)14 Citation (org.opengis.metadata.citation.Citation)10 IdentifiedObject (org.opengis.referencing.IdentifiedObject)9 ImmutableIdentifier (org.apache.sis.metadata.iso.ImmutableIdentifier)5 DefaultResponsibleParty (org.apache.sis.metadata.iso.citation.DefaultResponsibleParty)5 URI (java.net.URI)3 DefaultIdentifier (org.apache.sis.metadata.iso.DefaultIdentifier)3 DefaultMetadata (org.apache.sis.metadata.iso.DefaultMetadata)3 DefaultCitationTest (org.apache.sis.metadata.iso.citation.DefaultCitationTest)3 DefaultOnlineResource (org.apache.sis.metadata.iso.citation.DefaultOnlineResource)3 ArrayList (java.util.ArrayList)2 CI_Citation (org.apache.sis.internal.jaxb.metadata.CI_Citation)2 SimpleIdentifiedObject (org.apache.sis.internal.simple.SimpleIdentifiedObject)2 SimpleIdentifier (org.apache.sis.internal.simple.SimpleIdentifier)2 DefaultCitationDate (org.apache.sis.metadata.iso.citation.DefaultCitationDate)2 DefaultIndividual (org.apache.sis.metadata.iso.citation.DefaultIndividual)2