Search in sources :

Example 41 with SweField

use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.

the class SweCommonEncoderv101Test method should_throw_NoApplicableCodeException_with_DataRecord_and_field_with_not_supported_element.

@Test
public void should_throw_NoApplicableCodeException_with_DataRecord_and_field_with_not_supported_element() throws EncodingException {
    thrown.expect(EncodingException.class);
    thrown.expectMessage("The element type '" + getClass().getName() + "$1' " + "of the received '" + SweField.class.getName() + "' is not supported" + " by this encoder '" + SweCommonEncoderv101.class.getName() + "'.");
    sweCommonEncoderv101.encode(new SweDataRecord().addField(new SweField("test", new SweAbstractDataComponent() {

        @Override
        public SweDataComponentType getDataComponentType() {
            return null;
        }

        @Override
        public <T, X extends Throwable> T accept(SweDataComponentVisitor<T, X> visitor) {
            return null;
        }

        @Override
        public <X extends Throwable> void accept(VoidSweDataComponentVisitor<X> visitor) {
        }

        @Override
        public SweAbstractDataComponent copy() {
            return null;
        }
    })));
}
Also used : SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) SweDataComponentType(org.n52.shetland.ogc.swe.SweConstants.SweDataComponentType) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent) Test(org.junit.Test)

Example 42 with SweField

use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.

the class SweCommonEncoderv20Test method shouldEncodeDataRecordWithSweTextField.

@Test
public void shouldEncodeDataRecordWithSweTextField() throws OwsExceptionReport, EncodingException {
    final SweDataRecord record = new SweDataRecord();
    record.addField(new SweField("text", new SweText().setValue("textValue").setDefinition("textDef")));
    record.addField(new SweField("count", new SweCount().setValue(2).setDefinition("countDef")));
    final XmlObject encoded = sweCommonEncoderv20.encode(record);
    // validateDocument throws exceptions if the document is invalid
    XmlHelper.validateDocument(encoded, EncodingException::new);
}
Also used : SweText(org.n52.shetland.ogc.swe.simpleType.SweText) SweDataRecord(org.n52.shetland.ogc.swe.SweDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) EncodingException(org.n52.svalbard.encode.exception.EncodingException) SweCount(org.n52.shetland.ogc.swe.simpleType.SweCount) XmlObject(org.apache.xmlbeans.XmlObject) Test(org.junit.Test)

Example 43 with SweField

use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.

the class OmDecoderV20Test method testComplexObservation.

@Test
public void testComplexObservation() throws XmlException, DecodingException {
    XmlObject xml = XmlObject.Factory.parse(getComplexObservationXml());
    // FIXME
    // Object decoded = CodingHelper.decodeXmlObject(xml);
    Object decoded = omDecoderv20.decode(xml);
    assertThat(decoded, is(instanceOf(OmObservation.class)));
    OmObservation observation = (OmObservation) decoded;
    assertThat(observation.getValue(), is(instanceOf(SingleObservationValue.class)));
    assertThat(observation.getValue().getValue(), is(instanceOf(ComplexValue.class)));
    ComplexValue value = (ComplexValue) observation.getValue().getValue();
    assertThat(value.getValue(), is(notNullValue()));
    SweAbstractDataRecord dataRecord = value.getValue();
    assertThat(dataRecord.getFields(), hasSize(5));
    SweField field1 = dataRecord.getFields().get(0);
    SweField field2 = dataRecord.getFields().get(1);
    SweField field3 = dataRecord.getFields().get(2);
    SweField field4 = dataRecord.getFields().get(3);
    SweField field5 = dataRecord.getFields().get(4);
    errors.checkThat(field1.getElement().getDefinition(), is("http://example.tld/phenomenon/child/1"));
    errors.checkThat(field2.getElement().getDefinition(), is("http://example.tld/phenomenon/child/2"));
    errors.checkThat(field3.getElement().getDefinition(), is("http://example.tld/phenomenon/child/3"));
    errors.checkThat(field4.getElement().getDefinition(), is("http://example.tld/phenomenon/child/4"));
    errors.checkThat(field5.getElement().getDefinition(), is("http://example.tld/phenomenon/child/5"));
    errors.checkThat(field1.getElement().getDataComponentType(), is(SweDataComponentType.Quantity));
    errors.checkThat(field2.getElement().getDataComponentType(), is(SweDataComponentType.Boolean));
    errors.checkThat(field3.getElement().getDataComponentType(), is(SweDataComponentType.Count));
    errors.checkThat(field4.getElement().getDataComponentType(), is(SweDataComponentType.Text));
    errors.checkThat(field5.getElement().getDataComponentType(), is(SweDataComponentType.Category));
}
Also used : ComplexValue(org.n52.shetland.ogc.om.values.ComplexValue) SweAbstractDataRecord(org.n52.shetland.ogc.swe.SweAbstractDataRecord) SweField(org.n52.shetland.ogc.swe.SweField) OmObservation(org.n52.shetland.ogc.om.OmObservation) XmlObject(org.apache.xmlbeans.XmlObject) XmlObject(org.apache.xmlbeans.XmlObject) Test(org.junit.Test)

