Author: desruisseaux
Date: Wed Mar 5 20:41:37 2014
New Revision: 1574654
URL: http://svn.apache.org/r1574654
Log:
Added more tests.
Added:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderMock.java
(with props)
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderTest.java
(with props)
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterBuilder.java
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterBuilderTest.java
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParametersTest.java
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterBuilder.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterBuilder.java?rev=1574654&r1=1574653&r2=1574654&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterBuilder.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/parameter/ParameterBuilder.java
[UTF-8] Wed Mar 5 20:41:37 2014
@@ -139,6 +139,18 @@ public class ParameterBuilder extends Bu
}
/**
+ * Creates a descriptor for values of the given type without domain
restriction.
+ *
+ * @param <T> The compile-time type of the {@code valueClass}
argument.
+ * @param valueClass The class that describe the type of the parameter
values.
+ * @param defaultValue The default value for the parameter, or {@code
null} if none.
+ * @return The parameter descriptor for the given default value and unit.
+ */
+ public <T> ParameterDescriptor<T> create(final Class<T> valueClass, final
T defaultValue) {
+ return create(valueClass, null, null, defaultValue);
+ }
+
+ /**
* Creates a descriptor for floating point values greater than zero.
* The zero value is not considered valid. There is no maximal value.
*
@@ -243,11 +255,11 @@ public class ParameterBuilder extends Bu
* a {@linkplain org.opengis.util.CodeList code list} or enumeration
subset.
* It is not necessary to provide this property when all values from the
code list or enumeration are valid.</p>
*
- * @param <T> The compile-time type of the {@code valueClass}
argument.
- * @param valueClass The class that describe the type of the parameter
values.
- * @param validValues A finite set of valid values (usually from a
{@linkplain CodeList code list})
- * or {@code null} if it doesn't apply.
- * @param defaultValue The default value for the parameter, or {@code
null} if none.
+ * @param <T> The compile-time type of the {@code valueClass}
argument.
+ * @param valueClass The class that describe the type of the parameter
values.
+ * @param validValues A finite set of valid values (usually from a
{@linkplain CodeList code list})
+ * or {@code null} if it doesn't apply.
+ * @param defaultValue The default value for the parameter, or {@code
null} if none.
* @return The parameter descriptor for the given set of valid values.
*/
public <T> ParameterDescriptor<T> createEnumerated(final Class<T>
valueClass, final T[] validValues, final T defaultValue) {
Modified:
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java?rev=1574654&r1=1574653&r2=1574654&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/main/java/org/apache/sis/referencing/Builder.java
[UTF-8] Wed Mar 5 20:41:37 2014
@@ -40,8 +40,8 @@ import java.util.Objects;
/**
- * Base class of builders for various kind of {@code IdentifiedObject}. {@code
Builder}s aim to make object
- * creation easier — they do not add any new functionality to {@link
org.opengis.referencing.ObjectFactory}.
+ * Base class of builders for various kind of {@link IdentifiedObject}. {@code
Builder}s aim to make object creation
+ * easier — they do not add any new functionality compared to {@link
org.opengis.referencing.ObjectFactory}.
* Builder methods like {@link #name(CharSequence)} and {@link
#identifier(String)} provide convenient ways
* to fill the {@link #properties} map, which will be given to the {@code
ObjectFactory} methods at
* {@code IdentifiedObject} creation time. Creations happen when any {@code
createXXX(…)} method defined in
@@ -50,7 +50,7 @@ import java.util.Objects;
* <p>This base class provides method for defining the following {@link
IdentifiedObject} properties:</p>
* <ul>
* <li><p><b>{@link AbstractIdentifiedObject#getName() Name}:</b><br>
- * Each {@code IdentifiedObject} must have a name, which can be specified
by a call to any of the
+ * Each {@code IdentifiedObject} shall have a name, which can be specified
by a call to any of the
* {@code name(…)} methods defined in this class.</p></li>
*
* <li><p><b>{@link AbstractIdentifiedObject#getAlias() Aliases}:</b><br>
@@ -69,7 +69,7 @@ import java.util.Objects;
* {@section Builder property lifetimes}
* The same builder can be used for creating many objects, since constructing
a Coordinate Reference System (CRS)
* may require constructing many components (coordinate system, datum,
ellipsoid, prime meridian, <i>etc.</i>),
- * some of them sharing common properties. In order to simplify the most
common usage scenarios, identification
+ * some of them sharing common properties. In order to simplify the most
common usages, identification
* properties have two different lifetimes in the {@code Builder} class:
*
* <ul>
@@ -80,8 +80,11 @@ import java.util.Objects;
* method, because they are usually specific to a particular {@code
IdentifiedObject} instance.</li>
* </ul>
*
+ * {@section Usage examples}
+ * See {@link org.apache.sis.parameter.ParameterBuilder} class javadoc for an
example with the
+ * <cite>Mercator</cite> projection.
*
- * <div class="note"><b>Note for subclass implementors:</b>
+ * {@section Note for subclass implementors}
* <ul>
* <li>The type {@code <B>} shall be exactly the subclass type.
* For performance reasons, this is verified only if Java assertions are
enabled.</li>
@@ -89,7 +92,7 @@ import java.util.Objects;
* usage of {@link #properties} map by the factory.</li>
* </ul>
*
- * <b>Example:</b>
+ * <div class="note"><b>Example:</b>
* {@preformat java
* public class MyBuilder extends Builder<MyBuilder> {
* public Foo createFoo() {
@@ -118,7 +121,7 @@ public abstract class Builder<B extends
* {@value org.opengis.referencing.IdentifiedObject#IDENTIFIERS_KEY} and
* {@value org.opengis.referencing.IdentifiedObject#REMARKS_KEY} keys.
* Subclasses may add other entries like
- * {@value org.opengis.referencing.ReferenceSystem#DOMAIN_OF_VALIDITY_KEY},
+ * {@value org.opengis.referencing.ReferenceSystem#DOMAIN_OF_VALIDITY_KEY}
and
* {@value org.opengis.referencing.ReferenceSystem#SCOPE_KEY} keys.
*
* <p>See <cite>Notes for subclass implementors</cite> in class javadoc
for usage conditions.</p>
@@ -148,7 +151,7 @@ public abstract class Builder<B extends
* Creates a new builder.
*/
protected Builder() {
- assert isSelf(getClass());
+ assert verifyParameterizedType(getClass());
properties = new HashMap<>(8);
aliases = new ArrayList<>(4);
identifiers = new ArrayList<>(4);
@@ -158,7 +161,7 @@ public abstract class Builder<B extends
* Verifies that {@code B} in {@code <B extends Builder<B>} is the
expected class.
* This method is for assertion purposes only.
*/
- private static boolean isSelf(final Class<?> expected) {
+ private static boolean verifyParameterizedType(final Class<?> expected) {
for (Class<?> c = expected; c != null; c = c.getSuperclass()) {
Type type = c.getGenericSuperclass();
if (type instanceof ParameterizedType) {
Modified:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterBuilderTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterBuilderTest.java?rev=1574654&r1=1574653&r2=1574654&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterBuilderTest.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterBuilderTest.java
[UTF-8] Wed Mar 5 20:41:37 2014
@@ -37,7 +37,11 @@ import static org.junit.Assert.*;
* @version 0.4
* @module
*/
-@DependsOn({DefaultParameterDescriptorTest.class,
DefaultParameterValueTest.class})
+@DependsOn({
+ org.apache.sis.referencing.BuilderTest.class,
+ DefaultParameterDescriptorTest.class,
+ DefaultParameterValueTest.class
+})
public final strictfp class ParameterBuilderTest extends TestCase {
/**
* Tests the "<cite>Mercator (variant A)</cite>" example given in Javadoc.
Modified:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParametersTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParametersTest.java?rev=1574654&r1=1574653&r2=1574654&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParametersTest.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParametersTest.java
[UTF-8] Wed Mar 5 20:41:37 2014
@@ -78,7 +78,7 @@ public final class ParametersTest extend
}
/**
- * Tests {@link Parameters#getValueDomain(ParameterDescriptor)
+ * Tests {@link Parameters#getValueDomain(ParameterDescriptor)}.
*/
@Test
public void testValueDomain() {
Added:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderMock.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderMock.java?rev=1574654&view=auto
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderMock.java
(added)
+++
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderMock.java
[UTF-8] Wed Mar 5 20:41:37 2014
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.referencing;
+
+
+/**
+ * A {@link Builder} that doesn't build anything. Such builder is useless and
is defined here
+ * only for testing the content of {@link Builder#properties} map.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.4
+ * @version 0.4
+ * @module
+ */
+final strictfp class BuilderMock extends Builder<BuilderMock> {
+}
Propchange:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderMock.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderMock.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Added:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderTest.java?rev=1574654&view=auto
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderTest.java
(added)
+++
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderTest.java
[UTF-8] Wed Mar 5 20:41:37 2014
@@ -0,0 +1,181 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.referencing;
+
+import org.opengis.util.NameSpace;
+import org.opengis.util.LocalName;
+import org.opengis.util.GenericName;
+import org.opengis.metadata.citation.Citation;
+import org.opengis.referencing.ReferenceIdentifier;
+import org.apache.sis.metadata.iso.ImmutableIdentifier;
+import org.apache.sis.test.DependsOnMethod;
+import org.apache.sis.test.TestCase;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+import static org.opengis.referencing.IdentifiedObject.*;
+import static org.apache.sis.metadata.iso.citation.HardCodedCitations.*;
+import static org.apache.sis.internal.system.DefaultFactories.SIS_NAMES;
+
+
+/**
+ * Tests {@link Builder}.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.4
+ * @version 0.4
+ * @module
+ */
+public final strictfp class BuilderTest extends TestCase {
+ /**
+ * Tests {@link Builder#verifyParameterizedType(Class)}.
+ */
+ @Test
+ public void testVerifyParameterizedType() {
+ final class Invalid extends Builder<BuilderMock> {
+ }
+ try {
+ new Invalid();
+ } catch (AssertionError e) {
+ final String message = e.getMessage();
+ assertTrue(message, message.contains(BuilderMock.class.getName()));
+ }
+ }
+
+ /**
+ * Tests {@link Builder#codespace(Citation, String)}.
+ */
+ @Test
+ public void testCodespace() {
+ final BuilderMock builder = new BuilderMock();
+ builder.codespace(OGP, "EPSG");
+ builder.name("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.
+ */
+ builder.codespace(OGP, "EPSG");
+ try {
+ builder.codespace(EPSG, "EPSG");
+ fail("Setting a different codespace shall not be allowed.");
+ } catch (IllegalStateException e) {
+ final String message = e.getMessage();
+ assertTrue(message,
message.contains(ReferenceIdentifier.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 ( OGP,
builder.properties.get(ReferenceIdentifier.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 ( OGP,
builder.properties.get(ReferenceIdentifier.AUTHORITY_KEY));
+ builder.codespace(EPSG, "EPSG");
+ assertEquals("EPSG",
builder.properties.get(ReferenceIdentifier.CODESPACE_KEY));
+ assertSame ( EPSG,
builder.properties.get(ReferenceIdentifier.AUTHORITY_KEY));
+ }
+
+ /**
+ * Tests {@link Builder#name(CharSequence)} without codespace.
+ */
+ @Test
+ public void testUnscopedName() {
+ // Expected values to be used later in the test.
+ final String name = "Mercator (variant A)";
+ final LocalName alias1 = SIS_NAMES.createLocalName(null, "Mercator
(1SP)");
+ final LocalName alias2 = SIS_NAMES.createLocalName(null,
"Mercator_1SP");
+ final LocalName alias3 = SIS_NAMES.createLocalName(null,
"CT_Mercator");
+ assertEquals("Mercator (variant A)", name .toString());
+ assertEquals("Mercator (1SP)", alias1.toString());
+ assertEquals("Mercator_1SP", alias2.toString());
+ assertEquals("CT_Mercator", alias3.toString());
+
+ // The test.
+ final BuilderMock builder = new BuilderMock();
+ builder.name("Mercator (variant A)"); // EPSG version 7.6 and later.
+ builder.name("Mercator (1SP)"); // EPSG before version 7.6.
+ builder.name("Mercator_1SP"); // OGC
+ builder.name("CT_Mercator"); // GeoTIFF
+ builder.onCreate(false);
+ assertEquals(name, builder.properties.get(NAME_KEY));
+ assertArrayEquals(new GenericName[] {alias1, alias2, alias3},
+ (GenericName[]) builder.properties.get(ALIAS_KEY));
+ }
+
+ /**
+ * Tests {@link Builder#name(Citation, CharSequence)} and {@link
Builder#name(CharSequence)} with codespace.
+ */
+ @Test
+ @DependsOnMethod({"testUnscopedName", "testCodespace"})
+ public void testScopedName() {
+ // Expected values to be used later in the test.
+ final String name = "Mercator (variant A)";
+ final GenericName alias1 = SIS_NAMES.createLocalName(scope("EPSG"),
"Mercator (1SP)");
+ final GenericName alias2 = new NamedIdentifier(OGC,
"Mercator_1SP");
+ final GenericName alias3 = new NamedIdentifier(GEOTIFF, "CT_Mercator");
+ assertEquals("Mercator (variant A)", name .toString());
+ assertEquals("Mercator (1SP)", alias1.toString());
+ assertEquals("OGC:Mercator_1SP", alias2.toString());
+ assertEquals("GeoTIFF:CT_Mercator", alias3.toString());
+ assertEquals("EPSG", alias1.scope().name().toString());
+
+ // The test.
+ final BuilderMock builder = new BuilderMock();
+ builder.codespace(OGP, "EPSG");
+ builder.name( "Mercator (variant A)");
+ builder.name( "Mercator (1SP)");
+ builder.name(OGC, "Mercator_1SP");
+ builder.name(GEOTIFF, "CT_Mercator");
+ builder.onCreate(false);
+ assertEquals(name, builder.properties.get(NAME_KEY));
+ assertArrayEquals(new GenericName[] {alias1, alias2, alias3},
+ (GenericName[]) builder.properties.get(ALIAS_KEY));
+ }
+
+ /**
+ * Convenience method creating a namespace for {@link #testScopedName()}
purpose.
+ */
+ private static NameSpace scope(final String codespace) {
+ return SIS_NAMES.createNameSpace(SIS_NAMES.createLocalName(null,
codespace), null);
+ }
+
+ /**
+ * Tests {@link Builder#identifier(Citation, String)} and {@link
Builder#identifier(String)}
+ * with codespace.
+ */
+ @Test
+ public void testIdentifiers() {
+ // Expected values to be used later in the test.
+ final ReferenceIdentifier id1 = new ImmutableIdentifier(OGP,
"EPSG", "9804");
+ final ReferenceIdentifier id2 = new ImmutableIdentifier(GEOTIFF,
"GeoTIFF", "7");
+ assertEquals("EPSG:9804", IdentifiedObjects.toString(id1));
+ assertEquals("GeoTIFF:7", IdentifiedObjects.toString(id2));
+
+ // The test.
+ final BuilderMock builder = new BuilderMock();
+ builder.codespace (OGP, "EPSG");
+ builder.identifier( "9804");
+ builder.identifier(GEOTIFF, "7");
+ builder.onCreate(false);
+ assertArrayEquals(new ReferenceIdentifier[] {id1, id2},
+ (ReferenceIdentifier[])
builder.properties.get(IDENTIFIERS_KEY));
+ }
+}
Propchange:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/referencing/BuilderTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified:
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1574654&r1=1574653&r2=1574654&view=diff
==============================================================================
---
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] (original)
+++
sis/branches/JDK7/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] Wed Mar 5 20:41:37 2014
@@ -50,6 +50,7 @@ import org.junit.BeforeClass;
org.apache.sis.referencing.NamedIdentifierTest.class,
org.apache.sis.referencing.AbstractIdentifiedObjectTest.class,
org.apache.sis.referencing.AbstractReferenceSystemTest.class,
+ org.apache.sis.referencing.BuilderTest.class,
org.apache.sis.parameter.DefaultParameterDescriptorTest.class,
org.apache.sis.parameter.DefaultParameterValueTest.class,
org.apache.sis.parameter.ParametersTest.class,