Search in sources :

Example 1 with SimpleIdentifier

use of org.apache.sis.internal.simple.SimpleIdentifier 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 2 with SimpleIdentifier

use of org.apache.sis.internal.simple.SimpleIdentifier 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 3 with SimpleIdentifier

use of org.apache.sis.internal.simple.SimpleIdentifier in project sis by apache.

the class BuilderTest method testCreationFromObject.

/**
 * Tests the {@link Builder#Builder(IdentifiedObject)} constructor.
 *
 * @since 0.6
 */
@Test
public void testCreationFromObject() {
    final Map<String, Object> properties = new HashMap<>();
    final Identifier id = new SimpleIdentifier(null, "An identifier", false);
    assertNull(properties.put(AbstractIdentifiedObject.IDENTIFIERS_KEY, id));
    assertNull(properties.put(AbstractIdentifiedObject.ALIAS_KEY, "An alias"));
    assertNull(properties.put(AbstractIdentifiedObject.NAME_KEY, "Dummy object"));
    assertNull(properties.put(AbstractIdentifiedObject.REMARKS_KEY, "Some remarks"));
    final BuilderMock builder = new BuilderMock(new AbstractIdentifiedObject(properties));
    assertEquals("Expected only name, remarks and deprecated status.", 3, builder.properties.size());
    builder.onCreate(false);
    assertEquals("Expected name, aliases, identifiers and remarks.", 5, builder.properties.size());
    assertEquals(AbstractIdentifiedObject.NAME_KEY, "Dummy object", builder.properties.get(AbstractIdentifiedObject.NAME_KEY).toString());
    assertEquals(AbstractIdentifiedObject.REMARKS_KEY, "Some remarks", builder.properties.get(AbstractIdentifiedObject.REMARKS_KEY).toString());
    assertEquals(AbstractIdentifiedObject.ALIAS_KEY, "An alias", ((Object[]) builder.properties.get(AbstractIdentifiedObject.ALIAS_KEY))[0].toString());
    assertSame(AbstractIdentifiedObject.IDENTIFIERS_KEY, id, ((Object[]) builder.properties.get(AbstractIdentifiedObject.IDENTIFIERS_KEY))[0]);
}
Also used : ImmutableIdentifier(org.apache.sis.metadata.iso.ImmutableIdentifier) SimpleIdentifier(org.apache.sis.internal.simple.SimpleIdentifier) Identifier(org.opengis.metadata.Identifier) ReferenceIdentifier(org.opengis.referencing.ReferenceIdentifier) HashMap(java.util.HashMap) SimpleIdentifier(org.apache.sis.internal.simple.SimpleIdentifier) Test(org.junit.Test)

Aggregations

SimpleIdentifier (org.apache.sis.internal.simple.SimpleIdentifier)3 Test (org.junit.Test)3 DefaultCitation (org.apache.sis.metadata.iso.citation.DefaultCitation)2 HashMap (java.util.HashMap)1 ImmutableIdentifier (org.apache.sis.metadata.iso.ImmutableIdentifier)1 DependsOnMethod (org.apache.sis.test.DependsOnMethod)1 Identifier (org.opengis.metadata.Identifier)1 ReferenceIdentifier (org.opengis.referencing.ReferenceIdentifier)1