Example 44 with SweField

use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.

the class SweDataRecordTest method getFieldIndexByIdentifier_should_return_one.

@Test
public void getFieldIndexByIdentifier_should_return_one() {
    final SweDataRecord dataRecord = new SweDataRecord();
    dataRecord.addField(new SweField("identifier", new SweBoolean()));
    final SweBoolean b = new SweBoolean();
    final String definition = "test-element-definition";
    b.setDefinition(definition);
    final String name = "test-field-name";
    dataRecord.addField(new SweField(name, b));
    assertThat(dataRecord.getFieldIndexByIdentifier(definition), is(1));
    assertThat(dataRecord.getFieldIndexByIdentifier(name), is(1));
}
Also used : SweBoolean(org.n52.shetland.ogc.swe.simpleType.SweBoolean) Test(org.junit.Test)

Example 45 with SweField

use of org.n52.shetland.ogc.swe.SweField in project arctic-sea by 52North.

the class ProfileLevel method valueAsDataRecord.

public SweDataRecord valueAsDataRecord(SweDataRecord dataRecord) {
    int counter = 0;
    for (Value<?> v : getValue()) {
        if (v instanceof SweAbstractDataComponent) {
            SweAbstractDataComponent adc = (SweAbstractDataComponent) v;
            String name;
            if (adc.isSetName()) {
                name = adc.getName().getValue();
            } else if (adc.isSetDefinition()) {
                name = adc.getDefinition();
            } else {
                name = "component_" + counter++;
            }
            dataRecord.addField(new SweField(name, adc));
        }
    }
    return dataRecord;
}
Also used : SweField(org.n52.shetland.ogc.swe.SweField) SweAbstractDataComponent(org.n52.shetland.ogc.swe.SweAbstractDataComponent)

Aggregations

SweField (org.n52.shetland.ogc.swe.SweField)59 Test (org.junit.Test)42 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)34 XmlObject (org.apache.xmlbeans.XmlObject)20 SimpleDataRecordType (net.opengis.swe.x101.SimpleDataRecordType)19 SweDataRecord (org.n52.shetland.ogc.swe.SweDataRecord)19 SweBoolean (org.n52.shetland.ogc.swe.simpleType.SweBoolean)12 SweTime (org.n52.shetland.ogc.swe.simpleType.SweTime)12 AnyScalarPropertyType (net.opengis.swe.x101.AnyScalarPropertyType)11 SweQuantity (org.n52.shetland.ogc.swe.simpleType.SweQuantity)11 SweText (org.n52.shetland.ogc.swe.simpleType.SweText)11 SweAbstractDataComponent (org.n52.shetland.ogc.swe.SweAbstractDataComponent)10 SweSimpleDataRecord (org.n52.shetland.ogc.swe.SweSimpleDataRecord)10 DataComponentPropertyType (net.opengis.swe.x101.DataComponentPropertyType)9 DataRecordType (net.opengis.swe.x101.DataRecordType)9 SweCategory (org.n52.shetland.ogc.swe.simpleType.SweCategory)9 SweCount (org.n52.shetland.ogc.swe.simpleType.SweCount)9 SweTimeRange (org.n52.shetland.ogc.swe.simpleType.SweTimeRange)8 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)7 DateTime (org.joda.time.DateTime)4