org.geojson.Point Java Examples

The following examples show how to use org.geojson.Point. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ResultTypesTests.java    From FROST-Server with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static void createEntities() throws ServiceFailureException, URISyntaxException {
    Thing thing = new Thing("Thing 1", "The first thing.");
    THINGS.add(thing);
    Location location = new Location("Location 1.0", "Location of Thing 1.", "application/vnd.geo+json", new Point(8, 51));
    thing.getLocations().add(location);
    service.create(thing);

    Sensor sensor = new Sensor("Sensor 1", "The first sensor.", "text", "Some metadata.");
    ObservedProperty obsProp = new ObservedProperty("Temperature", new URI("http://ucom.org/temperature"), "The temperature of the thing.");
    Datastream datastream = new Datastream("Datastream 1", "The temperature of thing 1, sensor 1.", "someType", new UnitOfMeasurement("degree celcius", "°C", "ucum:T"));
    datastream.setThing(thing);
    datastream.setSensor(sensor);
    datastream.setObservedProperty(obsProp);
    service.create(datastream);
    DATASTREAMS.add(datastream);
}
 
Example #2
Source File: GeoTests.java    From FROST-Server with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static void createLocation0() throws ServiceFailureException {
    // Locations 0
    Point gjo = new Point(8, 51);
    Location location = new Location("Location 1.0", "First Location of Thing 1.", "application/vnd.geo+json", gjo);
    location.getThings().add(THINGS.get(0));
    service.create(location);
    LOCATIONS.add(location);

    FeatureOfInterest featureOfInterest = new FeatureOfInterest("FoI 0", "This should be FoI #0.", "application/geo+json", gjo);
    service.create(featureOfInterest);
    FEATURESOFINTEREST.add(featureOfInterest);

    Observation o = new Observation(1, DATASTREAMS.get(0));
    o.setFeatureOfInterest(featureOfInterest);
    o.setPhenomenonTimeFrom(ZonedDateTime.parse("2016-01-01T01:01:01.000Z"));
    o.setValidTime(Interval.of(Instant.parse("2016-01-01T01:01:01.000Z"), Instant.parse("2016-01-01T23:59:59.999Z")));
    service.create(o);
    OBSERVATIONS.add(o);
}
 
Example #3
Source File: GeoTests.java    From FROST-Server with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static void createLocation1() throws ServiceFailureException {
    // Locations 1
    Point gjo = new Point(8, 52);
    Location location = new Location("Location 1.1", "Second Location of Thing 1.", "application/vnd.geo+json", gjo);
    location.getThings().add(THINGS.get(0));
    service.create(location);
    LOCATIONS.add(location);

    FeatureOfInterest featureOfInterest = new FeatureOfInterest("FoI 1", "This should be FoI #1.", "application/geo+json", gjo);
    service.create(featureOfInterest);
    FEATURESOFINTEREST.add(featureOfInterest);

    Observation o = new Observation(2, DATASTREAMS.get(0));
    o.setFeatureOfInterest(featureOfInterest);
    o.setPhenomenonTimeFrom(ZonedDateTime.parse("2016-01-02T01:01:01.000Z"));
    o.setValidTime(Interval.of(Instant.parse("2016-01-02T01:01:01.000Z"), Instant.parse("2016-01-02T23:59:59.999Z")));
    service.create(o);
    OBSERVATIONS.add(o);
}
 
Example #4
Source File: GeoTests.java    From FROST-Server with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static void createLocation2() throws ServiceFailureException {
    // Locations 2
    Point gjo = new Point(8, 53);
    Location location = new Location("Location 2", "Location of Thing 2.", "application/vnd.geo+json", gjo);
    location.getThings().add(THINGS.get(1));
    service.create(location);
    LOCATIONS.add(location);

    FeatureOfInterest featureOfInterest = new FeatureOfInterest("FoI 2", "This should be FoI #2.", "application/geo+json", gjo);
    service.create(featureOfInterest);
    FEATURESOFINTEREST.add(featureOfInterest);

    Observation o = new Observation(3, DATASTREAMS.get(1));
    o.setFeatureOfInterest(featureOfInterest);
    o.setPhenomenonTimeFrom(ZonedDateTime.parse("2016-01-03T01:01:01.000Z"));
    o.setValidTime(Interval.of(Instant.parse("2016-01-03T01:01:01.000Z"), Instant.parse("2016-01-03T23:59:59.999Z")));
    service.create(o);
    OBSERVATIONS.add(o);
}
 
