Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package vital.management.job;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.Properties;
- import java.util.Random;
- import com.fasterxml.jackson.databind.JsonNode;
- import com.fasterxml.jackson.databind.ObjectMapper;
- import com.fasterxml.jackson.databind.node.ArrayNode;
- import com.fasterxml.jackson.databind.node.ObjectNode;
- import org.apache.commons.io.IOUtils;
- import static org.junit.Assert.*;
- /**
- * Created by jbjares on 17/06/2016.
- */
- public class AdminEventsServiceIntTest {
- private static final String FILE_NAME = "test-data/sensors-list_3cases.jsonld";
- @org.junit.Test
- public void setUp() throws Exception {
- //TODO Create the test simulation for the rest service as follow: http://vital-integration.atosresearch.eu:8280/hireplyppi/sensor/metadat ["vital:VitalSensor"]
- String data = getFileWithUtil(FILE_NAME);
- assertNotNull(data);
- ObjectMapper mapper = new ObjectMapper();
- assertNotNull(mapper);
- JsonNode actualObj = mapper.readTree(data);
- assertNotNull(actualObj);
- // JsonNode jsonNodeExpanded = expand(actualObj);
- // assertNotNull(jsonNodeExpanded);
- //String response = "[{\"@context\":\"http://vital-iot.eu/contexts/sensor.jsonld\",\"id\":\"http://vital-integration.atosresearch.eu:8280/hireplyppi/sensor/vital2-I_TrS_2\",\"type\":\"vital:VitalSensor\",\"name\":\"vital2-I_TrS_2\",\"description\":\"TEM Karanfilköy\",\"status\":\"vital:Running\",\"hasLastKnownLocation\":{\"type\":\"geo:Point\",\"geo:lat\":41.09301817,\"geo:long\":29.0270595},\"ssn:observes\":[{\"type\":\"vital:Speed\",\"id\":\"http://vital-integration.atosresearch.eu:8280/hireplyppi/sensor/vital2-I_TrS_2/Speed\"},{\"type\":\"vital:Color\",\"id\":\"http://vital-integration.atosresearch.eu:8280/hireplyppi/sensor/vital2-I_TrS_2/Color\"}]}]";
- ArrayNode sensorList = new ObjectMapper().createArrayNode();
- sensorList.add(actualObj);
- JsonNode locationJSON = null;
- JsonNode observerJSON = null;
- JsonNode sensorJSON = null;
- String name = "";
- String traffic = "Traffic";
- String status = "Running";
- String lat = "";
- String longitude = "";
- String speed = "";
- for (JsonNode outerSensor : sensorList) {
- for (JsonNode innerSensor : outerSensor) {
- sensorJSON = (ObjectNode) innerSensor;
- name = innerSensor.get("name").asText();
- if(!name.equals("vital2-I_TrS_"+getNumber())){
- continue;
- }
- locationJSON = innerSensor.get("hasLastKnownLocation");
- lat = locationJSON.get("geo:lat").asText();
- longitude = locationJSON.get("geo:long").asText();
- observerJSON = innerSensor.get("ssn:observes");
- String speedStr = getSpeed(name);
- System.out.println(speedStr);
- break;
- }
- break;
- }
- }
- private int getNumber() {
- Random rn = new Random();
- int number = 0;
- while(true){
- number = rn.nextInt(10) + 1;
- if(number==2 || number==3 || number==5 ){
- break;
- }
- }
- System.out.println(number);
- return number;
- }
- private String getSpeed(String name) throws IOException {
- Properties prop = new Properties();
- //TODO point to the current classpath
- InputStream input = new FileInputStream("C:\\Users\\JoaoBoscoJares\\workspace\\vital-istanbul-demo\\repo\\vital-istanbul-demo\\vital-istanbul-demo-ejb\\src\\test\\resources\\test-data\\speed-list_3cases_jsonld.properties");
- prop.load(input);
- String jsonSpeed = prop.getProperty(name);
- JsonNode actualObj = new ObjectMapper().readTree(jsonSpeed);
- assertNotNull(actualObj);
- System.out.println(actualObj);
- String speed = "";
- for (JsonNode speedResource : actualObj) {
- JsonNode speedResourceJSON = (ObjectNode) speedResource;
- System.out.println(speedResourceJSON);
- }
- return speed;
- }
- private String getFileWithUtil(String fileName) {
- String result = "";
- ClassLoader classLoader = getClass().getClassLoader();
- try {
- result = IOUtils.toString(classLoader.getResourceAsStream(fileName));
- } catch (IOException e) {
- throw new RuntimeException(e.getMessage(), e);
- }
- return result;
- }
- //
- // @org.junit.After
- // public void tearDown() throws Exception {
- //
- // }
- //
- // @org.junit.Test
- // public void testSyncEvents() throws Exception {
- //
- // }
- //
- // @org.junit.Test
- // public void testSyncIncidents() throws Exception {
- //
- // }
- //
- // @org.junit.Test
- // public void testSyncObservations() throws Exception {
- //
- // }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement