Search in sources :

Example 1 with SimpleCitation

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

the class BuilderTest method testSetCodeSpace.

/**
 * Tests {@link Builder#setCodeSpace(Citation, String)}.
 */
@Test
public void testSetCodeSpace() {
    final BuilderMock builder = new BuilderMock();
    builder.setCodeSpace(Citations.EPSG, "EPSG");
    builder.addName("Mercator (variant A)");
    /*
         * Setting the same codespace should have no effect, while attempt to
         * set a new codespace after we added a name shall not be allowed.
         */
    final SimpleCitation IOGP = new SimpleCitation("IOGP");
    builder.setCodeSpace(Citations.EPSG, "EPSG");
    try {
        builder.setCodeSpace(IOGP, "EPSG");
        fail("Setting a different codespace shall not be allowed.");
    } catch (IllegalStateException e) {
        final String message = e.getMessage();
        assertTrue(message, message.contains(Identifier.AUTHORITY_KEY));
    }
    /*
         * The failed attempt to set a new codespace shall not have modified builder state.
         */
    assertEquals("EPSG", builder.properties.get(ReferenceIdentifier.CODESPACE_KEY));
    assertSame(Citations.EPSG, builder.properties.get(Identifier.AUTHORITY_KEY));
    /*
         * After a cleanup (normally after a createXXX(…) method call), user shall be allowed to
         * set a new codespace again. Note that the cleanup operation shall not clear the codespace.
         */
    builder.onCreate(true);
    assertEquals("EPSG", builder.properties.get(ReferenceIdentifier.CODESPACE_KEY));
    assertSame(Citations.EPSG, builder.properties.get(Identifier.AUTHORITY_KEY));
    builder.setCodeSpace(IOGP, "EPSG");
    assertEquals("EPSG", builder.properties.get(ReferenceIdentifier.CODESPACE_KEY));
    assertSame(IOGP, builder.properties.get(Identifier.AUTHORITY_KEY));
}
Also used : SimpleCitation(org.apache.sis.internal.simple.SimpleCitation) Test(org.junit.Test)

Example 2 with SimpleCitation

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

the class CodeTest method testSimple.

/**
 * Tests the {@link Code#Code(ReferenceIdentifier)} constructor with {@code "EPSG:4326"} identifier.
 * This test intentionally uses an identifier with the {@code IOGP} authority instead than
 * EPSG in order to make sure that the {@code codeSpace} attribute is set from
 * {@code Identifier.getCodeSpace()}, not from {@code Identifier.getAuthority()}.
 */
@Test
public void testSimple() {
    final SimpleCitation IOGP = new SimpleCitation("IOGP");
    // See above javadoc.
    final ReferenceIdentifier id = new ImmutableIdentifier(IOGP, "EPSG", "4326");
    final Code value = new Code(id);
    assertEquals("codeSpace", "EPSG", value.codeSpace);
    assertEquals("code", "4326", value.code);
    /*
         * Reverse operation. Note that the authority is lost since there is no room for that in a
         * <gml:identifier> element. Current implementation sets the authority to the code space.
         */
    final ReferenceIdentifier actual = value.getIdentifier();
    assertSame("authority", Citations.EPSG, actual.getAuthority());
    assertEquals("codeSpace", "EPSG", actual.getCodeSpace());
    assertNull("version", actual.getVersion());
    assertEquals("code", "4326", actual.getCode());
}
Also used : ReferenceIdentifier(org.opengis.referencing.ReferenceIdentifier) SimpleCitation(org.apache.sis.internal.simple.SimpleCitation) ImmutableIdentifier(org.apache.sis.metadata.iso.ImmutableIdentifier) Test(org.junit.Test)

Example 3 with SimpleCitation

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

the class CodeTest method testWithVersion.

/**
 * Tests the {@link Code#Code(ReferenceIdentifier)} constructor with {@code "EPSG:8.3:4326"} identifier.
 * This test intentionally uses an identifier with the {@code IOGP} authority instead than EPSG
 * for the same reason than {@link #testSimple()}.
 */
@Test
@DependsOnMethod("testSimple")
public void testWithVersion() {
    final SimpleCitation IOGP = new SimpleCitation("IOGP");
    // See above javadoc.
    final ReferenceIdentifier id = new ImmutableIdentifier(IOGP, "EPSG", "4326", "8.2", null);
    final Code value = new Code(id);
    assertEquals("codeSpace", "EPSG:8.2", value.codeSpace);
    assertEquals("code", "4326", value.code);
    /*
         * Reverse operation. Note that the authority is lost since there is no room for that in a
         * <gml:identifier> element. Current implementation sets the authority to the code space.
         */
    final ReferenceIdentifier actual = value.getIdentifier();
    assertSame("authority", Citations.EPSG, actual.getAuthority());
    assertEquals("codeSpace", "EPSG", actual.getCodeSpace());
    assertEquals("version", "8.2", actual.getVersion());
    assertEquals("code", "4326", actual.getCode());
}
Also used : ReferenceIdentifier(org.opengis.referencing.ReferenceIdentifier) SimpleCitation(org.apache.sis.internal.simple.SimpleCitation) ImmutableIdentifier(org.apache.sis.metadata.iso.ImmutableIdentifier) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 4 with SimpleCitation

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

the class CitationsTest method testGetCodeSpace.

/**
 * Tests {@link Citations#getCodeSpace(Citation)} with some ignorable characters.
 * Ignorable character used in this test are:
 *
 * <ul>
 *   <li>200B: zero width space</li>
 *   <li>2060: word joiner</li>
 * </ul>
 */
@Test
@DependsOnMethod("testGetIdentifier")
public void testGetCodeSpace() {
    final SimpleCitation citation = new SimpleCitation(" Valid\u2060Id\u200Bentifier ");
    assertEquals("ValidIdentifier", Citations.getCodeSpace(citation));
    assertNull("Shall not be taken as a valid identifier.", Citations.getCodeSpace(new SimpleCitation("Proj.4")));
    assertEquals("Shall fallback on the the identifier space name.", "TheProj4Space", Citations.getCodeSpace(new Proj4()));
}
Also used : SimpleCitation(org.apache.sis.internal.simple.SimpleCitation) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Aggregations

SimpleCitation (org.apache.sis.internal.simple.SimpleCitation)4 Test (org.junit.Test)4 ImmutableIdentifier (org.apache.sis.metadata.iso.ImmutableIdentifier)2 DependsOnMethod (org.apache.sis.test.DependsOnMethod)2 ReferenceIdentifier (org.opengis.referencing.ReferenceIdentifier)2