Author: desruisseaux
Date: Wed Sep 2 08:59:24 2015
New Revision: 1700737
URL: http://svn.apache.org/r1700737
Log:
Complete CC_OperationParameterGroup test with a case for merge operation.
Modified:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroupTest.java
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterFormatTest.java
sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/parameter/ParameterDescriptorGroup.xml
sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/parameter/ParameterValueGroup.xml
Modified:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroupTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroupTest.java?rev=1700737&r1=1700736&r2=1700737&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroupTest.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/internal/jaxb/referencing/CC_OperationParameterGroupTest.java
[UTF-8] Wed Sep 2 08:59:24 2015
@@ -19,15 +19,19 @@ package org.apache.sis.internal.jaxb.ref
import java.util.List;
import java.util.Map;
import java.util.IdentityHashMap;
+import java.util.Collections;
import javax.xml.bind.JAXBException;
import javax.measure.unit.NonSI;
import org.opengis.parameter.ParameterDescriptor;
import org.opengis.parameter.ParameterDescriptorGroup;
import org.opengis.parameter.GeneralParameterDescriptor;
+import org.apache.sis.parameter.DefaultParameterDescriptor;
import org.apache.sis.parameter.DefaultParameterDescriptorGroup;
import org.apache.sis.parameter.ParameterBuilder;
+import org.apache.sis.internal.util.UnmodifiableArrayList;
import org.apache.sis.test.XMLTestCase;
import org.apache.sis.test.DependsOn;
+import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.xml.Namespaces;
import org.junit.Test;
@@ -52,37 +56,38 @@ public final strictfp class CC_Operation
*/
private DefaultParameterDescriptorGroup unmarshal() throws JAXBException {
return unmarshal(DefaultParameterDescriptorGroup.class,
- "<gml:OperationParameterGroup xmlns:gml=\"" + Namespaces.GML +
"\">\n"
- + " <gml:name>Mercator (1SP)</gml:name>\n"
- + " <gml:parameter>\n"
- + " <gml:OperationParameter gml:id=\"epsg-parameter-8801\">\n"
- + " <gml:identifier
codeSpace=\"IOGP\">urn:ogc:def:parameter:EPSG::8801</gml:identifier>\n"
- + " <gml:name codeSpace=\"EPSG\">Latitude of natural
origin</gml:name>\n"
- + " </gml:OperationParameter>\n"
- + " </gml:parameter>\n"
- + " <gml:parameter>\n"
- + " <gml:OperationParameter gml:id=\"epsg-parameter-8802\">\n"
- + " <gml:identifier
codeSpace=\"IOGP\">urn:ogc:def:parameter:EPSG::8802</gml:identifier>\n"
- + " <gml:name codeSpace=\"EPSG\">Longitude of natural
origin</gml:name>\n"
- + " </gml:OperationParameter>\n"
- + " </gml:parameter>\n"
- // There is more parameters in a Mercator projection, but 2 is
enough for this test.
- + "</gml:OperationParameterGroup>");
+ "<gml:OperationParameterGroup xmlns:gml=\"" + Namespaces.GML +
"\">\n" +
+ " <gml:name>Mercator (1SP)</gml:name>\n" +
+ " <gml:parameter>\n" +
+ " <gml:OperationParameter
gml:id=\"epsg-parameter-8801\">\n" +
+ " <gml:identifier
codeSpace=\"IOGP\">urn:ogc:def:parameter:EPSG::8801</gml:identifier>\n" +
+ " <gml:name codeSpace=\"EPSG\">Latitude of natural
origin</gml:name>\n" +
+ " <gml:remarks>Always zero for this
projection.</gml:remarks>\n" +
+ " </gml:OperationParameter>\n" +
+ " </gml:parameter>\n" +
+ " <gml:parameter>\n" +
+ " <gml:OperationParameter
gml:id=\"epsg-parameter-8802\">\n" +
+ " <gml:identifier
codeSpace=\"IOGP\">urn:ogc:def:parameter:EPSG::8802</gml:identifier>\n" +
+ " <gml:name codeSpace=\"EPSG\">Longitude of natural
origin</gml:name>\n" +
+ " </gml:OperationParameter>\n" +
+ " </gml:parameter>\n" +
+ // There is more parameters in a Mercator projection, but 2 is
enough for this test.
+ "</gml:OperationParameterGroup>");
}
/**
- * Creates a parameter descriptor equivalent to the result of {@link
#unmarshal()}
- * but with arbitrary default values.
+ * Creates the parameter descriptors equivalent to the result of {@link
#unmarshal()}
+ * but with value class, units and default values.
+ *
+ * @param remarks Remarks to associate to the latitude parameter, or
{@code null} if none.
*/
- private static ParameterDescriptorGroup create() {
+ private static ParameterDescriptor<?>[] create(final String remarks) {
final ParameterBuilder builder = new ParameterBuilder();
builder.setCodeSpace(EPSG, "EPSG").setRequired(true);
- ParameterDescriptor<?>[] parameters = {
- builder.addIdentifier("8801").addName("Latitude of natural
origin") .create( 40, NonSI.DEGREE_ANGLE),
- builder.addIdentifier("8802").addName("Longitude of natural
origin").create(-60, NonSI.DEGREE_ANGLE),
+ return new ParameterDescriptor<?>[] {
+ builder.addIdentifier("8801").addName("Latitude of natural
origin") .setRemarks(remarks).create(0, NonSI.DEGREE_ANGLE),
+ builder.addIdentifier("8802").addName("Longitude of natural
origin").create(0, NonSI.DEGREE_ANGLE),
};
- builder.addName("Mercator (1SP)");
- return builder.createGroup(parameters);
}
/**
@@ -93,14 +98,15 @@ public final strictfp class CC_Operation
*/
@Test
public void testSubtitution() throws JAXBException {
- final ParameterDescriptorGroup provided = unmarshal();
- final ParameterDescriptorGroup complete = create();
+ final ParameterDescriptorGroup fromXML = unmarshal();
+ final ParameterDescriptor<?>[] expected = create("Always zero for this
projection.");
+ final UnmodifiableArrayList<GeneralParameterDescriptor> fromValues =
UnmodifiableArrayList.wrap(expected);
// Normal usage: merge to existing descriptors the more complete
information found in parameter values.
- verifySubtitution(provided.descriptors(), complete.descriptors(),
complete.descriptors());
+ verifySubtitution(fromXML.descriptors(), fromValues, expected);
// Unusual case, tested for safety: the existing descriptors were
actually more complete.
- verifySubtitution(complete.descriptors(), provided.descriptors(),
complete.descriptors());
+ verifySubtitution(fromValues, fromXML.descriptors(), expected);
}
/**
@@ -110,10 +116,9 @@ public final strictfp class CC_Operation
* @param fromValues Simulates the descriptors created from {@code
ParameterValue} instances.
* @param expected The expected descriptors.
*/
- private static void verifySubtitution(
- final List<GeneralParameterDescriptor> descriptors,
- final List<GeneralParameterDescriptor> fromValues,
- final List<GeneralParameterDescriptor> expected)
+ private static void verifySubtitution(final
List<GeneralParameterDescriptor> descriptors,
+ final
List<GeneralParameterDescriptor> fromValues,
+ final GeneralParameterDescriptor[]
expected)
{
final Map<GeneralParameterDescriptor,GeneralParameterDescriptor>
replacements = new IdentityHashMap<>(4);
final GeneralParameterDescriptor[] merged =
CC_OperationParameterGroup.merge(descriptors,
@@ -121,8 +126,48 @@ public final strictfp class CC_Operation
assertTrue("Expected no replacement.", replacements.isEmpty());
assertEquals("Number of parameters", 2, merged.length);
+ assertNotSame(expected, merged);
+ assertArrayEquals(expected, merged);
for (int i=0; i<merged.length; i++) {
- assertSame(expected.get(i), merged[i]);
+ assertSame(expected[i], merged[i]); // Not just equals, but
actually same instance.
}
}
+
+ /**
+ * Tests the merge of unmarshalled descriptors with more complete
descriptors.
+ * This operation is expected to create new descriptor instances as a
result of the merges.
+ *
+ * @throws JAXBException if this method failed to create test data.
+ */
+ @Test
+ @DependsOnMethod("testSubtitution")
+ public void testMerge() throws JAXBException {
+ final ParameterDescriptorGroup fromXML = unmarshal();
+ final ParameterDescriptor<?>[] fromValues = create(null);
+ final Map<GeneralParameterDescriptor,GeneralParameterDescriptor>
replacements = new IdentityHashMap<>(4);
+ final GeneralParameterDescriptor[] merged =
CC_OperationParameterGroup.merge(fromXML.descriptors(), fromValues.clone(),
replacements);
+ assertNotSame(fromValues, merged);
+ /*
+ * "Longitude of natural origin" parameter should be the same.
+ */
+ assertEquals("Number of parameters", 2, merged.length);
+ assertSame("Longitude of natural origin", fromValues[1], merged[1]);
+ /*
+ * "Latitude of natural origin" should be a new parameter, because we
merged the remarks from the
+ * 'fromXML' descriptor with value class, unit and default value from
the 'fromValue' descriptor.
+ */
+ final GeneralParameterDescriptor incomplete =
fromXML.descriptors().get(0);
+ final DefaultParameterDescriptor<?> fromValue =
(DefaultParameterDescriptor<?>) fromValues[0];
+ final DefaultParameterDescriptor<?> complete =
(DefaultParameterDescriptor<?>) merged[0];
+ assertNotSame("Latitude of natural origin", incomplete, complete);
+ assertNotSame("Latitude of natural origin", fromValue, complete);
+ assertSame ("name", fromValue .getName(),
complete.getName());
+ assertSame ("remarks", incomplete.getRemarks(),
complete.getRemarks());
+ assertEquals ("valueClass", Double.class,
complete.getValueClass());
+ assertSame ("valueDomain", fromValue.getValueDomain(),
complete.getValueDomain());
+ /*
+ * All references to 'fromValue' will need to be replaced by
references to 'complete'.
+ */
+ assertEquals("replacements", Collections.singletonMap(fromValue,
complete), replacements);
+ }
}
Modified:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterFormatTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterFormatTest.java?rev=1700737&r1=1700736&r2=1700737&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterFormatTest.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/parameter/ParameterFormatTest.java
[UTF-8] Wed Sep 2 08:59:24 2015
@@ -44,7 +44,7 @@ import static org.apache.sis.metadata.is
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.4
- * @version 0.5
+ * @version 0.6
* @module
*/
@DependsOn(ParameterBuilderTest.class)
@@ -77,7 +77,9 @@ public final strictfp class ParameterFor
ParameterBuilder builder = new ParameterBuilder();
builder.setCodeSpace(EPSG, "EPSG").setRequired(true);
ParameterDescriptor<?>[] parameters = {
- builder.addIdentifier("8801").addName("Latitude of natural
origin") .addName(OGC, "latitude_of_origin").createBounded( -80, +84,
40, NonSI.DEGREE_ANGLE),
+ builder.addIdentifier("8801").addName("Latitude of natural
origin").addName(OGC, "latitude_of_origin")
+ .setRemarks("This parameter is shown for completeness, but
should never have a value different than 0 for this projection.")
+ .createBounded( -80, +84, 40, NonSI.DEGREE_ANGLE),
builder.addIdentifier("8802").addName("Longitude of natural
origin") .addName(OGC, "central_meridian") .createBounded(-180, +180, -60,
NonSI.DEGREE_ANGLE),
builder.addIdentifier("8805").addName("Scale factor at natural
origin") .addName(OGC, "scale_factor") .createStrictlyPositive(1,
Unit.ONE),
builder.addIdentifier("8806").addName("False
easting").setRequired(false).addName(OGC, "false_easting") .create( 5000,
SI.METRE),
@@ -127,12 +129,13 @@ public final strictfp class ParameterFor
"┌────────────────────────────────┬────────┬────────────┬───────────────┬───────────────┐\n"
+
"│ Name (EPSG) │ Type │ Obligation │
Value domain │ Default value │\n" +
"├────────────────────────────────┼────────┼────────────┼───────────────┼───────────────┤\n"
+
- "│ Latitude of natural origin │ Double │ Mandatory │
[-80 … 84]° │ 40.0° │\n" +
+ "│ Latitude of natural origin¹ │ Double │ Mandatory │
[-80 … 84]° │ 40.0° │\n" +
"│ Longitude of natural origin │ Double │ Mandatory │
[-180 … 180]° │ -60.0° │\n" +
"│ Scale factor at natural origin │ Double │ Mandatory │
(0 … ∞) │ 1.0 │\n" +
"│ False easting │ Double │ Optional │
(-∞ … ∞) m │ 5000.0 m │\n" +
"│ False northing │ Double │ Optional │
(-∞ … ∞) m │ 10000.0 m │\n" +
-
"└────────────────────────────────┴────────┴────────────┴───────────────┴───────────────┘\n",
text);
+
"└────────────────────────────────┴────────┴────────────┴───────────────┴───────────────┘\n"
+
+ "¹ This parameter is shown for completeness, but should never
have a value different than 0 for this projection.\n", text);
}
/**
@@ -158,11 +161,12 @@ public final strictfp class ParameterFor
"┌────────────────────────────────┬────────┬───────────────┬──────────┐\n" +
"│ Name (EPSG) │ Type │ Value domain │
Value │\n" +
"├────────────────────────────────┼────────┼───────────────┼──────────┤\n" +
- "│ Latitude of natural origin │ Double │ [-80 … 84]° │
20.0° │\n" +
+ "│ Latitude of natural origin¹ │ Double │ [-80 … 84]° │
20.0° │\n" +
"│ Longitude of natural origin │ Double │ [-180 … 180]° │
-60.0° │\n" +
"│ Scale factor at natural origin │ Double │ (0 … ∞) │
0.997 │\n" +
"│ False northing │ Double │ (-∞ … ∞) m │
20.0 km │\n" +
-
"└────────────────────────────────┴────────┴───────────────┴──────────┘\n",
text);
+
"└────────────────────────────────┴────────┴───────────────┴──────────┘\n" +
+ "¹ This parameter is shown for completeness, but should never
have a value different than 0 for this projection.\n", text);
}
/**
@@ -179,11 +183,12 @@ public final strictfp class ParameterFor
"┌────────────────────────────────┬────────┬─────────────────────┬──────────┐\n"
+
"│ Nom (EPSG) │ Type │ Domaine des
valeurs │ Valeur │\n" +
"├────────────────────────────────┼────────┼─────────────────────┼──────────┤\n"
+
- "│ Latitude of natural origin │ Double │ [-80 … 84]°
│ 20° │\n" +
+ "│ Latitude of natural origin¹ │ Double │ [-80 … 84]°
│ 20° │\n" +
"│ Longitude of natural origin │ Double │ [-180 … 180]°
│ -60° │\n" +
"│ Scale factor at natural origin │ Double │ (0 … ∞)
│ 0,997 │\n" +
"│ False northing │ Double │ (-∞ … ∞) m
│ 20 km │\n" +
-
"└────────────────────────────────┴────────┴─────────────────────┴──────────┘\n",
text);
+
"└────────────────────────────────┴────────┴─────────────────────┴──────────┘\n"
+
+ "¹ This parameter is shown for completeness, but should never
have a value different than 0 for this projection.\n", text);
}
/**
@@ -205,7 +210,7 @@ public final strictfp class ParameterFor
"╔═════════════════════════════════════════════╤════════╤════════════╤═══════════════╤═══════════════╗\n"
+
"║ Name │ Type │
Obligation │ Value domain │ Default value ║\n" +
"╟─────────────────────────────────────────────┼────────┼────────────┼───────────────┼───────────────╢\n"
+
- "║ EPSG: Latitude of natural origin (8801) │ Double │
Mandatory │ [-80 … 84]° │ 40.0° ║\n" +
+ "║ EPSG: Latitude of natural origin¹ (8801) │ Double │
Mandatory │ [-80 … 84]° │ 40.0° ║\n" +
"║ OGC: latitude_of_origin │ │
│ │ ║\n" +
"╟─────────────────────────────────────────────┼────────┼────────────┼───────────────┼───────────────╢\n"
+
"║ EPSG: Longitude of natural origin (8802) │ Double │
Mandatory │ [-180 … 180]° │ -60.0° ║\n" +
@@ -219,7 +224,8 @@ public final strictfp class ParameterFor
"╟─────────────────────────────────────────────┼────────┼────────────┼───────────────┼───────────────╢\n"
+
"║ EPSG: False northing (8807) │ Double │
Optional │ (-∞ … ∞) m │ 10000.0 m ║\n" +
"║ OGC: false_northing │ │
│ │ ║\n" +
-
"╚═════════════════════════════════════════════╧════════╧════════════╧═══════════════╧═══════════════╝\n",
text);
+
"╚═════════════════════════════════════════════╧════════╧════════════╧═══════════════╧═══════════════╝\n"
+
+ "¹ This parameter is shown for completeness, but should never
have a value different than 0 for this projection.\n", text);
}
/**
@@ -239,7 +245,7 @@ public final strictfp class ParameterFor
"╔═════════════════════════════════════════════╤════════╤════════════╤═══════════════╤══════════╗\n"
+
"║ Name │ Type │
Obligation │ Value domain │ Value ║\n" +
"╟─────────────────────────────────────────────┼────────┼────────────┼───────────────┼──────────╢\n"
+
- "║ EPSG: Latitude of natural origin (8801) │ Double │
Mandatory │ [-80 … 84]° │ 20.0° ║\n" +
+ "║ EPSG: Latitude of natural origin¹ (8801) │ Double │
Mandatory │ [-80 … 84]° │ 20.0° ║\n" +
"║ OGC: latitude_of_origin │ │
│ │ ║\n" +
"╟─────────────────────────────────────────────┼────────┼────────────┼───────────────┼──────────╢\n"
+
"║ EPSG: Longitude of natural origin (8802) │ Double │
Mandatory │ [-180 … 180]° │ -60.0° ║\n" +
@@ -250,7 +256,8 @@ public final strictfp class ParameterFor
"╟─────────────────────────────────────────────┼────────┼────────────┼───────────────┼──────────╢\n"
+
"║ EPSG: False northing (8807) │ Double │
Optional │ (-∞ … ∞) m │ 20.0 km ║\n" +
"║ OGC: false_northing │ │
│ │ ║\n" +
-
"╚═════════════════════════════════════════════╧════════╧════════════╧═══════════════╧══════════╝\n",
text);
+
"╚═════════════════════════════════════════════╧════════╧════════════╧═══════════════╧══════════╝\n"
+
+ "¹ This parameter is shown for completeness, but should never
have a value different than 0 for this projection.\n", text);
}
/**
@@ -315,14 +322,15 @@ public final strictfp class ParameterFor
text = format.format(createParameterValues());
assertMultilinesEquals(
"OGC: Mercator_1SP\n" +
- "┌────────────────────┬────────┬───────────────┬──────────┐\n"
+
- "│ Name (OGC) │ Type │ Value domain │ Value │\n"
+
- "├────────────────────┼────────┼───────────────┼──────────┤\n"
+
- "│ latitude_of_origin │ Double │ [-80 … 84]° │ 20.0° │\n"
+
- "│ central_meridian │ Double │ [-180 … 180]° │ -60.0° │\n"
+
- "│ scale_factor │ Double │ (0 … ∞) │ 0.997 │\n"
+
- "│ false_northing │ Double │ (-∞ … ∞) m │ 20.0 km │\n"
+
-
"└────────────────────┴────────┴───────────────┴──────────┘\n", text);
+
"┌─────────────────────┬────────┬───────────────┬──────────┐\n" +
+ "│ Name (OGC) │ Type │ Value domain │ Value
│\n" +
+
"├─────────────────────┼────────┼───────────────┼──────────┤\n" +
+ "│ latitude_of_origin¹ │ Double │ [-80 … 84]° │ 20.0°
│\n" +
+ "│ central_meridian │ Double │ [-180 … 180]° │ -60.0°
│\n" +
+ "│ scale_factor │ Double │ (0 … ∞) │ 0.997
│\n" +
+ "│ false_northing │ Double │ (-∞ … ∞) m │ 20.0 km
│\n" +
+
"└─────────────────────┴────────┴───────────────┴──────────┘\n" +
+ "¹ This parameter is shown for completeness, but should never
have a value different than 0 for this projection.\n", text);
}
/**
Modified:
sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/parameter/ParameterDescriptorGroup.xml
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/parameter/ParameterDescriptorGroup.xml?rev=1700737&r1=1700736&r2=1700737&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/parameter/ParameterDescriptorGroup.xml
(original)
+++
sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/parameter/ParameterDescriptorGroup.xml
Wed Sep 2 08:59:24 2015
@@ -32,6 +32,7 @@
<gml:identifier
codeSpace="IOGP">urn:ogc:def:parameter:EPSG::8801</gml:identifier>
<gml:name codeSpace="EPSG">Latitude of natural origin</gml:name>
<gml:name codeSpace="OGC">latitude_of_origin</gml:name>
+ <gml:remarks>This parameter is shown for completeness, but should never
have a value different than 0 for this projection.</gml:remarks>
</gml:OperationParameter>
</gml:parameter>
<gml:parameter>
Modified:
sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/parameter/ParameterValueGroup.xml
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/parameter/ParameterValueGroup.xml?rev=1700737&r1=1700736&r2=1700737&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/parameter/ParameterValueGroup.xml
(original)
+++
sis/branches/JDK8/core/sis-referencing/src/test/resources/org/apache/sis/parameter/ParameterValueGroup.xml
Wed Sep 2 08:59:24 2015
@@ -30,6 +30,7 @@
<gml:identifier
codeSpace="IOGP">urn:ogc:def:parameter:EPSG::8801</gml:identifier>
<gml:name codeSpace="EPSG">Latitude of natural origin</gml:name>
<gml:name codeSpace="OGC">latitude_of_origin</gml:name>
+ <gml:remarks>This parameter is shown for completeness, but should
never have a value different than 0 for this projection.</gml:remarks>
</gml:OperationParameter>
</gml:operationParameter>
</gml:ParameterValue>
@@ -75,6 +76,7 @@
<gml:identifier
codeSpace="IOGP">urn:ogc:def:parameter:EPSG::8801</gml:identifier>
<gml:name codeSpace="EPSG">Latitude of natural origin</gml:name>
<gml:name codeSpace="OGC">latitude_of_origin</gml:name>
+ <gml:remarks>This parameter is shown for completeness, but should
never have a value different than 0 for this projection.</gml:remarks>
</gml:OperationParameter>
</gml:parameter>
<gml:parameter>