Example #5
Source File: GeoTests.java    From FROST-Server with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static void createLocation3() throws ServiceFailureException {
    // Locations 3
    Point gjo = new Point(8, 54);
    Location location = new Location("Location 3", "Location of Thing 3.", "application/vnd.geo+json", gjo);
    location.getThings().add(THINGS.get(2));
    service.create(location);
    LOCATIONS.add(location);

    FeatureOfInterest featureOfInterest = new FeatureOfInterest("FoI 3", "This should be FoI #3.", "application/geo+json", gjo);
    service.create(featureOfInterest);
    FEATURESOFINTEREST.add(featureOfInterest);

    Observation o = new Observation(4, DATASTREAMS.get(2));
    o.setFeatureOfInterest(featureOfInterest);
    o.setPhenomenonTimeFrom(ZonedDateTime.parse("2016-01-04T01:01:01.000Z"));
    o.setValidTime(Interval.of(Instant.parse("2016-01-04T01:01:01.000Z"), Instant.parse("2016-01-04T23:59:59.999Z")));
    service.create(o);
    OBSERVATIONS.add(o);
}
 
Example #6
Source File: GeoHelper.java    From FROST-Server with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static Point parsePoint(String value) {
    Matcher matcher = GeoHelper.WKT_POINT_PATTERN.matcher(value.trim());
    if (matcher.matches()) {
        String[] coordinates = matcher.group(1).split(" ");
        if (coordinates.length < 2 || coordinates.length > 3) {
            throw new IllegalArgumentException("only 2d or 3d points are supported");
        }
        if (coordinates.length == 2) {
            return new Point(Double.parseDouble(coordinates[0]), Double.parseDouble(coordinates[1]));
        } else {
            return new Point(Double.parseDouble(coordinates[0]), Double.parseDouble(coordinates[1]), Double.parseDouble(coordinates[2]));
        }
    } else {
        throw new IllegalArgumentException("'" + value + DOES_NOT_MATCH_PATTERN + GeoHelper.WKT_POINT_PATTERN.pattern() + "'");
    }
}
 
Example #7
Source File: AdditionalTests.java    From FROST-Server with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Check the creation of a FoI on Observation creation, for Things that have
 * multiple Locations, only one of which is a geoJson location.
 *
 * @throws ServiceFailureException If the service doesn't respond.
 */
@Test
public void testMultipleLocations() throws ServiceFailureException {
    LOGGER.info("  testMultipleLocations");
    EntityUtils.deleteAll(service);

    Thing thing = new Thing("Thing 1", "The first thing.");

    Location location1 = new Location("Location 1.0, Address", "The address of Thing 1.", "text/plain", "");
    thing.getLocations().add(location1);
    Location location2 = new Location("Location 1.0", "Location of Thing 1.", "application/geo+json", new Point(8, 51));
    thing.getLocations().add(location2);
    Location location3 = new Location("Location 1.0, Directions", "How to find Thing 1 in human language.", "text/plain", "");
    thing.getLocations().add(location3);

    service.create(thing);
    THINGS.add(thing);

    Sensor sensor = new Sensor("Sensor 1", "The first sensor.", "text", "Some metadata.");
    ObservedProperty obsProp = new ObservedProperty("Temperature", "http://ucom.org/temperature", "The temperature of the thing.");
    Datastream datastream = new Datastream("Datastream 1", "The temperature of thing 1, sensor 1.", "someType", new UnitOfMeasurement("degree celcius", "°C", "ucum:T"));
    datastream.setSensor(sensor);
    datastream.setObservedProperty(obsProp);
    datastream.setThing(thing);

    service.create(datastream);
    DATASTREAMS.add(datastream);

    ObservationDao doa = service.observations();
    Observation observation = new Observation(1.0, DATASTREAMS.get(0));
    doa.create(observation);
    OBSERVATIONS.add(observation);

    Observation found;
    found = doa.find(observation.getId());
    FeatureOfInterest featureOfInterest = found.getFeatureOfInterest();

    Assert.assertNotNull("A FeatureOfInterest should have been generated, but got NULL.", featureOfInterest);
}
 
