Search in sources :

Example 21 with SimpleInternationalString

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

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

the class TreeNodeChildrenTest method metadataWithMultiOccurrences.

/**
 * Creates a shallow metadata object with multi-occurrences (i.e. more than one value in collections).
 * This method creates the following metadata:
 *
 * {@preformat text
 *   DefaultCitation
 *     ├─Title………………………………………………………… Some title
 *     ├─Alternate title (1 of 2)……… First alternate title
 *     ├─Alternate title (2 of 2)……… Second alternate title
 *     ├─Edition…………………………………………………… Some edition
 *     ├─Presentation form (1 of 2)… Map digital
 *     ├─Presentation form (2 of 2)… map hardcopy
 *     └─Other citation details…………… Some other details
 * }
 */
static DefaultCitation metadataWithMultiOccurrences() {
    final DefaultCitation citation = metadataWithSingletonInCollections();
    assertTrue(citation.getAlternateTitles().add(new SimpleInternationalString("Second alternate title")));
    assertTrue(citation.getPresentationForms().add(PresentationForm.MAP_HARDCOPY));
    return citation;
}
Also used : DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString)

Example 23 with SimpleInternationalString

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

the class TreeNodeChildrenTest method metadataWithSingletonInCollections.

/**
 * Creates a shallow metadata object with singleton value in collections.
 * This method creates the following metadata:
 *
 * {@preformat text
 *   DefaultCitation
 *     ├─Title………………………………………………… Some title
 *     ├─Alternate title……………………… First alternate title
 *     ├─Edition…………………………………………… Some edition
 *     ├─Presentation form………………… Map digital
 *     └─Other citation details…… Some other details
 * }
 */
static DefaultCitation metadataWithSingletonInCollections() {
    final DefaultCitation citation = metadataWithoutCollections();
    assertTrue(citation.getAlternateTitles().add(new SimpleInternationalString("First alternate title")));
    assertTrue(citation.getPresentationForms().add(PresentationForm.MAP_DIGITAL));
    return citation;
}
Also used : DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString)

Example 24 with SimpleInternationalString

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

the class DefaultExtentTest method testIntersect.

/**
 * Tests {@link DefaultExtent#intersect(Extent)}.
 */
@Test
public void testIntersect() {
    final DefaultGeographicBoundingBox bounds1 = new DefaultGeographicBoundingBox(10, 20, 30, 40);
    final DefaultGeographicBoundingBox bounds2 = new DefaultGeographicBoundingBox(16, 18, 31, 42);
    final DefaultGeographicBoundingBox clip = new DefaultGeographicBoundingBox(15, 25, 26, 32);
    final DefaultGeographicBoundingBox expected1 = new DefaultGeographicBoundingBox(15, 20, 30, 32);
    final DefaultGeographicBoundingBox expected2 = new DefaultGeographicBoundingBox(16, 18, 31, 32);
    final DefaultExtent e1 = new DefaultExtent("Somewhere", bounds1, null, null);
    final DefaultExtent e2 = new DefaultExtent("Somewhere", clip, null, null);
    e1.getGeographicElements().add(bounds2);
    e1.intersect(e2);
    assertEquals("description", "Somewhere", e1.getDescription().toString());
    assertFalse("isNil(description)", e1.getDescription() instanceof NilObject);
    assertArrayEquals("geographicElements", new DefaultGeographicBoundingBox[] { expected1, expected2 }, e1.getGeographicElements().toArray());
    /*
         * Change the description and test again. That description should be considered missing
         * because we have a mismatch. Also change abounding box in such a way that there is no
         * intersection. That bounding box should be omitted.
         */
    bounds2.setBounds(8, 12, 33, 35);
    e1.setGeographicElements(Arrays.asList(bounds1, bounds2));
    e2.setDescription(new SimpleInternationalString("Somewhere else"));
    e1.intersect(e2);
    assertTrue("isNil(description)", e1.getDescription() instanceof NilObject);
    assertArrayEquals("geographicElements", new DefaultGeographicBoundingBox[] { expected1 }, e1.getGeographicElements().toArray());
}
Also used : SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) NilObject(org.apache.sis.xml.NilObject) Test(org.junit.Test)

Example 25 with SimpleInternationalString

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

the class MetadataSourceTest method testSearch.

/**
 * Tests {@link MetadataSource#search(Object)}
 *
 * @param  source  the instance to test.
 * @throws MetadataStoreException if an error occurred while querying the database.
 */
@TestStep
public static void testSearch(final MetadataSource source) throws MetadataStoreException {
    final DefaultCitation specification = new DefaultCitation("PNG (Portable Network Graphics) Specification");
    specification.setAlternateTitles(Collections.singleton(new SimpleInternationalString("PNG")));
    final DefaultFormat format = new DefaultFormat();
    format.setFormatSpecificationCitation(specification);
    assertEquals("PNG", source.search(format));
    specification.setTitle(null);
    assertNull(source.search(format));
}
Also used : DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) DefaultFormat(org.apache.sis.metadata.iso.distribution.DefaultFormat) TestStep(org.apache.sis.test.TestStep)

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