Author: rezan
Date: Wed Jul 29 16:15:18 2015
New Revision: 1693307
URL: http://svn.apache.org/r1693307
Log:
base code completed
Modified:
devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java
devicemap/trunk/clients/2.0/reference/src/Main.java
Modified: devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java
URL:
http://svn.apache.org/viewvc/devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java?rev=1693307&r1=1693306&r2=1693307&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/DeviceMapClient.java Wed Jul 29
16:15:18 2015
@@ -209,6 +209,12 @@ public class DeviceMapClient {
}
public String classify(String text) {
+ if(text == null) {
+ text = "";
+ }
+
+ Main.log(" Classify: '" + text + "'");
+
return "";
}
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=1693307&r1=1693306&r2=1693307&view=diff
==============================================================================
--- devicemap/trunk/clients/2.0/reference/src/Main.java (original)
+++ devicemap/trunk/clients/2.0/reference/src/Main.java Wed Jul 29 16:15:18 2015
@@ -37,6 +37,8 @@ public class Main {
String testString = null;
+ boolean failure = false;
+
for(int i = 0; i < args.length; i++) {
String option = args[i];
@@ -76,12 +78,16 @@ public class Main {
for(String test : tests) {
Main.log("Test file: '" + test + "'");
- test(client, new JsonFile(test));
+ failure |= test(client, new JsonFile(test));
}
if(testString != null) {
Main.log("Test string: '" + testString + "'");
}
+
+ if(failure) {
+ throw new Exception("One or more tests failed");
+ }
}
private static void printHelp() {
@@ -111,7 +117,7 @@ public class Main {
}
}
- private static void test(DeviceMapClient client, JsonFile tests) throws
Exception {
+ private static boolean test(DeviceMapClient client, JsonFile tests) throws
Exception {
if(!tests.getType().equals("test")) {
throw new Exception("Unknown test type: " + tests.getType());
}
@@ -127,6 +133,7 @@ public class Main {
Main.log(" Loading test: " + tests.getDomain() + ", version: " +
tests.getDomainVersion());
int testCount = 0;
+ int passCount = 0;
if(DeviceMapClient.get(tests.getJsonNode(), "tests").isArray()) {
for(Iterator<JsonNode> i =
tests.getJsonNode().get("tests").iterator(); i.hasNext();) {
@@ -137,10 +144,10 @@ public class Main {
}
String input = test.get("input").asText();
- String result = null;
+ String resultPatternId = null;
if(!DeviceMapClient.get(test, "resultPatternId").isNull()) {
- result = DeviceMapClient.get(test, "resultPatternId").asText();
+ resultPatternId = DeviceMapClient.get(test,
"resultPatternId").asText();
}
if(DeviceMapClient.get(test, "resultAttributes").isObject()) {
@@ -150,10 +157,18 @@ public class Main {
}
}
+ String result = client.classify(input);
+
+ if(1 == 1) {
+ passCount++;
+ }
+
testCount++;
}
-
- Main.log(" Found " + testCount + " test(s)");
}
+
+ System.out.println("Test passed " + passCount + " out of " + testCount +
". " + (testCount == passCount ? "PASS" : "FAIL"));
+
+ return testCount != passCount;
}
}