Example #8
Source File: CrsTest.java    From geojson-jackson with Apache License 2.0 5 votes vote down vote up
@Test
public void itShouldSerializeCrsWithLink() throws Exception {
	Point point = new Point();
	Crs crs = new Crs();
	crs.setType(CrsType.link);
	point.setCrs(crs);
	String value = mapper.writeValueAsString(point);
	assertEquals("{\"type\":\"Point\",\"crs\":{\"type\":\"link\",\"properties\":{}}}", value);
}
 
Example #9
Source File: PointTest.java    From geojson-jackson with Apache License 2.0 5 votes vote down vote up
@Test
public void itShouldDeserializeAPointWithAdditionalAttributes() throws IOException {
	GeoJsonObject value = mapper.readValue("{\"type\":\"Point\",\"coordinates\":[100.0,5.0,123,456,789.2]}",
			GeoJsonObject.class);
	Point point = (Point)value;
	assertLngLatAlt(100, 5, 123, new double[] {456d, 789.2}, point.getCoordinates());
}
 
Example #10
Source File: PointTest.java    From geojson-jackson with Apache License 2.0 5 votes vote down vote up
@Test
public void itShouldDeserializeAPointWithAltitude() throws Exception {
	GeoJsonObject value = mapper.readValue("{\"type\":\"Point\",\"coordinates\":[100.0,5.0,123]}",
			GeoJsonObject.class);
	Point point = (Point)value;
	assertLngLatAlt(100, 5, 123, point.getCoordinates());
}
 
Example #11
Source File: PointTest.java    From geojson-jackson with Apache License 2.0 5 votes vote down vote up
@Test
public void itShouldDeserializeAPoint() throws Exception {
	GeoJsonObject value = mapper
			.readValue("{\"type\":\"Point\",\"coordinates\":[100.0,5.0]}", GeoJsonObject.class);
	assertNotNull(value);
	assertTrue(value instanceof Point);
	Point point = (Point)value;
	assertLngLatAlt(100, 5, Double.NaN, point.getCoordinates());
}
 
Example #12
Source File: TestHelper.java    From FROST-Server with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static <T extends Number> Point getPoint(T... values) {
    if (values == null || values.length < 2 || values.length > 3) {
        throw new IllegalArgumentException("values must have a length of 2 or 3.");
    }
    if (values.length == 2) {
        return new Point(values[0].doubleValue(), values[1].doubleValue());
    }
    return new Point(values[0].doubleValue(), values[1].doubleValue(), values[2].doubleValue());
}
 
Example #13
Source File: GeoHelper.java    From FROST-Server with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static <T extends Number> Point getPoint(T... values) {
    if (values == null || values.length < 2 || values.length > 3) {
        throw new IllegalArgumentException("values must have a length of 2 or 3.");
    }
    if (values.length == 2) {
        return new Point(values[0].doubleValue(), values[1].doubleValue());
    }
    return new Point(values[0].doubleValue(), values[1].doubleValue(), values[2].doubleValue());
}
 
Example #14
Source File: PointConstant.java    From FROST-Server with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected Point parse(String value) {
    return GeoHelper.parsePoint(value);
}
 
Example #15
Source File: PointConstant.java    From FROST-Server with GNU Lesser General Public License v3.0 4 votes vote down vote up
public PointConstant(Point value) {
    super(value);
}
 
