public void testCreate() throws FactoryException {
final CRSAuthorityFactory crsFactory;
final CoordinateOperationFactory opFactory;
CoordinateReferenceSystem sourceCRS;
CoordinateReferenceSystem targetCRS;
CoordinateOperation operation;
crsFactory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", null);
opFactory = ReferencingFactoryFinder.getCoordinateOperationFactory(null);
sourceCRS = crsFactory.createCoordinateReferenceSystem("4230");
targetCRS = crsFactory.createCoordinateReferenceSystem("4326");
operation = opFactory.createOperation(sourceCRS, targetCRS);
assertSame(sourceCRS, operation.getSourceCRS());
assertSame(targetCRS, operation.getTargetCRS());
assertSame(operation, opFactory.createOperation(sourceCRS, targetCRS));
assertTrue("Expected a buffered factory but got " + opFactory.getClass().getName(),
opFactory instanceof BufferedCoordinateOperationFactory);
assertTrue("EPSG authority factory not found.",
((BufferedCoordinateOperationFactory) opFactory).getImplementationHints().
get(Hints.COORDINATE_OPERATION_FACTORY) instanceof AuthorityBackedFactory);
assertEquals("1612", getIdentifier(operation)); // See comment in DefaultDataSourceTest.
assertEquals(1.0, AbstractCoordinateOperation.getAccuracy(operation), 1E-6);
assertTrue(operation instanceof Transformation);
/*
* Tests a transformation not backed directly by an authority factory.
* However, the inverse transform may exist in the authority factory.
*/
sourceCRS = crsFactory.createCoordinateReferenceSystem("4326");
targetCRS = crsFactory.createCoordinateReferenceSystem("2995");
operation = opFactory.createOperation(sourceCRS, targetCRS);
assertTrue("This test needs an operation not backed by the EPSG factory.",
operation.getIdentifiers().isEmpty());
// Should contains exactly one transformations and an arbitrary number of conversions.
assertTrue(operation instanceof ConcatenatedOperation);
int count = 0;
for (final Iterator it=((ConcatenatedOperation) operation).getOperations().iterator(); it.hasNext();) {
final CoordinateOperation op = (CoordinateOperation) it.next();
if (op instanceof Transformation) {
count++;
} else {
assertTrue("Expected Conversion but got " +
Classes.getShortName(AbstractCoordinateOperation.getType(op)) + ". ",