Search in sources :

Example 6 with SimpleInternationalString

use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.

the class MetadataStandardTest method testEqualsOnCyclicMetadata.

/**
 * Tests the {@link MetadataStandard#equals(Object, Object, ComparisonMode)} method on an object
 * having cyclic associations. In absence of safety guard against infinite recursivity, this test
 * would produce {@link StackOverflowError}.
 */
@Test
@DependsOnMethod("testEquals")
public void testEqualsOnCyclicMetadata() {
    final DefaultAcquisitionInformation p1 = createCyclicMetadata();
    final DefaultAcquisitionInformation p2 = createCyclicMetadata();
    assertTrue("equals", p1.equals(p2));
    final DefaultPlatform platform = (DefaultPlatform) getSingleton(p2.getPlatforms());
    final DefaultInstrument instrument = (DefaultInstrument) getSingleton(platform.getInstruments());
    instrument.setType(new SimpleInternationalString("An other instrument type."));
    assertFalse("equals", p1.equals(p2));
}
Also used : DefaultAcquisitionInformation(org.apache.sis.metadata.iso.acquisition.DefaultAcquisitionInformation) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) DefaultPlatform(org.apache.sis.metadata.iso.acquisition.DefaultPlatform) DefaultInstrument(org.apache.sis.metadata.iso.acquisition.DefaultInstrument) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 7 with SimpleInternationalString

use of org.apache.sis.util.iso.SimpleInternationalString 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 8 with SimpleInternationalString

use of org.apache.sis.util.iso.SimpleInternationalString 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 9 with SimpleInternationalString

use of org.apache.sis.util.iso.SimpleInternationalString 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 10 with SimpleInternationalString

use of org.apache.sis.util.iso.SimpleInternationalString 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)

Aggregations

SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)45 Test (org.junit.Test)20 DefaultCitation (org.apache.sis.metadata.iso.citation.DefaultCitation)19 InternationalString (org.opengis.util.InternationalString)14 URI (java.net.URI)4 DependsOnMethod (org.apache.sis.test.DependsOnMethod)4 NamedIdentifier (org.apache.sis.referencing.NamedIdentifier)3 Citation (org.opengis.metadata.citation.Citation)3 IdentifiedObject (org.opengis.referencing.IdentifiedObject)3 Collection (java.util.Collection)2 DefaultIdentifier (org.apache.sis.metadata.iso.DefaultIdentifier)2 DefaultMetadata (org.apache.sis.metadata.iso.DefaultMetadata)2 DefaultAcquisitionInformation (org.apache.sis.metadata.iso.acquisition.DefaultAcquisitionInformation)2 DefaultInstrument (org.apache.sis.metadata.iso.acquisition.DefaultInstrument)2 DefaultPlatform (org.apache.sis.metadata.iso.acquisition.DefaultPlatform)2 DefaultFormat (org.apache.sis.metadata.iso.distribution.DefaultFormat)2 DefaultDataQuality (org.apache.sis.metadata.iso.quality.DefaultDataQuality)2 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 URISyntaxException (java.net.URISyntaxException)1