Search in sources :

Example 31 with DefaultCitation

use of org.apache.sis.metadata.iso.citation.DefaultCitation in project sis by apache.

the class MetadataStandardTest method testValueMap.

/**
 * Tests the {@link MetadataStandard#asValueMap(Object, Class, KeyNamePolicy, ValueExistencePolicy)} implementation.
 * This test duplicates {@link ValueMapTest}, but is done here again as an integration test and because many
 * {@code MetadataStandard} methods depend on it ({@code equals}, {@code hashCode}, {@code prune}, <i>etc.</i>).
 */
@Test
@DependsOnMethod("testGetAccessor")
public void testValueMap() {
    final DefaultCitation instance = new DefaultCitation(HardCodedCitations.EPSG);
    final Map<String, Object> map = MetadataStandard.ISO_19115.asValueMap(instance, null, KeyNamePolicy.JAVABEANS_PROPERTY, ValueExistencePolicy.NON_EMPTY);
    assertFalse("The properties map shall not be empty.", map.isEmpty());
    assertEquals("Unexpected number of properties.", 4, map.size());
    /*
         * Verify the set of keys in the ValueMap.
         *
         * Note: the iterator order (and consequently, the order of elements in the following
         * string representation) is determined by the @XmlType(…) annotation and verified by
         * PropertyAccessorTest.testConstructor().
         */
    final Set<String> keys = map.keySet();
    assertEquals("[title, identifiers, citedResponsibleParties, presentationForms]", keys.toString());
    assertTrue("Shall exist and be defined.", keys.contains("title"));
    assertTrue("Shall exist and be defined.", keys.contains("getTitle"));
    assertTrue("Shall exist and be defined.", keys.contains("identifier"));
    assertTrue("Shall exist and be defined.", keys.contains("identifiers"));
    assertTrue("Shall exist and be defined.", keys.contains("getIdentifiers"));
    assertTrue("Shall exist and be defined.", keys.contains("citedResponsibleParty"));
    assertTrue("Shall exist and be defined.", keys.contains("citedResponsibleParties"));
    assertFalse("Shall exist but be undefined.", keys.contains("ISBN"));
    assertFalse("Shall not exists.", keys.contains("dummy"));
    /*
         * Verifies values.
         */
    assertEquals("title", "EPSG Geodetic Parameter Dataset", map.get("title").toString());
    assertEquals("title", "EPSG Geodetic Parameter Dataset", map.get("getTitle").toString());
    assertEquals("EPSG", PropertyAccessorTest.getSingletonCode(map.get("identifiers")));
}
Also used : DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) SimpleIdentifiedObject(org.apache.sis.internal.simple.SimpleIdentifiedObject) IdentifiedObject(org.opengis.referencing.IdentifiedObject) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 32 with DefaultCitation

use of org.apache.sis.metadata.iso.citation.DefaultCitation in project sis by apache.

the class PropertyAccessorTest method testSetWithConversion.

/**
 * Tests the {@link PropertyAccessor#set(int, Object, Object, int)} method
 * with a value that will need to be converted. The conversion will be from
 * {@link String} to {@link InternationalString}. The created metadata object is:
 *
 * {@preformat text
 *   DefaultCitation
 *     └─Title……………… Some title
 * }
 */
@Test
@DependsOnMethod("testSet")
public void testSetWithConversion() {
    final String expected = "Some title";
    final DefaultCitation instance = new DefaultCitation();
    final PropertyAccessor accessor = createPropertyAccessor();
    final int index = accessor.indexOf("title", true);
    final Object oldValue = accessor.set(index, instance, expected, RETURN_PREVIOUS);
    final Object value = accessor.get(index, instance);
    assertNull("title", oldValue);
    assertInstanceOf("title", InternationalString.class, value);
    assertSame("title", expected, value.toString());
    assertSame("title", value, instance.getTitle());
}
Also used : DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) IdentifiedObject(org.opengis.referencing.IdentifiedObject) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 33 with DefaultCitation

use of org.apache.sis.metadata.iso.citation.DefaultCitation in project sis by apache.

the class PropertyAccessorTest method testEquals.

/**
 * Tests the equals methods.
 */
