devicemap-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From re...@apache.org
Subject svn commit: r1693304 - /devicemap/trunk/clients/2.0/reference/src/Main.java
Date Wed, 29 Jul 2015 15:50:28 GMT
Author: rezan
Date: Wed Jul 29 15:50:27 2015
New Revision: 1693304

URL: http://svn.apache.org/r1693304
Log:
json test parsing

Modified:
    devicemap/trunk/clients/2.0/reference/src/Main.java

Modified: devicemap/trunk/clients/2.0/reference/src/Main.java
URL: http://svn.apache.org/viewvc/devicemap/trunk/clients/2.0/reference/src/Main.java?rev=1693304&r1=1693303&r2=1693304&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/Main.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/Main.java Wed Jul 29 15:50:27 2015
@@ -18,7 +18,9 @@
  */
 
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
+import org.codehaus.jackson.JsonNode;
 
 public class Main {
 
@@ -109,19 +111,49 @@ public class Main {
     }
   }
 
-  private static void test(DeviceMapClient client, JsonFile test) throws Exception {
-    if(!test.getType().equals("test")) {
-      throw new Exception("Unknown test type: " + test.getType());
+  private static void test(DeviceMapClient client, JsonFile tests) throws Exception {
+    if(!tests.getType().equals("test")) {
+      throw new Exception("Unknown test type: " + tests.getType());
     }
 
-    if(!test.getDomain().equals(client.getDomain())) {
-      throw new Exception("Domains do not match: " + client.getDomain() + " != " + test.getDomain());
+    if(!tests.getDomain().equals(client.getDomain())) {
+      throw new Exception("Domains do not match: " + client.getDomain() + " != " + tests.getDomain());
     }
 
-    if(!test.getDomainVersion().equals(client.getDomainVersion())) {
-      throw new Exception("DomainVersions do not match: " + client.getDomainVersion() + "
!= " + test.getDomainVersion());
+    if(!tests.getDomainVersion().equals(client.getDomainVersion())) {
+      throw new Exception("DomainVersions do not match: " + client.getDomainVersion() + "
!= " + tests.getDomainVersion());
     }
 
-    Main.log("  Loading test: " + test.getDomain() + ", version: " + test.getDomainVersion());
+    Main.log("  Loading test: " + tests.getDomain() + ", version: " + tests.getDomainVersion());
+
+    int testCount = 0;
+
+    if(DeviceMapClient.get(tests.getJsonNode(), "tests").isArray()) {
+        for(Iterator<JsonNode> i = tests.getJsonNode().get("tests").iterator(); i.hasNext();)
{
+          JsonNode test = i.next();
+
+          if(DeviceMapClient.get(test, "input").asText().isEmpty()) {
+            throw new Exception("Bad test input found, position: " + testCount);
+          }
+
+          String input = test.get("input").asText();
+          String result = null;
+
+          if(!DeviceMapClient.get(test, "resultPatternId").isNull()) {
+            result = DeviceMapClient.get(test, "resultPatternId").asText();
+          }
+
+          if(DeviceMapClient.get(test, "resultAttributes").isObject()) {
+            for(Iterator<String> j = test.get("resultAttributes").getFieldNames();
j.hasNext();) {
+              String key = j.next();
+              String value = test.get("resultAttributes").get(key).asText();
+            }
+          }
+
+          testCount++;
+        }
+
+        Main.log("  Found " + testCount + " test(s)");
+      }
   }
 }



Mime
View raw message