Example #16
Source File: DateTimeTests.java    From FROST-Server with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static void createEntities() throws ServiceFailureException, URISyntaxException {
    Thing thing = new Thing("Thing 1", "The first thing.");
    THINGS.add(thing);
    Location location = new Location("Location 1.0", "Location of Thing 1.", "application/vnd.geo+json", new Point(8, 51));
    thing.getLocations().add(location);
    service.create(thing);

    Sensor sensor = new Sensor("Sensor 1", "The first sensor.", "text", "Some metadata.");
    ObservedProperty obsProp = new ObservedProperty("Temperature", new URI("http://ucom.org/temperature"), "The temperature of the thing.");
    Datastream datastream = new Datastream("Datastream 1", "The temperature of thing 1, sensor 1.", "someType", new UnitOfMeasurement("degree celcius", "°C", "ucum:T"));
    datastream.setThing(thing);
    datastream.setSensor(sensor);
    datastream.setObservedProperty(obsProp);
    service.create(datastream);
    DATASTREAMS.add(datastream);

    createObservation(0, datastream, T600, T600, null); // 0
    createObservation(1, datastream, T659, T659, null); // 1
    createObservation(2, datastream, T700, T700, null); // 2
    createObservation(3, datastream, T701, T701, null); // 3
    createObservation(4, datastream, T759, T759, null); // 4
    createObservation(5, datastream, T800, T800, null); // 5
    createObservation(6, datastream, T801, T801, null); // 6
    createObservation(7, datastream, T900, T900, null); // 7

    createObservation(8, datastream, I600_659, null, I600_659); // 8
    createObservation(9, datastream, I600_700, null, I600_700); // 9
    createObservation(10, datastream, I600_701, null, I600_701); // 10
    createObservation(11, datastream, I700_800, null, I700_800); // 11
    createObservation(12, datastream, I701_759, null, I701_759); // 12
    createObservation(13, datastream, I759_900, null, I759_900); // 13
    createObservation(14, datastream, I800_900, null, I800_900); // 14
    createObservation(15, datastream, I801_900, null, I801_900); // 15

    createObservation(16, datastream, I659_801, null, I659_801); // 16
    createObservation(17, datastream, I700_759, null, I700_759); // 17
    createObservation(18, datastream, I700_801, null, I700_801); // 18
    createObservation(19, datastream, I659_800, null, I659_800); // 19
    createObservation(20, datastream, I701_800, null, I701_800); // 20

    createObservation(21, datastream, T2015, T2015, null); // 21
    createObservation(22, datastream, T2017, T2017, null); // 22
    createObservation(23, datastream, I2015, T2015, I2015); // 23
    createObservation(24, datastream, I2017, T2017.plus(1, ChronoUnit.HOURS), I2017); // 24

    // A second Datastream, with no observations.
    Datastream datastream2 = new Datastream("Datastream 2", "The second temperature of thing 1, sensor 1.", "someType", new UnitOfMeasurement("degree celcius", "°C", "ucum:T"));
    datastream2.setThing(thing);
    datastream2.setSensor(sensor);
    datastream2.setObservedProperty(obsProp);
    service.create(datastream2);
    DATASTREAMS.add(datastream2);
}
 
Example #17
Source File: MultiDatastreamTests.java    From FROST-Server with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Creates some basic non-MultiDatastream entities.
 *
 * @throws ServiceFailureException
 * @throws URISyntaxException
 */
private static void createEntities() throws ServiceFailureException, URISyntaxException {
    Location location = new Location("Location 1.0", "Location of Thing 1.", "application/vnd.geo+json", new Point(8, 51));
    service.create(location);
    LOCATIONS.add(location);

    Thing thing = new Thing("Thing 1", "The first thing.");
    thing.getLocations().add(location.withOnlyId());
    service.create(thing);
    THINGS.add(thing);

    thing = new Thing("Thing 2", "The second thing.");
    thing.getLocations().add(location.withOnlyId());
    service.create(thing);
    THINGS.add(thing);

    Sensor sensor = new Sensor("Sensor 1", "The first sensor.", "text", "Some metadata.");
    service.create(sensor);
    SENSORS.add(sensor);

    sensor = new Sensor("Sensor 2", "The second sensor.", "text", "Some metadata.");
    service.create(sensor);
    SENSORS.add(sensor);

    ObservedProperty obsProp = new ObservedProperty("ObservedProperty 1", new URI("http://ucom.org/temperature"), "The temperature of the thing.");
    service.create(obsProp);
    OBSERVED_PROPS.add(obsProp);

    obsProp = new ObservedProperty("ObservedProperty 2", new URI("http://ucom.org/humidity"), "The humidity of the thing.");
    service.create(obsProp);
    OBSERVED_PROPS.add(obsProp);

    Datastream datastream = new Datastream("Datastream 1", "The temperature of thing 1, sensor 1.", "someType", new UnitOfMeasurement("degree celcius", "°C", "ucum:T"));
    DATASTREAMS.add(datastream);
    datastream.setThing(THINGS.get(0).withOnlyId());
    datastream.setSensor(SENSORS.get(0).withOnlyId());
    datastream.setObservedProperty(OBSERVED_PROPS.get(0).withOnlyId());
    service.create(datastream);

    datastream = new Datastream("Datastream 2", "The temperature of thing 2, sensor 2.", "someType", new UnitOfMeasurement("degree celcius", "°C", "ucum:T"));
    DATASTREAMS.add(datastream);
    datastream.setThing(THINGS.get(1).withOnlyId());
    datastream.setSensor(SENSORS.get(1).withOnlyId());
    datastream.setObservedProperty(OBSERVED_PROPS.get(0).withOnlyId());
    service.create(datastream);

    createObservation(DATASTREAMS.get(0).withOnlyId(), -1);
    createObservation(DATASTREAMS.get(1).withOnlyId(), 0);
}
 
