Search in sources :

Example 1 with DefaultCitation

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

the class MetadataStandardTest method testHashCode.

/**
 * Tests {@link MetadataStandard#hashCode(Object)} using {@link HashSet} as the reference
 * implementation for computing hash code values. The hash code is defined as the sum of
 * hash code values of all non-empty properties, plus the hash code of the interface.
 */
@Test
@DependsOnMethod("testValueMap")
public void testHashCode() {
    standard = MetadataStandard.ISO_19115;
    final DefaultCitation instance = HardCodedCitations.EPSG;
    final Map<String, Object> map = standard.asValueMap(instance, null, KeyNamePolicy.JAVABEANS_PROPERTY, ValueExistencePolicy.NON_EMPTY);
    // Actually 'testValueMap()' job, but verified for safety.
    assertFalse(map.isEmpty());
    assertEquals("hashCode()", new HashSet<>(map.values()).hashCode() + Citation.class.hashCode(), standard.hashCode(instance));
}
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 2 with DefaultCitation

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

the class MetadataStandardTest method testEquals.

/**
 * Tests the {@link MetadataStandard#equals(Object, Object, ComparisonMode)} method.
 */
@Test
@DependsOnMethod("testGetAccessor")
public void testEquals() {
    standard = MetadataStandard.ISO_19115;
    // Self equality test
    DefaultCitation instance = HardCodedCitations.EPSG;
    assertFalse(standard.equals(instance, HardCodedCitations.SIS, ComparisonMode.STRICT));
    assertTrue(standard.equals(instance, HardCodedCitations.EPSG, ComparisonMode.STRICT));
    // Test comparison with a copy
    instance = new DefaultCitation(HardCodedCitations.EPSG);
    assertFalse(standard.equals(instance, HardCodedCitations.SIS, ComparisonMode.STRICT));
    assertTrue(standard.equals(instance, HardCodedCitations.EPSG, ComparisonMode.STRICT));
    // test comparison with a modified copy
    instance.setTitle(new SimpleInternationalString("A dummy title"));
    assertFalse(standard.equals(instance, HardCodedCitations.EPSG, ComparisonMode.STRICT));
}
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 3 with DefaultCitation

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

the class PropertyAccessorTest method testSetCollection.

/**
 * Tests the {@link PropertyAccessor#set(int, Object, Object, int)} method when the value
 * is a collection. The new collection shall replace the previous one (no merge expected).
 * The metadata object created by this test after the replacement is:
 *
 * {@preformat text
 *   DefaultCitation
 *     ├─Title……………………………………………………… Ignored title
 *     ├─Alternate title (1 of 2)…… New title 1
 *     └─Alternate title (2 of 2)…… New title 2
 * }
 *
 * @see #testSetInAppendMode()
 */
@Test
@DependsOnMethod("testSet")
public void testSetCollection() {
    final DefaultCitation instance = new DefaultCitation("Ignored title");
    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"));
    // Set the alternate titles.
    instance.setAlternateTitles(oldTitles);
    final PropertyAccessor accessor = createPropertyAccessor();
    final int index = accessor.indexOf("alternateTitles", true);
    final Object oldValue = accessor.set(index, instance, newTitles, RETURN_PREVIOUS);
    final Object newValue = accessor.get(index, instance);
    // Verify the values.
    assertEquals("set(…, RETURN_PREVIOUS)", oldTitles, oldValue);
    assertEquals("get(…)", newTitles, newValue);
    assertSame("alternateTitles", newValue, instance.getAlternateTitles());
    assertTitleEquals("title", "Ignored 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) IdentifiedObject(org.opengis.referencing.IdentifiedObject) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 4 with DefaultCitation

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

the class PropertyAccessorTest method testHashCode.

/**
 * Tests {@link PropertyAccessor#hashCode(Object)}.
 */
@Test
public void testHashCode() {
    final DefaultCitation instance = new DefaultCitation();
    final PropertyAccessor accessor = createPropertyAccessor();
    final int baseCode = Citation.class.hashCode();
    int hashCode = accessor.hashCode(instance);
    assertEquals("Empty metadata.", baseCode, hashCode);
    final InternationalString title = new SimpleInternationalString("Some title");
    instance.setTitle(title);
    hashCode = accessor.hashCode(instance);
    assertEquals("Metadata with a single value.", baseCode + title.hashCode(), hashCode);
    final InternationalString alternateTitle = new SimpleInternationalString("An other title");
    instance.setAlternateTitles(singleton(alternateTitle));
    hashCode = accessor.hashCode(instance);
    assertEquals("Metadata with two values.", baseCode + title.hashCode() + Arrays.asList(alternateTitle).hashCode(), hashCode);
}
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) Test(org.junit.Test)

Example 5 with DefaultCitation

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

the class PropertyAccessorTest method testGet.

/**
 * Tests the {@link PropertyAccessor#get(int, Object)} method on the {@link HardCodedCitations#ISO_19111} constant.
 * The metadata object read by this test is:
 *
 * {@preformat text
 *   DefaultCitation
 *     ├─Title…………………………………… International Organization for Standardization
 *     ├─Alternate title………… ISO 19111
 *     ├─Identifier
 *     │   ├─Code…………………………… 19111
 *     │   └─Code space…………… ISO
 *     └─Presentation form…… Document digital
 * }
 */
@Test
@DependsOnMethod("testConstructor")
public void testGet() {
    final DefaultCitation instance = HardCodedCitations.ISO_19111;
    final PropertyAccessor accessor = createPropertyAccessor();
    // Singleton value (not a collection)
    final Object title = accessor.get(accessor.indexOf("title", true), instance);
    assertInstanceOf("title", InternationalString.class, title);
    assertEquals("title", "Spatial referencing by coordinates", title.toString());
    // Collection of InternationalStrings
    final Object alternateTitles = accessor.get(accessor.indexOf("alternateTitles", true), instance);
    assertInstanceOf("alternateTitles", Collection.class, alternateTitles);
    assertEquals("alternateTitles", "ISO 19111", getSingleton((Collection<?>) alternateTitles).toString());
    // Collection of Identifiers
    final Object identifiers = accessor.get(accessor.indexOf("identifiers", true), instance);
    assertEquals("19111", getSingletonCode(identifiers));
}
Also used : DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) IdentifiedObject(org.opengis.referencing.IdentifiedObject) 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