Search in sources :

Example 1 with ParameterDescriptorGroup

use of org.opengis.parameter.ParameterDescriptorGroup in project sis by apache.

the class TensorValuesTest method testDescriptor.

/**
 * Tests {@link TensorValues#descriptor(String)}.
 */
@Test
public void testDescriptor() {
    final Double N0 = 0.0;
    final Double N1 = 1.0;
    final Integer N3 = 3;
    final ParameterValueGroup group = createWKT1();
    final ParameterDescriptorGroup d = group.getDescriptor();
    assertDescriptorEquals(NUM_ROW, N3, d.descriptor(NUM_ROW));
    assertDescriptorEquals(NUM_COL, N3, d.descriptor(NUM_COL));
    assertDescriptorEquals("elt_0_0", N1, d.descriptor("elt_0_0"));
    assertDescriptorEquals("elt_0_1", N0, d.descriptor("elt_0_1"));
    assertDescriptorEquals("elt_0_2", N0, d.descriptor("elt_0_2"));
    assertDescriptorEquals("elt_1_0", N0, d.descriptor("elt_1_0"));
    assertDescriptorEquals("elt_1_1", N1, d.descriptor("elt_1_1"));
    assertDescriptorEquals("elt_1_2", N0, d.descriptor("elt_1_2"));
    assertDescriptorEquals("elt_2_0", N0, d.descriptor("elt_2_0"));
    assertDescriptorEquals("elt_2_1", N0, d.descriptor("elt_2_1"));
    assertDescriptorEquals("elt_2_2", N1, d.descriptor("elt_2_2"));
    /*
         * Same test than above, but using the EPSG or pseudo-EPSG names.
         */
    assertDescriptorEquals("elt_0_0", N1, d.descriptor("A0"));
    assertDescriptorEquals("elt_0_1", N0, d.descriptor("A1"));
    assertDescriptorEquals("elt_0_2", N0, d.descriptor("A2"));
    assertDescriptorEquals("elt_1_0", N0, d.descriptor("B0"));
    assertDescriptorEquals("elt_1_1", N1, d.descriptor("B1"));
    assertDescriptorEquals("elt_1_2", N0, d.descriptor("B2"));
    assertDescriptorEquals("elt_2_0", N0, d.descriptor("C0"));
    assertDescriptorEquals("elt_2_1", N0, d.descriptor("C1"));
    assertDescriptorEquals("elt_2_2", N1, d.descriptor("C2"));
    /*
         * If we reduce the matrix size, than it shall not be possible
         * anymore to get the descriptor in the row that we removed.
         */
    group.parameter(NUM_COL).setValue(2);
    try {
        d.descriptor("elt_2_2");
        fail("elt_2_2 should not exist.");
    } catch (ParameterNotFoundException e) {
        final String message = e.getMessage();
        assertTrue(message, message.contains("elt_2_2"));
        assertTrue(message, message.contains(GROUP_NAME));
    }
}
Also used : ParameterValueGroup(org.opengis.parameter.ParameterValueGroup) ParameterDescriptorGroup(org.opengis.parameter.ParameterDescriptorGroup) ParameterNotFoundException(org.opengis.parameter.ParameterNotFoundException) Test(org.junit.Test)

Example 2 with ParameterDescriptorGroup

use of org.opengis.parameter.ParameterDescriptorGroup 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 3 with ParameterDescriptorGroup

use of org.opengis.parameter.ParameterDescriptorGroup 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 4 with ParameterDescriptorGroup

use of org.opengis.parameter.ParameterDescriptorGroup 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 5 with ParameterDescriptorGroup

use of org.opengis.parameter.ParameterDescriptorGroup 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)

Aggregations

ParameterDescriptorGroup (org.opengis.parameter.ParameterDescriptorGroup)27 DefaultParameterDescriptorGroup (org.apache.sis.parameter.DefaultParameterDescriptorGroup)13 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)13 Test (org.junit.Test)8 HashMap (java.util.HashMap)7 DependsOnMethod (org.apache.sis.test.DependsOnMethod)6 ParameterDescriptor (org.opengis.parameter.ParameterDescriptor)5 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)5 DefaultOperationMethod (org.apache.sis.referencing.operation.DefaultOperationMethod)4 ParameterNotFoundException (org.opengis.parameter.ParameterNotFoundException)4 OperationMethod (org.opengis.referencing.operation.OperationMethod)3 ArrayList (java.util.ArrayList)2 IdentityHashMap (java.util.IdentityHashMap)2 FormattableObject (org.apache.sis.io.wkt.FormattableObject)2 ParameterBuilder (org.apache.sis.parameter.ParameterBuilder)2 GeneralParameterValue (org.opengis.parameter.GeneralParameterValue)2 FactoryException (org.opengis.util.FactoryException)2 Collection (java.util.Collection)1 LinkedHashMap (java.util.LinkedHashMap)1 UnmodifiableArrayList (org.apache.sis.internal.util.UnmodifiableArrayList)1