Search in sources :

Example 1 with ObservationDao

use of de.fraunhofer.iosb.ilt.sta.dao.ObservationDao in project FROST-Server by FraunhoferIOSB.

the class ResultTypesTests method testStringResult.

/**
 * Tests if String result values are stored and retrieved correctly.
 *
 * @throws ServiceFailureException if the service connection fails.
 */
@Test
public void testStringResult() throws ServiceFailureException {
    LOGGER.info("  testStringResult");
    ObservationDao doa = service.observations();
    Observation b1 = new Observation("fourty two", DATASTREAMS.get(0));
    doa.create(b1);
    OBSERVATIONS.add(b1);
    Observation found;
    found = doa.find(b1.getId());
    String message = "Expected result to be a String.";
    Assert.assertEquals(message, b1.getResult(), found.getResult());
}
Also used : ObservationDao(de.fraunhofer.iosb.ilt.sta.dao.ObservationDao) Observation(de.fraunhofer.iosb.ilt.sta.model.Observation) Test(org.junit.Test)

Example 2 with ObservationDao

use of de.fraunhofer.iosb.ilt.sta.dao.ObservationDao in project FROST-Server by FraunhoferIOSB.

the class ResultTypesTests method testResultQualityArray.

/**
 * Tests if resultQuality can have arbitrary json.
 *
 * @throws ServiceFailureException if the service connection fails.
 */
@Test
public void testResultQualityArray() throws ServiceFailureException, IOException {
    LOGGER.info("  testResultQualityArray");
    ObservationDao doa = service.observations();
    Observation o1 = new Observation(1.0, DATASTREAMS.get(0));
    ObjectMapper mapper = ObjectMapperFactory.get();
    String resultQualityString = "[\n" + "    {\n" + "        \"nameOfMeasure\": \"DQ_Status\",\n" + "        \"DQ_Result\": {\n" + "            \"code\": \"http://id.eaufrance.fr/nsa/446#2\",\n" + "            \"label\": \"Niveau 1\",\n" + "            \"comment\": \"Donnée contrôlée niveau 1 (données contrôlées)\"\n" + "        }\n" + "    },\n" + "    {\n" + "        \"nameOfMeasure\": \"DQ_Qualification\",\n" + "        \"DQ_Result\": {\n" + "            \"code\": \"http://id.eaufrance.fr/nsa/414#1\",\n" + "            \"label\": \"Correcte\",\n" + "            \"comment\": \"Correcte\"\n" + "        }\n" + "    }\n" + "\n" + "]";
    o1.setResultQuality(mapper.readTree(resultQualityString));
    doa.create(o1);
    OBSERVATIONS.add(o1);
    Observation found;
    found = doa.find(o1.getId());
    String message = "resultQuality not stored correctly.";
    Assert.assertEquals(message, o1.getResultQuality(), mapper.valueToTree(found.getResultQuality()));
}
Also used : ObservationDao(de.fraunhofer.iosb.ilt.sta.dao.ObservationDao) Observation(de.fraunhofer.iosb.ilt.sta.model.Observation) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 3 with ObservationDao

use of de.fraunhofer.iosb.ilt.sta.dao.ObservationDao in project FROST-Server by FraunhoferIOSB.

the class ResultTypesTests method testNumericResult.

/**
 * Tests if Numeric result values are stored and retrieved correctly.
 *
 * @throws ServiceFailureException if the service connection fails.
 */
@Test
public void testNumericResult() throws ServiceFailureException {
    LOGGER.info("  testNumericResult");
    ObservationDao doa = service.observations();
    Observation b1 = new Observation(1, DATASTREAMS.get(0));
    doa.create(b1);
    OBSERVATIONS.add(b1);
    Observation found;
    found = doa.find(b1.getId());
    String message = "Expected result to be a Number.";
    Assert.assertEquals(message, b1.getResult(), found.getResult());
    Observation b2 = new Observation(BigDecimal.valueOf(1.23), DATASTREAMS.get(0));
    doa.create(b2);
    OBSERVATIONS.add(b2);
    found = doa.find(b2.getId());
    message = "Expected result to be a Number.";
    Assert.assertEquals(message, b2.getResult(), found.getResult());
}
Also used : ObservationDao(de.fraunhofer.iosb.ilt.sta.dao.ObservationDao) Observation(de.fraunhofer.iosb.ilt.sta.model.Observation) Test(org.junit.Test)

