Search in sources :

Example 11 with TimePeriodType

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);
}
Also used : TimeInstantType(org.geotoolkit.gml.xml.v311.TimeInstantType) TimePeriodType(org.geotoolkit.gml.xml.v311.TimePeriodType) StringReader(java.io.StringReader) JAXBElement(javax.xml.bind.JAXBElement) TimePositionType(org.geotoolkit.gml.xml.v311.TimePositionType)

Example 12 with TimePeriodType

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());
}
Also used : TimeInstantType(org.geotoolkit.gml.xml.v311.TimeInstantType) TimePeriodType(org.geotoolkit.gml.xml.v311.TimePeriodType) TimeInstantPropertyType(org.geotoolkit.gml.xml.v311.TimeInstantPropertyType) TimePositionType(org.geotoolkit.gml.xml.v311.TimePositionType)

Example 13 with TimePeriodType

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());
}
Also used : TimePeriodType(org.geotoolkit.gml.xml.v311.TimePeriodType)

Example 14 with TimePeriodType

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);
}
Also used : TimePeriodType(org.geotoolkit.gml.xml.v321.TimePeriodType) StringReader(java.io.StringReader) JAXBElement(javax.xml.bind.JAXBElement) TimePositionType(org.geotoolkit.gml.xml.v321.TimePositionType)

Example 15 with TimePeriodType

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();
}
Also used : EnvelopeType(org.geotoolkit.gml.xml.v321.EnvelopeType) LineStringSegmentType(org.geotoolkit.gml.xml.v321.LineStringSegmentType) DirectPositionType(org.geotoolkit.gml.xml.v321.DirectPositionType) Node(org.w3c.dom.Node) DirectPositionListType(org.geotoolkit.gml.xml.v321.DirectPositionListType) Duration(javax.xml.datatype.Duration) StringWriter(java.io.StringWriter) TimePeriodType(org.geotoolkit.gml.xml.v321.TimePeriodType) DocumentComparator(org.apache.sis.test.xml.DocumentComparator) TimePositionType(org.geotoolkit.gml.xml.v321.TimePositionType)

Aggregations

BinaryTemporalOpType (net.opengis.filter.v_2_0_0.BinaryTemporalOpType)15 FilterType (net.opengis.filter.v_2_0_0.FilterType)15 TimePeriodType (net.opengis.gml.v_3_2_1.TimePeriodType)14 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)12 Date (java.util.Date)12 TimePositionType (net.opengis.gml.v_3_2_1.TimePositionType)11 TimePeriodType (org.geotoolkit.gml.xml.v311.TimePeriodType)11 TimePositionType (org.geotoolkit.gml.xml.v311.TimePositionType)7 FilterCapabilities (net.opengis.filter.v_2_0_0.FilterCapabilities)6 JAXBElement (javax.xml.bind.JAXBElement)5 TimeInstantType (net.opengis.gml.v_3_2_1.TimeInstantType)5 TimePeriodType (org.geotoolkit.gml.xml.v321.TimePeriodType)5 StringWriter (java.io.StringWriter)4 TimePositionType (org.geotoolkit.gml.xml.v321.TimePositionType)4 DateTime (org.joda.time.DateTime)4 StringReader (java.io.StringReader)3 List (java.util.List)3 DirectPositionType (org.geotoolkit.gml.xml.v311.DirectPositionType)3 TimeInstantType (org.geotoolkit.gml.xml.v311.TimeInstantType)3