Example #18
Source File: PointTest.java    From geojson-jackson with Apache License 2.0 4 votes vote down vote up
@Test
public void itShouldSerializeAPoint() throws Exception {
	Point point = new Point(100, 0);
	assertEquals("{\"type\":\"Point\",\"coordinates\":[100.0,0.0]}",
			mapper.writeValueAsString(point));
}
 
Example #19
Source File: JsonPatchTests.java    From FROST-Server with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static void createEntities() throws ServiceFailureException, URISyntaxException {
    {
        Thing thing = new Thing("Thing 1", "The first thing.");
        service.create(thing);
        THINGS.add(thing);
    }
    {
        Location location = new Location("Location Des Dings von ILT", "First Location of Thing 1.", "application/vnd.geo+json", new Point(8, 49));
        location.getThings().add(THINGS.get(0));
        service.create(location);
        LOCATIONS.add(location);
    }
    {
        Sensor sensor1 = new Sensor("Sensor 1", "The first sensor.", "text", "Some metadata.");
        service.create(sensor1);
        SENSORS.add(sensor1);
    }
    {
        Sensor sensor2 = new Sensor("Sensor 2", "The second sensor", "text", "Some metadata.");
        service.create(sensor2);
        SENSORS.add(sensor2);
    }
    {
        ObservedProperty obsProp1 = new ObservedProperty("Temperature", new URI("http://ucom.org/temperature"), "The temperature of the thing.");
        service.create(obsProp1);
        OPROPS.add(obsProp1);
    }
    {
        ObservedProperty obsProp2 = new ObservedProperty("Humidity", new URI("http://ucom.org/humidity"), "The humidity of the thing.");
        service.create(obsProp2);
        OPROPS.add(obsProp2);
    }
    {
        Datastream datastream1 = new Datastream("Datastream Temp", "The temperature of thing 1, sensor 1.", "someType", new UnitOfMeasurement("degree celcius", "°C", "ucum:T"));
        datastream1.setThing(THINGS.get(0).withOnlyId());
        datastream1.setSensor(SENSORS.get(0).withOnlyId());
        datastream1.setObservedProperty(OPROPS.get(0).withOnlyId());
        service.create(datastream1);
        DATASTREAMS.add(datastream1);
    }
    {
        Datastream datastream2 = new Datastream("Datastream LF", "The humidity of thing 1, sensor 2.", "someType", new UnitOfMeasurement("relative humidity", "%", "ucum:Humidity"));
        datastream2.setThing(THINGS.get(0).withOnlyId());
        datastream2.setSensor(SENSORS.get(1).withOnlyId());
        datastream2.setObservedProperty(OPROPS.get(1).withOnlyId());
        service.create(datastream2);
        DATASTREAMS.add(datastream2);
    }
}
 
Example #20
Source File: AdditionalTests.java    From FROST-Server with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Test
public void testRecreateAutomaticFoi() throws ServiceFailureException {
    LOGGER.info("  testRecreateAutomaticFoi");
    EntityUtils.deleteAll(service);
    // Create two things

    Location location1 = new Location("LocationThing1", "Location of Thing 1", "application/geo+json", new Point(8, 50));
    service.create(location1);

    Thing thing1 = new Thing("Thing 1", "The first thing.");
    thing1.getLocations().add(location1.withOnlyId());
    service.create(thing1);

    Sensor sensor1 = new Sensor("Test Thermometre", "Test Sensor", "None", "-");
    service.create(sensor1);

    ObservedProperty obsProp1 = new ObservedProperty("Temperature", "http://example.org", "-");
    service.create(obsProp1);

    Datastream datastream1 = new Datastream("Ds 1, Thing 1", "The datastream of Thing 1", "http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement", new UnitOfMeasurement("Degrees Celcius", "°C", "http://qudt.org/vocab/unit#DegreeCelsius"));
    datastream1.setThing(thing1);
    datastream1.setSensor(sensor1);
    datastream1.setObservedProperty(obsProp1);
    service.create(datastream1);

    Observation obs1 = new Observation(1.0, datastream1);
    service.create(obs1);

    FeatureOfInterest foiGenerated1 = service.observations().find(obs1.getId()).getFeatureOfInterest();
    Assert.assertNotNull(foiGenerated1);

    service.delete(foiGenerated1);

    Observation obs2 = new Observation(1.0, datastream1);
    service.create(obs2);

    FeatureOfInterest foiGenerated2 = service.observations().find(obs2.getId()).getFeatureOfInterest();
    Assert.assertNotNull(foiGenerated2);

    Assert.assertNotEquals(foiGenerated1, foiGenerated2);
}
 
Example #21
Source File: PointTest.java    From geojson-jackson with Apache License 2.0 4 votes vote down vote up
@Test
public void itShouldSerializeAPointWithAltitude() throws Exception {
	Point point = new Point(100, 0, 256);
	assertEquals("{\"type\":\"Point\",\"coordinates\":[100.0,0.0,256.0]}",
			mapper.writeValueAsString(point));
}
 
Example #22
Source File: AdditionalTests.java    From FROST-Server with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Tests requests on paths like Things(x)/Datastreams(y)/Observations, where
 * Datastream(y) exists, but is not part of the, also existing, Things(x).
 *
 * @throws ServiceFailureException If the service doesn't respond.
 */
@Test
public void testPostInvalidPath() throws ServiceFailureException {
    LOGGER.info("  testPostInvalidPath");
    EntityUtils.deleteAll(service);
    // Create two things

    Location location1 = new Location("LocationThing1", "Location of Thing 1", "application/geo+json", new Point(8, 50));
    service.create(location1);

    Thing thing1 = new Thing("Thing 1", "The first thing.");
    thing1.getLocations().add(location1.withOnlyId());
    service.create(thing1);

    Thing thing2 = new Thing("Thing 2", "The second thing.");
    thing2.getLocations().add(location1.withOnlyId());
    service.create(thing2);

    Sensor sensor1 = new Sensor("Test Thermometre", "Test Sensor", "None", "-");
    service.create(sensor1);

    ObservedProperty obsProp1 = new ObservedProperty("Temperature", "http://example.org", "-");
    service.create(obsProp1);

    Datastream datastream1 = new Datastream("Ds 1, Thing 1", "The datastream of Thing 1", "http://www.opengis.net/def/observationType/OGC-OM/2.0/OM_Measurement", new UnitOfMeasurement("Degrees Celcius", "°C", "http://qudt.org/vocab/unit#DegreeCelsius"));
    datastream1.setThing(thing1);
    datastream1.setSensor(sensor1);
    datastream1.setObservedProperty(obsProp1);
    service.create(datastream1);

    Observation obs1 = new Observation(1.0, datastream1);
    service.create(obs1);

    testGet(thing1, datastream1, thing2);

    // PUT tests
    String urlObsGood = serverSettings.getServiceUrl(version)
            + "/Things(" + thing1.getId().getUrl() + ")"
            + "/Datastreams(" + datastream1.getId().getUrl() + ")"
            + "/Observations(" + obs1.getId().getUrl() + ")";
    String urlObsBad = serverSettings.getServiceUrl(version)
            + "/Things(" + thing2.getId().getUrl() + ")"
            + "/Datastreams(" + datastream1.getId().getUrl() + ")"
            + "/Observations(" + obs1.getId().getUrl() + ")";

    testPut(urlObsGood, urlObsBad);
    testPatch(urlObsGood, urlObsBad);
    testDelete(urlObsBad, urlObsGood);
}
 
