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;
}
})));
}
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);
}
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));
}
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));
}
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;
}
Aggregations