use of org.apache.sis.parameter.DefaultParameterDescriptorGroup in project sis by apache.
the class CC_GeneralOperationParameterTest method testGroupMergeBecauseDifferentProperties.
/**
* Tests case where the unmarshalled parameter group needs to be merged with the complete parameter group.
* The reason for the group merge in this test is because the unmarshalled parameters have different remarks
* or different obligation.
*
* @throws JAXBException if this method failed to create test data.
*/
@Test
@DependsOnMethod({ "testGroupSubstitution", "testParameterMerge" })
public void testGroupMergeBecauseDifferentProperties() throws JAXBException {
final Map<String, String> properties = new HashMap<>(4);
assertNull(properties.put(DefaultParameterDescriptor.NAME_KEY, "Group"));
final ParameterDescriptorGroup provided = new DefaultParameterDescriptorGroup(properties, 1, 2, unmarshal("Parameter A", "Remarks A."), unmarshal("Parameter B", "Remarks B."), unmarshal("Parameter C", "Remarks C."));
assertNull(properties.put(DefaultParameterDescriptor.REMARKS_KEY, "More details here."));
final ParameterDescriptorGroup complete = new DefaultParameterDescriptorGroup(properties, 1, 2, create("Parameter A", "Remarks A.", true, 3), create("Parameter B", "Remarks B.", false, 4), create("Parameter C", "Different.", false, 5), create("Parameter D", "Remarks D.", false, 6));
final ParameterDescriptorGroup merged = (ParameterDescriptorGroup) CC_GeneralOperationParameter.merge(provided, complete);
assertNotSame(complete, provided);
assertSame("name", complete.getName(), merged.getName());
assertSame("remarks", complete.getRemarks(), merged.getRemarks());
assertEquals("minimumOccurs", 1, merged.getMinimumOccurs());
assertEquals("maximumOccurs", 2, merged.getMaximumOccurs());
final Iterator<GeneralParameterDescriptor> itc = complete.descriptors().iterator();
final Iterator<GeneralParameterDescriptor> itm = merged.descriptors().iterator();
// Not same because different obligation.
verifyParameter(itc.next(), itm.next(), false, "Remarks A.");
// Same ParameterDescriptor instance.
verifyParameter(itc.next(), itm.next(), true, "Remarks B.");
// Not same because different remarks.
verifyParameter(itc.next(), itm.next(), false, "Remarks C.");
assertTrue("Missing descriptor.", itc.hasNext());
assertFalse("Unexpected descriptor.", itm.hasNext());
}
use of org.apache.sis.parameter.DefaultParameterDescriptorGroup in project sis by apache.
the class CC_GeneralOperationParameterTest method testGroupMergeBecauseExtraParameter.
/**
* Tests case where the unmarshalled parameter group needs to be merged with the complete parameter group.
* The reason for the group merge in this test is because the unmarshalled parameters have a parameter not
* present in the "complete" group.
*
* @throws JAXBException if this method failed to create test data.
*/
@Test
@DependsOnMethod("testGroupMergeBecauseDifferentProperties")
public void testGroupMergeBecauseExtraParameter() throws JAXBException {
final Map<String, String> properties = new HashMap<>(4);
assertNull(properties.put(DefaultParameterDescriptor.NAME_KEY, "Group"));
final ParameterDescriptorGroup provided = new DefaultParameterDescriptorGroup(properties, 1, 2, unmarshal("Parameter A", "Remarks A."), unmarshal("Parameter B", "Remarks B."), unmarshal("Parameter C", "Remarks C."));
assertNull(properties.put(DefaultParameterDescriptor.REMARKS_KEY, "More details here."));
final ParameterDescriptorGroup complete = new DefaultParameterDescriptorGroup(properties, 1, 2, create("Parameter A", "Remarks A.", false, 3), create("Parameter C", "Remarks C.", false, 4));
loggings.assertNoUnexpectedLog();
final ParameterDescriptorGroup merged = (ParameterDescriptorGroup) CC_GeneralOperationParameter.merge(provided, complete);
assertNotSame(complete, provided);
assertSame("name", complete.getName(), merged.getName());
assertSame("remarks", complete.getRemarks(), merged.getRemarks());
assertEquals("minimumOccurs", 1, merged.getMinimumOccurs());
assertEquals("maximumOccurs", 2, merged.getMaximumOccurs());
loggings.assertNextLogContains("Parameter B", "Group");
loggings.assertNoUnexpectedLog();
final Iterator<GeneralParameterDescriptor> itc = complete.descriptors().iterator();
final Iterator<GeneralParameterDescriptor> itm = merged.descriptors().iterator();
verifyParameter(itc.next(), itm.next(), true, "Remarks A.");
final GeneralParameterDescriptor extra = itm.next();
assertEquals("name", "Parameter B", extra.getName().getCode());
assertEquals("remark", "Remarks B.", extra.getRemarks().toString());
verifyParameter(itc.next(), itm.next(), true, "Remarks C.");
assertFalse("Unexpected descriptor.", itc.hasNext());
assertFalse("Unexpected descriptor.", itm.hasNext());
}
use of org.apache.sis.parameter.DefaultParameterDescriptorGroup in project sis by apache.
the class CC_GeneralOperationParameterTest method testGroupMergeBecauseMissingParameter.
/**
* Tests case where the unmarshalled parameter group needs to be merged with the complete parameter group.
* The reason for the group merge in this test is because the unmarshalled parameters is missing a mandatory
* parameter.
*
* @throws JAXBException if this method failed to create test data.
*/
@Test
@DependsOnMethod("testGroupMergeBecauseDifferentProperties")
public void testGroupMergeBecauseMissingParameter() throws JAXBException {
final Map<String, String> properties = new HashMap<>(4);
assertNull(properties.put(DefaultParameterDescriptor.NAME_KEY, "Group"));
final ParameterDescriptorGroup provided = new DefaultParameterDescriptorGroup(properties, 1, 2, unmarshal("Parameter A", null), unmarshal("Parameter C", null));
assertNull(properties.put(DefaultParameterDescriptor.REMARKS_KEY, "More details here."));
final ParameterDescriptorGroup complete = new DefaultParameterDescriptorGroup(properties, 1, 2, create("Parameter A", null, false, 3), create("Parameter B", null, true, 4), create("Parameter C", null, false, 5));
final ParameterDescriptorGroup merged = (ParameterDescriptorGroup) CC_GeneralOperationParameter.merge(provided, complete);
assertNotSame(complete, provided);
assertSame("name", complete.getName(), merged.getName());
assertSame("remarks", complete.getRemarks(), merged.getRemarks());
assertEquals("minimumOccurs", 1, merged.getMinimumOccurs());
assertEquals("maximumOccurs", 2, merged.getMaximumOccurs());
final Iterator<GeneralParameterDescriptor> itc = complete.descriptors().iterator();
final Iterator<GeneralParameterDescriptor> itm = merged.descriptors().iterator();
verifyParameter(itc.next(), itm.next(), true, null);
// Skip the parameter which is missing in the unmarshalled descriptor group.
assertEquals("Missing parameter.", "Parameter B", itc.next().getName().getCode());
verifyParameter(itc.next(), itm.next(), true, null);
assertFalse("Unexpected descriptor.", itc.hasNext());
assertFalse("Unexpected descriptor.", itm.hasNext());
}
use of org.apache.sis.parameter.DefaultParameterDescriptorGroup in project sis by apache.
the class CC_GeneralOperationParameterTest method testGroupSubstitution.
/**
* Tests case where the unmarshalled parameter group can be substituted by the complete parameter group.
* The cases tested in this method should not create any new {@link ParameterDescriptorGroup} instance.
*
* @throws JAXBException if this method failed to create test data.
*/
@Test
@DependsOnMethod("testParameterSubstitution")
public void testGroupSubstitution() throws JAXBException {
final Map<String, String> properties = new HashMap<>(4);
assertNull(properties.put(DefaultParameterDescriptor.NAME_KEY, "Group"));
final ParameterDescriptorGroup provided = new DefaultParameterDescriptorGroup(properties, 1, 2, unmarshal("Parameter A", null), unmarshal("Parameter B", "Remarks B."), unmarshal("Parameter C", null));
assertNull(properties.put(DefaultParameterDescriptor.REMARKS_KEY, "More details here."));
final ParameterDescriptorGroup complete = new DefaultParameterDescriptorGroup(properties, 1, 2, create("Parameter A", "Remarks A.", false, 3), create("Parameter B", "Remarks B.", false, 4), create("Parameter C", "Remarks C.", false, 5), create("Parameter D", "Remarks D.", false, 6));
assertSame(complete, CC_GeneralOperationParameter.merge(provided, complete));
}
use of org.apache.sis.parameter.DefaultParameterDescriptorGroup in project sis by apache.
the class DefaultOperationMethodTest method create.
/**
* Creates a new two-dimensional operation method for an operation of the given name and identifier.
*
* @param method the operation name (example: "Mercator (variant A)").
* @param identifier the EPSG numeric identifier (example: "9804").
* @param formula formula citation (example: "EPSG guidance note #7-2").
* @param dimension the number of input and output dimension, or {@code null}.
* @param parameters the parameters (can be empty).
* @return the operation method.
*/
static DefaultOperationMethod create(final String method, final String identifier, final String formula, final Integer dimension, final ParameterDescriptor<?>... parameters) {
final Map<String, Object> properties = new HashMap<>(8);
assertNull(properties.put(OperationMethod.NAME_KEY, method));
assertNull(properties.put(ReferenceIdentifier.CODESPACE_KEY, "EPSG"));
assertNull(properties.put(Identifier.AUTHORITY_KEY, Citations.EPSG));
/*
* The parameter group for a Mercator projection is actually not empty, but it is not the purpose of
* this class to test DefaultParameterDescriptorGroup. So we use an empty group of parameters here.
*/
final ParameterDescriptorGroup pg = new DefaultParameterDescriptorGroup(properties, 1, 1, parameters);
/*
* NAME_KEY share the same Identifier instance for saving a little bit of memory.
* Then define the other properties to be given to OperationMethod.
*/
assertNotNull(properties.put(OperationMethod.NAME_KEY, pg.getName()));
assertNull(properties.put(OperationMethod.IDENTIFIERS_KEY, new ImmutableIdentifier(Citations.EPSG, "EPSG", identifier)));
assertNull(properties.put(OperationMethod.FORMULA_KEY, new DefaultCitation(formula)));
return new DefaultOperationMethod(properties, dimension, dimension, pg);
}
Aggregations