Search in sources :

Example 1 with DefaultParameterDescriptorGroup

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());
}
Also used : DefaultParameterDescriptorGroup(org.apache.sis.parameter.DefaultParameterDescriptorGroup) HashMap(java.util.HashMap) DefaultParameterDescriptorGroup(org.apache.sis.parameter.DefaultParameterDescriptorGroup) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 2 with DefaultParameterDescriptorGroup

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());
}
Also used : DefaultParameterDescriptorGroup(org.apache.sis.parameter.DefaultParameterDescriptorGroup) HashMap(java.util.HashMap) DefaultParameterDescriptorGroup(org.apache.sis.parameter.DefaultParameterDescriptorGroup) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 3 with DefaultParameterDescriptorGroup

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());
}
Also used : DefaultParameterDescriptorGroup(org.apache.sis.parameter.DefaultParameterDescriptorGroup) HashMap(java.util.HashMap) DefaultParameterDescriptorGroup(org.apache.sis.parameter.DefaultParameterDescriptorGroup) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) GeneralParameterDescriptor(org.opengis.parameter.GeneralParameterDescriptor) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 4 with DefaultParameterDescriptorGroup

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));
}
Also used : DefaultParameterDescriptorGroup(org.apache.sis.parameter.DefaultParameterDescriptorGroup) HashMap(java.util.HashMap) DefaultParameterDescriptorGroup(org.apache.sis.parameter.DefaultParameterDescriptorGroup) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 5 with DefaultParameterDescriptorGroup

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);
}
Also used : DefaultParameterDescriptorGroup(org.apache.sis.parameter.DefaultParameterDescriptorGroup) HashMap(java.util.HashMap) DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) DefaultParameterDescriptorGroup(org.apache.sis.parameter.DefaultParameterDescriptorGroup) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) ImmutableIdentifier(org.apache.sis.metadata.iso.ImmutableIdentifier)

Aggregations

DefaultParameterDescriptorGroup (org.apache.sis.parameter.DefaultParameterDescriptorGroup)11 ParameterDescriptorGroup (org.opengis.parameter.ParameterDescriptorGroup)9 HashMap (java.util.HashMap)5 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)5 DependsOnMethod (org.apache.sis.test.DependsOnMethod)4 Test (org.junit.Test)4 DefaultOperationMethod (org.apache.sis.referencing.operation.DefaultOperationMethod)3 CorruptedObjectException (org.apache.sis.util.CorruptedObjectException)2 ParameterDescriptor (org.opengis.parameter.ParameterDescriptor)2 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 ImmutableIdentifier (org.apache.sis.metadata.iso.ImmutableIdentifier)1 DefaultCitation (org.apache.sis.metadata.iso.citation.DefaultCitation)1 DefaultParameterDescriptor (org.apache.sis.parameter.DefaultParameterDescriptor)1 AbstractIdentifiedObject (org.apache.sis.referencing.AbstractIdentifiedObject)1 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)1 ParameterNotFoundException (org.opengis.parameter.ParameterNotFoundException)1 IdentifiedObject (org.opengis.referencing.IdentifiedObject)1