use of org.geotoolkit.swe.xml.v100.DataRecordType in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_encode_Datarecord_with_fieldCount.
@Test
public void should_encode_Datarecord_with_fieldCount() throws EncodingException {
final String field1Name = "test-name";
final int field1Value = 52;
final XmlObject encode = sweCommonEncoderv101.encode(new SweDataRecord().addField(new SweField(field1Name, new SweCount().setValue(field1Value))));
assertThat(encode, is(instanceOf(DataRecordType.class)));
final DataRecordType xbDataRecord = (DataRecordType) encode;
final DataComponentPropertyType field1 = xbDataRecord.getFieldArray(0);
assertThat(xbDataRecord.getFieldArray().length, is(1));
assertThat(field1.isSetCount(), is(TRUE));
assertThat(field1.getName(), is(field1Name));
assertThat(field1.getCount().getValue(), is(BigInteger.valueOf(field1Value)));
}
use of org.geotoolkit.swe.xml.v100.DataRecordType in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_encode_Datarecord_with_fieldTime.
@Test
public void should_encode_Datarecord_with_fieldTime() throws EncodingException {
final String field1Name = "test-name";
final DateTime field1Value = new DateTime(System.currentTimeMillis());
final XmlObject encode = sweCommonEncoderv101.encode(new SweDataRecord().addField(new SweField(field1Name, new SweTime().setValue(field1Value))));
assertThat(encode, is(instanceOf(DataRecordType.class)));
final DataRecordType xbDataRecord = (DataRecordType) encode;
final DataComponentPropertyType field1 = xbDataRecord.getFieldArray(0);
assertThat(xbDataRecord.getFieldArray().length, is(1));
assertThat(field1.isSetTime(), is(TRUE));
assertThat(field1.getName(), is(field1Name));
final DateTime xbTime = new DateTime(((XmlCalendar) field1.getTime().getValue()).getTimeInMillis(), DateTimeZone.UTC);
assertThat(xbTime.toDateTime(field1Value.getZone()), is(field1Value));
}
use of org.geotoolkit.swe.xml.v100.DataRecordType in project arctic-sea by 52North.
the class SweCommonEncoderv101Test method should_encode_Datarecord_with_fieldText.
@Test
public void should_encode_Datarecord_with_fieldText() throws EncodingException {
final String field1Name = "test-name";
final String field1Value = "test-value";
final XmlObject encode = sweCommonEncoderv101.encode(new SweDataRecord().addField(new SweField(field1Name, new SweText().setValue(field1Value))));
assertThat(encode, is(instanceOf(DataRecordType.class)));
final DataRecordType xbDataRecord = (DataRecordType) encode;
final DataComponentPropertyType field1 = xbDataRecord.getFieldArray(0);
assertThat(xbDataRecord.getFieldArray().length, is(1));
assertThat(field1.isSetText(), is(TRUE));
assertThat(field1.getName(), is(field1Name));
assertThat(field1.getText().getValue(), is(field1Value));
}
use of org.geotoolkit.swe.xml.v100.DataRecordType in project geotoolkit by Geomatys.
the class SweXMLBindingTest method marshallingTest.
/**
* Test simple Record Marshalling.
*/
@Test
public void marshallingTest() throws JAXBException, IOException, ParserConfigurationException, SAXException {
Text text = new Text("definition", "some value");
StringWriter sw = new StringWriter();
marshaller.marshal(text, sw);
String result = sw.toString();
// we remove the first line
result = result.substring(result.indexOf("?>") + 2).trim();
// we remove the xmlmns
result = StringUtilities.removeXmlns(result);
String expResult = "<swe:Text definition=\"definition\" >" + '\n' + " <swe:value>some value</swe:value>" + '\n' + "</swe:Text>";
assertEquals(expResult, result.trim());
SimpleDataRecordType elementType = new SimpleDataRecordType();
AnyScalarPropertyType any = new AnyScalarPropertyType("id-1", "any name", text);
TextBlockType encoding = new TextBlockType("encoding-1", ",", "@@", ".");
elementType.setField(Arrays.asList(any));
DataArrayType array = new DataArrayType("array-id-1", 0, "array-id-1", elementType, encoding, null, null);
sw = new StringWriter();
marshaller.marshal(array, sw);
result = sw.toString();
// we remove the first line
result = result.substring(result.indexOf("?>") + 2).trim();
expResult = "<swe:DataArray gml:id=\"array-id-1\"" + " xmlns:gml=\"http://www.opengis.net/gml\"" + " xmlns:swe=\"http://www.opengis.net/swe/1.0.1\">" + '\n' + " <swe:elementCount>" + '\n' + " <swe:Count>" + '\n' + " <swe:value>0</swe:value>" + '\n' + " </swe:Count>" + '\n' + " </swe:elementCount>" + '\n' + " <swe:elementType name=\"array-id-1\">" + '\n' + " <swe:SimpleDataRecord>" + '\n' + " <swe:field name=\"any name\">" + '\n' + " <swe:Text definition=\"definition\">" + '\n' + " <swe:value>some value</swe:value>" + '\n' + " </swe:Text>" + '\n' + " </swe:field>" + '\n' + " </swe:SimpleDataRecord>" + '\n' + " </swe:elementType>" + '\n' + " <swe:encoding>" + '\n' + " <swe:TextBlock blockSeparator=\"@@\" decimalSeparator=\".\" tokenSeparator=\",\" id=\"encoding-1\"/>" + '\n' + " </swe:encoding>" + '\n' + "</swe:DataArray>" + '\n';
assertXmlEquals(expResult, result, "xmlns:*");
ObjectFactory factory = new ObjectFactory();
final List<DataComponentPropertyType> fields = new ArrayList<DataComponentPropertyType>();
fields.add(DataComponentPropertyType.LATITUDE_FIELD);
fields.add(DataComponentPropertyType.LONGITUDE_FIELD);
fields.add(DataComponentPropertyType.TIME_FIELD);
final DataRecordType posRecord = new DataRecordType(null, fields);
final DataBlockDefinitionType definition = new DataBlockDefinitionType(null, Arrays.asList((AbstractDataComponentType) posRecord), TextBlockType.DEFAULT_ENCODING);
marshaller.marshal(factory.createDataBlockDefinition(definition), System.out);
org.geotoolkit.swe.xml.v200.ObjectFactory factoryV200 = new org.geotoolkit.swe.xml.v200.ObjectFactory();
org.geotoolkit.swe.xml.v200.DataArrayType arrayV200 = new org.geotoolkit.swe.xml.v200.DataArrayType("test-id", 2, null, "balbbla", "test-id", null, null);
marshaller.marshal(factoryV200.createDataArray(arrayV200), System.out);
}
use of org.geotoolkit.swe.xml.v100.DataRecordType in project geotoolkit by Geomatys.
the class SweXMLBindingTest method cloneDataBlockDefinitionTest.
@Test
public void cloneDataBlockDefinitionTest() throws Exception {
final List<DataComponentPropertyType> fields = new ArrayList<DataComponentPropertyType>();
fields.add(DataComponentPropertyType.LATITUDE_FIELD);
fields.add(DataComponentPropertyType.LONGITUDE_FIELD);
fields.add(DataComponentPropertyType.TIME_FIELD);
final DataRecordType posRecord = new DataRecordType(null, fields);
final DataBlockDefinitionType expResult = new DataBlockDefinitionType(null, Arrays.asList((AbstractDataComponentType) posRecord), TextBlockType.DEFAULT_ENCODING);
final DataBlockDefinitionType result = new DataBlockDefinitionType(expResult);
assertEquals(expResult.getEncoding(), result.getEncoding());
assertEquals(expResult, result);
}
Aggregations