@Test
public void testEquals() {
    DefaultCitation citation = HardCodedCitations.EPSG;
    final PropertyAccessor accessor = createPropertyAccessor();
    assertFalse(accessor.equals(citation, HardCodedCitations.SIS, ComparisonMode.STRICT));
    assertTrue(accessor.equals(citation, HardCodedCitations.EPSG, ComparisonMode.STRICT));
    // Same test than above, but on a copy of the EPSG constant.
    citation = new DefaultCitation(HardCodedCitations.EPSG);
    assertFalse(accessor.equals(citation, HardCodedCitations.SIS, ComparisonMode.STRICT));
    assertTrue(accessor.equals(citation, HardCodedCitations.EPSG, ComparisonMode.STRICT));
    // Identifiers shall be stored in different collection instances with equal content.
    final int index = accessor.indexOf("identifiers", true);
    final Object source = accessor.get(index, HardCodedCitations.EPSG);
    final Object target = accessor.get(index, citation);
    assertInstanceOf("identifiers", Collection.class, source);
    assertInstanceOf("identifiers", Collection.class, target);
    assertNotSame("Distinct objects shall have distinct collections.", source, target);
    assertEquals("The two collections shall have the same content.", source, target);
    assertEquals("EPSG", getSingletonCode(target));
    // Set the identifiers to null, which should clear the collection.
    assertEquals("Expected the previous value.", source, accessor.set(index, citation, null, RETURN_PREVIOUS));
    final Object value = accessor.get(index, citation);
    assertNotNull("Should have replaced null by an empty collection.", value);
    assertTrue("Should have replaced null by an empty collection.", ((Collection<?>) value).isEmpty());
}
Also used : DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) IdentifiedObject(org.opengis.referencing.IdentifiedObject) Test(org.junit.Test)

Example 34 with DefaultCitation

use of org.apache.sis.metadata.iso.citation.DefaultCitation in project sis by apache.

the class PropertyAccessorTest method testSetInAppendMode.

/**
 * Tests the {@link PropertyAccessor#set(int, Object, Object, int)} method in
 * {@link PropertyAccessor#APPEND} mode. In this mode, new collections
 * are added into existing collections instead than replacing them.
 * The metadata object created by this test after the merge is:
 *
 * {@preformat text
 *   DefaultCitation
 *     ├─Title……………………………………………………… Added title
 *     ├─Alternate title (1 of 4)…… Old title 1
 *     ├─Alternate title (2 of 4)…… Old title 2
 *     ├─Alternate title (3 of 4)…… New title 1
 *     └─Alternate title (4 of 4)…… New title 2
 * }
 *
 * @see #testSetCollection()
 */
public void testSetInAppendMode() {
    final DefaultCitation instance = new DefaultCitation();
    final List<InternationalString> oldTitles = Arrays.<InternationalString>asList(new SimpleInternationalString("Old title 1"), new SimpleInternationalString("Old title 2"));
    final List<InternationalString> newTitles = Arrays.<InternationalString>asList(new SimpleInternationalString("New title 1"), new SimpleInternationalString("New title 2"));
    final List<InternationalString> merged = new ArrayList<>(oldTitles);
    assertTrue(merged.addAll(newTitles));
    // Set the title.
    instance.setAlternateTitles(oldTitles);
    final PropertyAccessor accessor = createPropertyAccessor();
    final int titleIndex = accessor.indexOf("title", true);
    Object titleChanged = accessor.set(titleIndex, instance, "Added title", APPEND);
    // Set the alternate titles.
    final int index = accessor.indexOf("alternateTitles", true);
    final Object changed = accessor.set(index, instance, newTitles, APPEND);
    final Object newValue = accessor.get(index, instance);
    // Verify the values.
    assertEquals("set(…, APPEND)", Boolean.TRUE, titleChanged);
    assertEquals("set(…, APPEND)", Boolean.TRUE, changed);
    assertEquals("get(…)", merged, newValue);
    assertSame("alternateTitles", newValue, instance.getAlternateTitles());
    assertTitleEquals("title", "Added title", instance);
    // Test setting again the title to the same value.
    titleChanged = accessor.set(titleIndex, instance, "Added title", APPEND);
    assertEquals("set(…, APPEND)", Boolean.FALSE, titleChanged);
    assertTitleEquals("title", "Added title", instance);
    // Test setting the title to a different value.
    titleChanged = accessor.set(titleIndex, instance, "Different title", APPEND);
    // Operation shall be refused.
    assertNull("set(…, APPEND)", titleChanged);
    assertTitleEquals("title", "Added title", instance);
}
Also used : DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) ArrayList(java.util.ArrayList) IdentifiedObject(org.opengis.referencing.IdentifiedObject)

Example 35 with DefaultCitation

use of org.apache.sis.metadata.iso.citation.DefaultCitation in project sis by apache.

the class PropertyAccessorTest method testSetNull.

/**
 * Tests the {@link PropertyAccessor#set(int, Object, Object, int)} method with a {@code null} value.
 * Setting a property to {@code null} is equivalent to removing that property value.
 * The metadata object used by this test (before removal) is:
 *
 * {@preformat text
 *   DefaultCitation
 *     └─Title………………………… Some title
 * }
 */
@Test
@DependsOnMethod("testSet")
public void testSetNull() {
    final DefaultCitation instance = new DefaultCitation("Some title");
    final PropertyAccessor accessor = createPropertyAccessor();
    final InternationalString title = instance.getTitle();
    final int index = accessor.indexOf("title", true);
    // Sanity check before to continue.
    assertEquals("Some title", title.toString());
    assertNull("title", accessor.set(index, instance, null, RETURN_NULL));
    assertNull("title", instance.getTitle());
    instance.setTitle(title);
    assertSame("title", title, accessor.set(index, instance, null, RETURN_PREVIOUS));
    assertNull("title", instance.getTitle());
}
Also used : DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) 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