Example #23
Source File: PointTest.java    From geojson-jackson with Apache License 2.0 4 votes vote down vote up
@Test
public void itShouldSerializeAPointWithAdditionalAttributes() throws JsonProcessingException {
	Point point = new Point(100, 0, 256, 345d, 678d);
	assertEquals("{\"type\":\"Point\",\"coordinates\":[100.0,0.0,256.0,345.0,678.0]}",
			mapper.writeValueAsString(point));
}
 
Example #24
Source File: PointTest.java    From geojson-jackson with Apache License 2.0 4 votes vote down vote up
@Test
public void itShouldSerializeAPointWithAdditionalAttributesAndNull() throws JsonProcessingException {
	Point point = new Point(100, 0, 256, 345d, 678d);
	assertEquals("{\"type\":\"Point\",\"coordinates\":[100.0,0.0,256.0,345.0,678.0]}",
			mapper.writeValueAsString(point));
}
 
Example #25
Source File: AdditionalTests.java    From FROST-Server with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Check if adding a new HistoricalLocation to a Thing changes the Location
 * of the Thing, if the new HistoricalLocation has a time that is later than
 * all others of the same Thing.
 *
 * Check if adding a new HistoricalLocation to a Thing does not change the
 * Location of the Thing, if the new HistoricalLocation has a time that is
 * not later than all others of the same Thing.
 *
 * @throws ServiceFailureException If the service doesn't respond.
 */
@Test
public void testHistoricalLocationThing() throws ServiceFailureException {
    LOGGER.info("  testHistoricalLocationThing");
    EntityUtils.deleteAll(service);

    // Create a thing
    Thing thing = new Thing("Thing 1", "The first thing.");
    service.create(thing);

    // Create three locations.
    Location location1 = new Location("Location 1.0", "Location Number 1.", "application/vnd.geo+json", new Point(8, 50));
    Location location2 = new Location("Location 2.0", "Location Number 2.", "application/vnd.geo+json", new Point(8, 51));
    Location location3 = new Location("Location 3.0", "Location Number 3.", "application/vnd.geo+json", new Point(8, 52));
    service.create(location1);
    service.create(location2);
    service.create(location3);

    // Give the Thing location 1
    thing.getLocations().add(location1.withOnlyId());
    service.update(thing);

    // Get the generated HistoricalLocation and change the time to a known value.
    List<HistoricalLocation> histLocations = thing.historicalLocations().query().list().toList();

    Assert.assertEquals("Incorrect number of HistoricalLocations for Thing.", 1, histLocations.size());

    HistoricalLocation histLocation = histLocations.get(0);
    histLocation.setTime(ZonedDateTime.parse("2016-01-01T06:00:00.000Z"));
    service.update(histLocation);

    // Now create a new HistoricalLocation for the Thing, with a later time.
    HistoricalLocation histLocation2 = HistoricalLocationBuilder.builder()
            .location(location2)
            .time(ZonedDateTime.parse("2016-01-01T07:00:00.000Z"))
            .thing(thing.withOnlyId())
            .build();
    service.create(histLocation2);

    // Check if the Location of the Thing is now Location 2.
    List<Location> thingLocations = thing.locations().query().list().toList();

    Assert.assertEquals("Incorrect number of Locations for Thing.", 1, thingLocations.size());

    Assert.assertEquals(location2, thingLocations.get(0));

    // Now create a new HistoricalLocation for the Thing, with an earlier time.
    HistoricalLocation histLocation3 = HistoricalLocationBuilder.builder()
            .location(location3)
            .time(ZonedDateTime.parse("2016-01-01T05:00:00.000Z"))
            .thing(thing.withOnlyId())
            .build();
    service.create(histLocation3);

    // Check if the Location of the Thing is still Location 2.
    thingLocations = thing.locations().query().list().toList();

    Assert.assertEquals("Incorrect number of Locations for Thing.", 1, thingLocations.size());

    Assert.assertEquals(location2, thingLocations.get(0));
}