Example 4 with ObservationDao

use of de.fraunhofer.iosb.ilt.sta.dao.ObservationDao in project FROST-Server by FraunhoferIOSB.

the class ResultTypesTests method testResultQualityObject.

/**
 * Tests if resultQuality can have arbitrary json.
 *
 * @throws ServiceFailureException if the service connection fails.
 */
@Test
public void testResultQualityObject() throws ServiceFailureException, IOException {
    LOGGER.info("  testResultQualityObject");
    ObservationDao doa = service.observations();
    Observation o1 = new Observation(1.0, DATASTREAMS.get(0));
    ObjectMapper mapper = ObjectMapperFactory.get();
    String resultQualityString = "" + "{\"DQ_Status\":{" + "  \"code\": \"http://id.eaufrance.fr/nsa/446#2\"," + "  \"label\": \"Niveau 1\",\n" + "  \"comment\": \"Donnée contrôlée niveau 1 (données contrôlées)\"" + "}}";
    o1.setResultQuality(mapper.readTree(resultQualityString));
    doa.create(o1);
    OBSERVATIONS.add(o1);
    Observation found;
    found = doa.find(o1.getId());
    String message = "resultQuality not stored correctly.";
    Assert.assertEquals(message, o1.getResultQuality(), mapper.valueToTree(found.getResultQuality()));
}
Also used : ObservationDao(de.fraunhofer.iosb.ilt.sta.dao.ObservationDao) Observation(de.fraunhofer.iosb.ilt.sta.model.Observation) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 5 with ObservationDao

use of de.fraunhofer.iosb.ilt.sta.dao.ObservationDao in project FROST-Server by FraunhoferIOSB.

the class ResultTypesTests method testObjectResult.

/**
 * Tests if Object result values are stored and retrieved correctly.
 *
 * @throws ServiceFailureException if the service connection fails.
 */
@Test
public void testObjectResult() throws ServiceFailureException {
    LOGGER.info("  testObjectResult");
    ObservationDao doa = service.observations();
    Map<String, Object> result = new HashMap<>();
    result.put("number", BigDecimal.valueOf(1.23));
    result.put("string", "One comma twentythree");
    result.put("boolean", Boolean.TRUE);
    Observation o1 = new Observation(result, DATASTREAMS.get(0));
    doa.create(o1);
    OBSERVATIONS.add(o1);
    Observation found;
    found = doa.find(o1.getId());
    String message = "Expected result Maps are not equal.";
    Assert.assertEquals(message, o1.getResult(), found.getResult());
}
Also used : HashMap(java.util.HashMap) ObservationDao(de.fraunhofer.iosb.ilt.sta.dao.ObservationDao) Observation(de.fraunhofer.iosb.ilt.sta.model.Observation) Test(org.junit.Test)

Aggregations

ObservationDao (de.fraunhofer.iosb.ilt.sta.dao.ObservationDao)21 Test (org.junit.Test)17 Observation (de.fraunhofer.iosb.ilt.sta.model.Observation)9 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Datastream (de.fraunhofer.iosb.ilt.sta.model.Datastream)1 FeatureOfInterest (de.fraunhofer.iosb.ilt.sta.model.FeatureOfInterest)1 HistoricalLocation (de.fraunhofer.iosb.ilt.sta.model.HistoricalLocation)1 Location (de.fraunhofer.iosb.ilt.sta.model.Location)1 ObservedProperty (de.fraunhofer.iosb.ilt.sta.model.ObservedProperty)1 Sensor (de.fraunhofer.iosb.ilt.sta.model.Sensor)1 Thing (de.fraunhofer.iosb.ilt.sta.model.Thing)1 UnitOfMeasurement (de.fraunhofer.iosb.ilt.sta.model.ext.UnitOfMeasurement)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Point (org.geojson.Point)1