Advertisement
jbjares

testcase

Jun 17th, 2016
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.00 KB | None | 0 0
  1. package vital.management.job;
  2.  
  3. import java.io.FileInputStream;
  4. import java.io.FileNotFoundException;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.util.Properties;
  8. import java.util.Random;
  9.  
  10. import com.fasterxml.jackson.databind.JsonNode;
  11. import com.fasterxml.jackson.databind.ObjectMapper;
  12. import com.fasterxml.jackson.databind.node.ArrayNode;
  13. import com.fasterxml.jackson.databind.node.ObjectNode;
  14. import org.apache.commons.io.IOUtils;
  15.  
  16. import static org.junit.Assert.*;
  17.  
  18. /**
  19. * Created by jbjares on 17/06/2016.
  20. */
  21. public class AdminEventsServiceIntTest {
  22.  
  23.  
  24. private static final String FILE_NAME = "test-data/sensors-list_3cases.jsonld";
  25.  
  26.  
  27. @org.junit.Test
  28. public void setUp() throws Exception {
  29. //TODO Create the test simulation for the rest service as follow: http://vital-integration.atosresearch.eu:8280/hireplyppi/sensor/metadat ["vital:VitalSensor"]
  30. String data = getFileWithUtil(FILE_NAME);
  31. assertNotNull(data);
  32. ObjectMapper mapper = new ObjectMapper();
  33. assertNotNull(mapper);
  34. JsonNode actualObj = mapper.readTree(data);
  35. assertNotNull(actualObj);
  36. // JsonNode jsonNodeExpanded = expand(actualObj);
  37. // assertNotNull(jsonNodeExpanded);
  38.  
  39. //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\"}]}]";
  40. ArrayNode sensorList = new ObjectMapper().createArrayNode();
  41. sensorList.add(actualObj);
  42. JsonNode locationJSON = null;
  43. JsonNode observerJSON = null;
  44. JsonNode sensorJSON = null;
  45. String name = "";
  46. String traffic = "Traffic";
  47. String status = "Running";
  48. String lat = "";
  49. String longitude = "";
  50. String speed = "";
  51.  
  52. for (JsonNode outerSensor : sensorList) {
  53. for (JsonNode innerSensor : outerSensor) {
  54. sensorJSON = (ObjectNode) innerSensor;
  55. name = innerSensor.get("name").asText();
  56. if(!name.equals("vital2-I_TrS_"+getNumber())){
  57. continue;
  58. }
  59. locationJSON = innerSensor.get("hasLastKnownLocation");
  60. lat = locationJSON.get("geo:lat").asText();
  61. longitude = locationJSON.get("geo:long").asText();
  62. observerJSON = innerSensor.get("ssn:observes");
  63. String speedStr = getSpeed(name);
  64. System.out.println(speedStr);
  65. break;
  66. }
  67. break;
  68. }
  69. }
  70.  
  71. private int getNumber() {
  72. Random rn = new Random();
  73. int number = 0;
  74. while(true){
  75. number = rn.nextInt(10) + 1;
  76. if(number==2 || number==3 || number==5 ){
  77. break;
  78. }
  79. }
  80. System.out.println(number);
  81. return number;
  82. }
  83.  
  84. private String getSpeed(String name) throws IOException {
  85. Properties prop = new Properties();
  86. //TODO point to the current classpath
  87. 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");
  88. prop.load(input);
  89. String jsonSpeed = prop.getProperty(name);
  90.  
  91. JsonNode actualObj = new ObjectMapper().readTree(jsonSpeed);
  92. assertNotNull(actualObj);
  93. System.out.println(actualObj);
  94. String speed = "";
  95. for (JsonNode speedResource : actualObj) {
  96. JsonNode speedResourceJSON = (ObjectNode) speedResource;
  97. System.out.println(speedResourceJSON);
  98. }
  99.  
  100. return speed;
  101. }
  102.  
  103. private String getFileWithUtil(String fileName) {
  104.  
  105. String result = "";
  106.  
  107. ClassLoader classLoader = getClass().getClassLoader();
  108. try {
  109. result = IOUtils.toString(classLoader.getResourceAsStream(fileName));
  110. } catch (IOException e) {
  111. throw new RuntimeException(e.getMessage(), e);
  112. }
  113.  
  114. return result;
  115. }
  116. //
  117. // @org.junit.After
  118. // public void tearDown() throws Exception {
  119. //
  120. // }
  121. //
  122. // @org.junit.Test
  123. // public void testSyncEvents() throws Exception {
  124. //
  125. // }
  126. //
  127. // @org.junit.Test
  128. // public void testSyncIncidents() throws Exception {
  129. //
  130. // }
  131. //
  132. // @org.junit.Test
  133. // public void testSyncObservations() throws Exception {
  134. //
  135. // }
  136.  
  137.  
  138.  
  139.  
  140. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement