summaryrefslogtreecommitdiff
path: root/qpid/java
diff options
context:
space:
mode:
authorKeith Wall <kwall@apache.org>2012-07-17 14:09:54 +0000
committerKeith Wall <kwall@apache.org>2012-07-17 14:09:54 +0000
commit0241c3b71364bcf0087bdbda1d2cd97805309fcd (patch)
treebb1df4e2770b5c5b55a62b0baad12b369e37f922 /qpid/java
parent0e22d4ab6aaa6d300eb150dde3a4702cace043c5 (diff)
downloadqpid-python-0241c3b71364bcf0087bdbda1d2cd97805309fcd.tar.gz
QPID-4103: [Java Performance Tests] modified test so that its success is no longer dependent on the order of the attributes in json2.js's JSON strings (this order varies between JDK 1.6 and 1.7, which caused a Jenkins test failure).
Applied patch from Philip Harvey <phil@philharveyonline.com>. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1362503 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
-rw-r--r--qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest-test-config.js (renamed from qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/test-config.js)0
-rw-r--r--qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java2
-rw-r--r--qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-expected-json.json94
-rw-r--r--qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js34
-rw-r--r--qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java50
5 files changed, 163 insertions, 17 deletions
diff --git a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/test-config.js b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest-test-config.js
index 07f8bf9d92..07f8bf9d92 100644
--- a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/test-config.js
+++ b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest-test-config.js
diff --git a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java
index 21981c93dd..e7b6cdd3c6 100644
--- a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java
+++ b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/ConfigReaderTest.java
@@ -111,7 +111,7 @@ public class ConfigReaderTest extends TestCase
public void testReadsJS() throws Exception
{
ConfigReader configReader = new ConfigReader();
- String path = getClass().getClassLoader().getResource("org/apache/qpid/disttest/controller/config/test-config.js").toURI().getPath();
+ String path = getClass().getResource("ConfigReaderTest-test-config.js").getPath();
_config = configReader.getConfigFromFile(path);
List<TestConfig> testConfigs = _config.getTestConfigs();
assertEquals("Unexpected number of tests", 2, testConfigs.size());
diff --git a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-expected-json.json b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-expected-json.json
new file mode 100644
index 0000000000..d56def5699
--- /dev/null
+++ b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-expected-json.json
@@ -0,0 +1,94 @@
+{
+ "_tests":[
+ {
+ "_queues":[
+ {
+ "_name":"Json-Queue-Name"
+ }
+ ],
+ "_clients":[
+ {
+ "_connections":[
+ {
+ "_name":"connection1",
+ "_sessions":[
+ {
+ "_acknowledgeMode":"0",
+ "_sessionName":"session1",
+ "_consumers":[
+
+ ]
+ }
+ ]
+ }
+ ],
+ "_name":"repeatingClient0"
+ },
+ {
+ "_connections":[
+ {
+ "_name":"connection1",
+ "_sessions":[
+ {
+ "_acknowledgeMode":"0",
+ "_sessionName":"session1",
+ "_consumers":[
+
+ ]
+ }
+ ]
+ }
+ ],
+ "_name":"repeatingClient1"
+ }
+ ],
+ "_iterationNumber":0,
+ "_name":"Test 1"
+ },
+ {
+ "_queues":[
+ {
+ "_name":"Json-Queue-Name"
+ }
+ ],
+ "_clients":[
+ {
+ "_connections":[
+ {
+ "_name":"connection1",
+ "_sessions":[
+ {
+ "_acknowledgeMode":"1",
+ "_sessionName":"session1",
+ "_consumers":[
+
+ ]
+ }
+ ]
+ }
+ ],
+ "_name":"repeatingClient0"
+ },
+ {
+ "_connections":[
+ {
+ "_name":"connection1",
+ "_sessions":[
+ {
+ "_acknowledgeMode":"1",
+ "_sessionName":"session1",
+ "_consumers":[
+
+ ]
+ }
+ ]
+ }
+ ],
+ "_name":"repeatingClient1"
+ }
+ ],
+ "_iterationNumber":1,
+ "_name":"Test 1"
+ }
+ ]
+} \ No newline at end of file
diff --git a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js
new file mode 100644
index 0000000000..07f8bf9d92
--- /dev/null
+++ b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js
@@ -0,0 +1,34 @@
+jsonObject = {
+ "_tests":
+ QPID.iterations( { "__ACK_MODE": [ 0, 1 ] },
+ {
+ // this is a comment - it wouldn't be allowed if this were pure JSON
+
+ "_name": "Test 1",
+ "_queues": [
+ {
+ "_name": "Json-Queue-Name"
+ }
+ ],
+
+ "_clients": QPID.times(2,
+ {
+ "_name": "repeatingClient__CLIENT_INDEX",
+ "_connections": [
+ {
+ "_name": "connection1",
+ "_sessions": [
+ {
+ "_sessionName": "session1",
+ "_acknowledgeMode": "__ACK_MODE",
+ "_consumers": []
+ }
+ ]
+ }
+ ]
+ },
+ "__CLIENT_INDEX"
+ )
+ })
+
+} \ No newline at end of file
diff --git a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java
index e797ce4c06..6d4b3f6290 100644
--- a/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java
+++ b/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java
@@ -20,29 +20,47 @@
*/
package org.apache.qpid.disttest.controller.config;
+import java.io.File;
+import java.util.TreeMap;
+
+import org.apache.qpid.util.FileUtils;
+
import junit.framework.TestCase;
+import com.google.gson.Gson;
+
public class JavaScriptConfigEvaluatorTest extends TestCase
{
public void testEvaluateJavaScript() throws Exception
{
- String path = getClass().getClassLoader().getResource("org/apache/qpid/disttest/controller/config/test-config.js")
- .toURI().getPath();
-
- String config = new JavaScriptConfigEvaluator().evaluateJavaScript(path);
-
- String expected = "{\"_tests\":[{\"_queues\":[{\"_name\":\"Json-Queue-Name\"}],\"_clients\":"
- + "[{\"_connections\":[{\"_name\":\"connection1\",\"_sessions\":[{\"_acknowledgeMode\":\"0\","
- + "\"_sessionName\":\"session1\",\"_consumers\":[]}]}],\"_name\":\"repeatingClient0\"},"
- + "{\"_connections\":[{\"_name\":\"connection1\",\"_sessions\":[{\"_acknowledgeMode\":\"0\","
- + "\"_sessionName\":\"session1\",\"_consumers\":[]}]}],\"_name\":\"repeatingClient1\"}]"
- + ",\"_iterationNumber\":0,\"_name\":\"Test 1\"},{\"_queues\":[{\"_name\":\"Json-Queue-Name\"}],"
- + "\"_clients\":[{\"_connections\":[{\"_name\":\"connection1\",\"_sessions\":"
- + "[{\"_acknowledgeMode\":\"1\",\"_sessionName\":\"session1\",\"_consumers\":[]}]}],"
- + "\"_name\":\"repeatingClient0\"},{\"_connections\":[{\"_name\":\"connection1\",\"_sessions\":"
- + "[{\"_acknowledgeMode\":\"1\",\"_sessionName\":\"session1\",\"_consumers\":[]}]}],"
- + "\"_name\":\"repeatingClient1\"}],\"_iterationNumber\":1,\"_name\":\"Test 1\"}]}";
+ String jsFilePath = getClass().getResource("JavaScriptConfigEvaluatorTest-test-config.js").getPath();
+
+ String rawConfig = new JavaScriptConfigEvaluator().evaluateJavaScript(jsFilePath);
+
+ String config = formatForComparison(rawConfig);
+ assertTrue(config.contains("\"_iterationNumber\":1"));
+
+ File expectedJsonFile = new File(getClass().getResource("JavaScriptConfigEvaluatorTest-expected-json.json").getPath());
+ String rawExpected = FileUtils.readFileAsString(expectedJsonFile);
+
+ String expected = formatForComparison(rawExpected);
assertEquals("Unexpected configuration", expected, config);
}
+
+ /**
+ * Does an unmarshall-then-marshall on the supplied JSON string so that
+ * we can compare the output when testing for equivalent JSON strings,
+ * ignoring ordering of attributes.
+ */
+ private String formatForComparison(String jsonStringIn)
+ {
+ Gson gson = new Gson();
+
+ @SuppressWarnings("rawtypes")
+ TreeMap configObj = gson.fromJson(jsonStringIn, TreeMap.class);
+
+ String jsonStringOut = gson.toJson(configObj);
+ return jsonStringOut;
+ }
}