use of net.opengis.gml.v_3_2_1.TimePeriodType in project geotoolkit by Geomatys.
the class GmlXMLBindingTest method timePeriodUmarshallingTest.
@Test
public void timePeriodUmarshallingTest() throws Exception {
TimePositionType begin = new TimePositionType("2002-08-01");
TimePositionType end = new TimePositionType("2003-08-01");
TimePeriodType expResult = new TimePeriodType(new TimeInstantType(begin), new TimeInstantType(end));
String xml = "<gml:TimePeriod xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + " <gml:beginPosition>2002-08-01</gml:beginPosition>" + '\n' + " <gml:endPosition>2003-08-01</gml:endPosition>" + '\n' + "</gml:TimePeriod>" + '\n';
Object result = unmarshaller.unmarshal(new StringReader(xml));
if (result instanceof JAXBElement) {
result = ((JAXBElement) result).getValue();
}
assertPeriodEquals(expResult, (Period) result);
end = null;
expResult = new TimePeriodType(new TimeInstantType(begin), new TimeInstantType(end));
xml = "<gml:TimePeriod xmlns:gml=\"http://www.opengis.net/gml\">" + '\n' + " <gml:beginPosition>2002-08-01</gml:beginPosition>" + '\n' + "</gml:TimePeriod>" + '\n';
result = unmarshaller.unmarshal(new StringReader(xml));
if (result instanceof JAXBElement) {
result = ((JAXBElement) result).getValue();
}
assertPeriodEquals(expResult, (Period) result);
}
use of net.opengis.gml.v_3_2_1.TimePeriodType in project geotoolkit by Geomatys.
the class TimePeriodTypeTest method getTime3Test.
@Test
public void getTime3Test() throws Exception {
String snull = null;
TimeInstantType tb = new TimeInstantType(new TimePositionType("2008-11-01T02:00:00"));
TimeInstantType te = new TimeInstantType(new TimePositionType("2008-11-01T02:01:00"));
TimePeriodType tp = new TimePeriodType(null, snull);
tp.setBegin(new TimeInstantPropertyType(tb));
tp.setEnd(new TimeInstantPropertyType(te));
assertEquals(60000, tp.getTime());
tb = new TimeInstantType(new TimePositionType("2008-11-01T01:00:00"));
te = new TimeInstantType(new TimePositionType("2008-11-01T02:00:00"));
tp = new TimePeriodType(null, snull);
tp.setBegin(new TimeInstantPropertyType(tb));
tp.setEnd(new TimeInstantPropertyType(te));
assertEquals(3600000, tp.getTime());
tp = new TimePeriodType(null, snull);
tp.setBegin(new TimeInstantPropertyType(tb));
assertEquals(-1, tp.getTime());
tp = new TimePeriodType(null, snull);
tp.setEnd(new TimeInstantPropertyType(te));
assertEquals(-1, tp.getTime());
tp = new TimePeriodType(null, snull);
assertEquals(-1, tp.getTime());
}
use of net.opengis.gml.v_3_2_1.TimePeriodType in project geotoolkit by Geomatys.
the class TimePeriodTypeTest method getTimeTest.
@Test
public void getTimeTest() throws Exception {
final String id = "id-1";
TimePeriodType tp = new TimePeriodType(id, "2008-11-01T02:00:00", "2008-11-01T02:01:00");
assertEquals(60000, tp.getTime());
tp = new TimePeriodType(id, "2008-11-01T01:00:00", "2008-11-01T02:00:00");
assertEquals(3600000, tp.getTime());
tp = new TimePeriodType(id, "2008-11-01T01:00:00", null);
assertEquals(-1, tp.getTime());
tp = new TimePeriodType(id, null, "2008-11-01T02:00:00");
assertEquals(-1, tp.getTime());
String s1 = null;
tp = new TimePeriodType(id, s1, null);
assertEquals(-1, tp.getTime());
}
use of net.opengis.gml.v_3_2_1.TimePeriodType in project geotoolkit by Geomatys.
the class GmlXMLBindingTest method timePeriodUmarshallingTest.
@Test
public void timePeriodUmarshallingTest() throws Exception {
TimePositionType begin = new TimePositionType("2002-08-01");
TimePositionType end = new TimePositionType("2003-08-01");
TimePeriodType expResult = new TimePeriodType(begin, end);
String xml = "<gml:TimePeriod xmlns:gml=\"http://www.opengis.net/gml/3.2\">" + '\n' + " <gml:beginPosition>2002-08-01</gml:beginPosition>" + '\n' + " <gml:endPosition>2003-08-01</gml:endPosition>" + '\n' + "</gml:TimePeriod>" + '\n';
Object result = unmarshaller.unmarshal(new StringReader(xml));
if (result instanceof JAXBElement) {
result = ((JAXBElement) result).getValue();
}
assertEquals(expResult, result);
end = null;
expResult = new TimePeriodType(begin, end);
xml = "<gml:TimePeriod xmlns:gml=\"http://www.opengis.net/gml/3.2\">" + '\n' + " <gml:beginPosition>2002-08-01</gml:beginPosition>" + '\n' + "</gml:TimePeriod>" + '\n';
result = unmarshaller.unmarshal(new StringReader(xml));
if (result instanceof JAXBElement) {
result = ((JAXBElement) result).getValue();
}
assertEquals(expResult, result);
}
use of net.opengis.gml.v_3_2_1.TimePeriodType in project geotoolkit by Geomatys.
the class GmlXMLBindingTest method marshallingTest.
/**
* Test simple Record Marshalling.
*
* @throws JAXBException
*/
@Test
public void marshallingTest() throws Exception {
DirectPositionType lower = new DirectPositionType(-30.711, 134.196);
DirectPositionType upper = new DirectPositionType(-30.702, 134.205);
EnvelopeType env = new EnvelopeType(lower, upper, "urn:ogc:def:crs:EPSG:6.8:4283");
StringWriter sw = new StringWriter();
marshaller.marshal(FACTORY.createEnvelope(env), sw);
String result = sw.toString();
// we remove the first line
result = result.substring(result.indexOf("?>") + 2).trim();
String expResult = "<gml:Envelope xmlns:gml=\"http://www.opengis.net/gml/3.2\" srsName=\"urn:ogc:def:crs:EPSG:6.8:4283\" >" + '\n' + " <gml:lowerCorner>-30.711 134.196</gml:lowerCorner>" + '\n' + " <gml:upperCorner>-30.702 134.205</gml:upperCorner>" + '\n' + "</gml:Envelope>" + '\n';
DocumentComparator comparator = new DocumentComparator(expResult, result) {
@Override
protected strictfp void compareNames(Node expected, Node actual) {
final String[] exArray = expected.getNodeName().split(":");
final String[] acArray = actual.getNodeName().split(":");
assertEquals(exArray.length, acArray.length);
assertEquals(exArray[exArray.length - 1], acArray[acArray.length - 1]);
}
};
comparator.ignoredAttributes.add("http://www.w3.org/2000/xmlns:*");
comparator.compare();
Duration d1 = javax.xml.datatype.DatatypeFactory.newInstance().newDuration("P2D");
TimePeriodType tp = new TimePeriodType(d1);
marshaller.marshal(FACTORY.createTimePeriod(tp), sw);
TimePositionType tpos = new TimePositionType("2002-08-15");
tp = new TimePeriodType(tpos);
marshaller.marshal(FACTORY.createTimePeriod(tp), sw);
// System.out.println(sw.toString());
LineStringSegmentType ls = new LineStringSegmentType();
DirectPositionListType posList = new DirectPositionListType();
posList.setValue(Arrays.asList(1.0, 1.1, 1.2));
ls.setPosList(posList);
sw = new StringWriter();
marshaller.marshal(FACTORY.createLineStringSegment(ls), sw);
result = sw.toString();
// we remove the first line
result = result.substring(result.indexOf("?>") + 2).trim();
expResult = "<gml:LineStringSegment xmlns:gml=\"http://www.opengis.net/gml/3.2\">" + '\n' + " <gml:posList>1.0 1.1 1.2</gml:posList>" + '\n' + "</gml:LineStringSegment>" + '\n';
comparator = new DocumentComparator(expResult, result) {
@Override
protected strictfp void compareNames(Node expected, Node actual) {
final String[] exArray = expected.getNodeName().split(":");
final String[] acArray = actual.getNodeName().split(":");
assertEquals(exArray.length, acArray.length);
assertEquals(exArray[exArray.length - 1], acArray[acArray.length - 1]);
}
};
comparator.ignoredAttributes.add("http://www.w3.org/2000/xmlns:*");
comparator.compare();
ls = new LineStringSegmentType();
DirectPositionType pos1 = new DirectPositionType(Arrays.asList(1.1, 1.2));
DirectPositionType pos2 = new DirectPositionType(Arrays.asList(2.3, 48.1));
ls.getPos().add(pos1);
ls.getPos().add(pos2);
sw = new StringWriter();
marshaller.marshal(FACTORY.createLineStringSegment(ls), sw);
result = sw.toString();
// we remove the first line
result = result.substring(result.indexOf("?>") + 2).trim();
expResult = "<gml:LineStringSegment xmlns:gml=\"http://www.opengis.net/gml/3.2\">" + '\n' + " <gml:pos>1.1 1.2</gml:pos>" + '\n' + " <gml:pos>2.3 48.1</gml:pos>" + '\n' + "</gml:LineStringSegment>" + '\n';
comparator = new DocumentComparator(expResult, result) {
@Override
protected strictfp void compareNames(Node expected, Node actual) {
final String[] exArray = expected.getNodeName().split(":");
final String[] acArray = actual.getNodeName().split(":");
assertEquals(exArray.length, acArray.length);
assertEquals(exArray[exArray.length - 1], acArray[acArray.length - 1]);
}
};
comparator.ignoredAttributes.add("http://www.w3.org/2000/xmlns:*");
comparator.compare();
}
Aggregations