use of org.n52.svalbard.decode.SweCommonDecoderV101 in project arctic-sea by 52North.
the class BatchRequestDecodingTest method before.
@Before
public void before() throws DecodingException {
DecoderRepository decoderRepository = new DecoderRepository();
this.decoder = new BatchRequestDecoder();
this.decoder.setDecoderRepository(decoderRepository);
InsertSensorRequestDecoder insertSensorRequestDecoder = new InsertSensorRequestDecoder();
insertSensorRequestDecoder.setDecoderRepository(decoderRepository);
InsertObservationRequestDecoder insertObservationRequestDecoder = new InsertObservationRequestDecoder();
insertObservationRequestDecoder.setDecoderRepository(decoderRepository);
SensorMLDecoderV101 sensorMLDecoder = new SensorMLDecoderV101();
sensorMLDecoder.setXmlOptions(XmlOptions::new);
sensorMLDecoder.setDecoderRepository(decoderRepository);
SweCommonDecoderV101 sweCommonDecoder = new SweCommonDecoderV101();
sweCommonDecoder.setXmlOptions(XmlOptions::new);
sweCommonDecoder.setDecoderRepository(decoderRepository);
GmlDecoderv311 gmlDecoderv311 = new GmlDecoderv311();
ObservationDecoder observationDecoder = new ObservationDecoder();
observationDecoder.setDecoderRepository(decoderRepository);
InsertResultTemplateRequestDecoder insertResultTemplateRequestDecoder = new InsertResultTemplateRequestDecoder();
insertResultTemplateRequestDecoder.setDecoderRepository(decoderRepository);
InsertResultRequestDecoder insertResultRequestDecoder = new InsertResultRequestDecoder();
insertResultRequestDecoder.setDecoderRepository(decoderRepository);
FieldDecoder fieldDecoder = new FieldDecoder();
fieldDecoder.setDecoderRepository(decoderRepository);
decoderRepository.setDecoders(Arrays.asList(decoder, insertSensorRequestDecoder, insertObservationRequestDecoder, insertResultTemplateRequestDecoder, insertResultRequestDecoder, sensorMLDecoder, sweCommonDecoder, observationDecoder, fieldDecoder, gmlDecoderv311));
decoderRepository.init();
this.request = decoder.decodeJSON(json, true);
}
use of org.n52.svalbard.decode.SweCommonDecoderV101 in project arctic-sea by 52North.
the class SweCommonDecoderV101Test method should_decode_Boolean_with_Quality_Quantity.
@Test
public void should_decode_Boolean_with_Quality_Quantity() throws DecodingException {
final BooleanDocument xbBoolean = BooleanDocument.Factory.newInstance();
final BigDecimal quantityValue = BigDecimal.valueOf(42.5);
xbBoolean.addNewBoolean().addNewQuality().addNewQuantity().setValue(quantityValue.doubleValue());
final Object decodedObject = new SweCommonDecoderV101().decode(xbBoolean);
assertThat(decodedObject, is(instanceOf(SweBoolean.class)));
final SweBoolean sweBoolean = (SweBoolean) decodedObject;
assertThat(sweBoolean.isSetQuality(), is(true));
assertThat(sweBoolean.getQuality().size(), is(1));
assertThat(sweBoolean.getQuality().iterator().next(), is(instanceOf(SweQuantity.class)));
assertThat(((SweQuantity) sweBoolean.getQuality().iterator().next()).getValue(), is(quantityValue));
}
use of org.n52.svalbard.decode.SweCommonDecoderV101 in project arctic-sea by 52North.
the class SweCommonDecoderV101Test method should_decode_Quantity_with_Quality_Category.
@Test
public void should_decode_Quantity_with_Quality_Category() throws DecodingException {
final QuantityDocument xbQuantity = QuantityDocument.Factory.newInstance();
final String categoryValue = "quality-category";
xbQuantity.addNewQuantity().addNewQuality().addNewCategory().setValue(categoryValue);
final Object decodedObject = new SweCommonDecoderV101().decode(xbQuantity);
assertThat(decodedObject, is(instanceOf(SweQuantity.class)));
final SweQuantity sweQuantity = (SweQuantity) decodedObject;
assertThat(sweQuantity.isSetQuality(), is(true));
assertThat(sweQuantity.getQuality().size(), is(1));
assertThat(sweQuantity.getQuality().iterator().next(), is(instanceOf(SweCategory.class)));
assertThat(((SweCategory) sweQuantity.getQuality().iterator().next()).getValue(), is(categoryValue));
}
use of org.n52.svalbard.decode.SweCommonDecoderV101 in project arctic-sea by 52North.
the class SweCommonDecoderV101Test method should_decode_Category_with_Quality_QuantityRange.
@Test
public void should_decode_Category_with_Quality_QuantityRange() throws DecodingException {
final CategoryDocument xbQuantity = CategoryDocument.Factory.newInstance();
final BigDecimal rangeStart = BigDecimal.valueOf(1.0);
final BigDecimal rangeEnd = BigDecimal.valueOf(2.0);
final ArrayList<BigDecimal> categoryValue = Lists.newArrayList(rangeStart, rangeEnd);
xbQuantity.addNewCategory().addNewQuality().addNewQuantityRange().setValue(categoryValue);
final Object decodedObject = new SweCommonDecoderV101().decode(xbQuantity);
assertThat(decodedObject, is(instanceOf(SweCategory.class)));
final SweCategory sweCategory = (SweCategory) decodedObject;
assertThat(sweCategory.isSetQuality(), is(true));
assertThat(sweCategory.getQuality().size(), is(1));
assertThat(sweCategory.getQuality().iterator().next(), is(instanceOf(SweQuantityRange.class)));
assertThat(((SweQuantityRange) sweCategory.getQuality().iterator().next()).getValue(), is(new RangeValue<BigDecimal>(rangeStart, rangeEnd)));
}
use of org.n52.svalbard.decode.SweCommonDecoderV101 in project arctic-sea by 52North.
the class SweCommonDecoderV101Test method should_decode_TimeRange.
@Test
public void should_decode_TimeRange() throws DecodingException {
final TimeRangeDocument xbTimeRangeDoc = TimeRangeDocument.Factory.newInstance();
TimeRange xbTimeRange = xbTimeRangeDoc.addNewTimeRange();
final DateTime startDate = new DateTime(1970, 1, 1, 0, 0, DateTimeZone.UTC);
final DateTime endDate = new DateTime(2013, 12, 31, 23, 59, DateTimeZone.UTC);
final List<String> values = Lists.newArrayList(startDate.toString(), endDate.toString());
xbTimeRange.setValue(values);
final String iso8601Uom = "urn:ogc:def:unit:ISO:8601";
xbTimeRange.addNewUom().setHref(iso8601Uom);
final Object decodedObject = new SweCommonDecoderV101().decode(xbTimeRange);
assertThat(decodedObject, is(instanceOf(SweTimeRange.class)));
final SweTimeRange sweTimeRange = (SweTimeRange) decodedObject;
assertThat(sweTimeRange.isSetUom(), is(true));
assertThat(sweTimeRange.getUom(), is(iso8601Uom));
assertThat(sweTimeRange.isSetValue(), is(true));
assertThat(sweTimeRange.getValue().getRangeStart(), is(startDate));
assertThat(sweTimeRange.getValue().getRangeEnd(), is(endDate));
}
Aggregations