Author: desruisseaux
Date: Mon Feb 23 22:25:10 2015
New Revision: 1661802
URL: http://svn.apache.org/r1661802
Log:
Register the Affine method in META-INF/services and added more tests.
Added:
sis/branches/JDK8/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.operation.OperationMethod
(with props)
Modified:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactoryTest.java
sis/branches/JDK8/ide-project/NetBeans/build.xml
Added:
sis/branches/JDK8/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.operation.OperationMethod
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.operation.OperationMethod?rev=1661802&view=auto
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.operation.OperationMethod
(added)
+++
sis/branches/JDK8/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.operation.OperationMethod
[UTF-8] Mon Feb 23 22:25:10 2015
@@ -0,0 +1,2 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements.
+org.apache.sis.internal.referencing.provider.Affine
Propchange:
sis/branches/JDK8/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.operation.OperationMethod
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK8/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.operation.OperationMethod
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactoryTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactoryTest.java?rev=1661802&r1=1661801&r2=1661802&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactoryTest.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/DefaultMathTransformFactoryTest.java
[UTF-8] Mon Feb 23 22:25:10 2015
@@ -16,14 +16,27 @@
*/
package org.apache.sis.referencing.operation.transform;
+import java.util.Set;
+import java.util.Map;
+import java.util.HashMap;
+import java.util.IdentityHashMap;
+import org.opengis.parameter.GeneralParameterDescriptor;
+import org.opengis.parameter.ParameterDescriptorGroup;
import org.opengis.util.NoSuchIdentifierException;
+import org.opengis.referencing.operation.Conversion;
+import org.opengis.referencing.operation.Projection;
+import org.opengis.referencing.operation.SingleOperation;
+import org.opengis.referencing.operation.OperationMethod;
+import org.apache.sis.internal.referencing.provider.Affine;
+import org.apache.sis.internal.util.Constants;
+import org.apache.sis.test.DependsOnMethod;
import org.apache.sis.test.DependsOn;
import org.apache.sis.test.TestCase;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-import static org.junit.Assert.*;
+import static org.opengis.test.Assert.*;
/**
@@ -63,9 +76,25 @@ public final strictfp class DefaultMathT
}
/**
+ * Tests the {@link
DefaultMathTransformFactory#getOperationMethod(String)} method.
+ *
+ * @throws NoSuchIdentifierException Should never happen.
+ */
+ @Test
+ public void testGetOperationMethod() throws NoSuchIdentifierException {
+ // A conversion which is not a projection.
+ OperationMethod method = factory.getOperationMethod(Constants.AFFINE);
+ assertInstanceOf("Affine", Affine.class, method);
+
+ // Same than above, using EPSG code.
+ assertSame("EPSG:9624", method,
factory.getOperationMethod("EPSG:9624"));
+ }
+
+ /**
* Tests non-existent operation method.
*/
@Test
+ @DependsOnMethod("testGetOperationMethod")
public void testNonExistentCode() {
try {
factory.getOperationMethod("EPXX:9624");
@@ -75,4 +104,53 @@ public final strictfp class DefaultMathT
assertTrue(message, message.contains("EPXX:9624"));
}
}
+
+ /**
+ * Tests the {@link
DefaultMathTransformFactory#getAvailableMethods(Class)} method.
+ *
+ * @throws NoSuchIdentifierException Should never happen.
+ */
+ @Test
+ @DependsOnMethod("testGetOperationMethod")
+ public void testGetAvailableMethods() throws NoSuchIdentifierException {
+ final Set<OperationMethod> transforms =
factory.getAvailableMethods(SingleOperation.class);
+ final Set<OperationMethod> conversions =
factory.getAvailableMethods(Conversion.class);
+ final Set<OperationMethod> projections =
factory.getAvailableMethods(Projection.class);
+ /*
+ * Following tests should not cause loading of more classes than
needed.
+ */
+ assertFalse(transforms .isEmpty());
+ assertFalse(conversions.isEmpty());
+ assertTrue (projections.isEmpty());
+ assertTrue
(conversions.contains(factory.getOperationMethod(Constants.AFFINE)));
+ /*
+ * Following tests will force instantiation of all remaining
OperationMethod.
+ */
+ assertTrue("Conversions should be a subset of transforms.",
transforms .containsAll(conversions));
+ assertTrue("Projections should be a subset of conversions.",
conversions.containsAll(projections));
+ }
+
+ /**
+ * Ensures that every parameter instance is unique. Actually this test is
not strong requirement.
+ * This is only for sharing existing resources by avoiding unnecessary
objects duplication.
+ */
+ @Test
+ @DependsOnMethod("testGetAvailableMethods")
+ public void ensureParameterUniqueness() {
+ final Map<GeneralParameterDescriptor, String> groupNames = new
IdentityHashMap<>();
+ final Map<GeneralParameterDescriptor, GeneralParameterDescriptor>
existings = new HashMap<>();
+ for (final OperationMethod method :
factory.getAvailableMethods(SingleOperation.class)) {
+ final ParameterDescriptorGroup group = method.getParameters();
+ final String name = group.getName().getCode();
+ for (final GeneralParameterDescriptor param : group.descriptors())
{
+ assertFalse("Parameter declared twice in the same group.",
name.equals(groupNames.put(param, name)));
+ final GeneralParameterDescriptor existing =
existings.put(param, param);
+ if (existing != null && existing != param) {
+ fail("Parameter “" + param.getName().getCode() + "”
defined in “" + name + '”'
+ + " was already defined in “" +
groupNames.get(existing) + "”."
+ + " The same instance could be shared.");
+ }
+ }
+ }
+ }
}
Modified: sis/branches/JDK8/ide-project/NetBeans/build.xml
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/ide-project/NetBeans/build.xml?rev=1661802&r1=1661801&r2=1661802&view=diff
==============================================================================
--- sis/branches/JDK8/ide-project/NetBeans/build.xml (original)
+++ sis/branches/JDK8/ide-project/NetBeans/build.xml Mon Feb 23 22:25:10 2015
@@ -62,6 +62,13 @@
</fileset>
</concat>
+ <!-- OperationMethod implementations to be loaded by ServiceLoader. -->
+ <concat
destfile="${build.classes.dir}/META-INF/services/org.opengis.referencing.operation.OperationMethod"
encoding="UTF-8" fixlastline="yes">
+ <fileset dir="${project.root}">
+ <include
name="*/*/src/main/resources/META-INF/services/org.opengis.referencing.operation.OperationMethod"/>
+ </fileset>
+ </concat>
+
<!-- ObjectConverter implementations to be loaded by ServiceLoader. -->
<concat
destfile="${build.classes.dir}/META-INF/services/org.apache.sis.util.ObjectConverter"
encoding="UTF-8" fixlastline="yes">
<fileset dir="${project.root}">