You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by kw...@apache.org on 2012/07/18 13:45:01 UTC
svn commit: r1362891 - in
/qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config:
JavaScriptConfigEvaluatorTest-expected-json.json
JavaScriptConfigEvaluatorTest-test-config.js
JavaScriptConfigEvaluatorTest.java
Author: kwall
Date: Wed Jul 18 11:45:01 2012
New Revision: 1362891
URL: http://svn.apache.org/viewvc?rev=1362891&view=rev
Log:
QPID-4103: Refactor test approach to avoid comparing JSON strings.
Applied patch from Philip Harvey <ph...@philharveyonline.com>.
Removed:
qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-expected-json.json
Modified:
qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js
qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java
Modified: qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js?rev=1362891&r1=1362890&r2=1362891&view=diff
==============================================================================
--- qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js (original)
+++ qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest-test-config.js Wed Jul 18 11:45:01 2012
@@ -1,33 +1,22 @@
jsonObject = {
- "_tests":
- QPID.iterations( { "__ACK_MODE": [ 0, 1 ] },
+ "_countries":
+ QPID.iterations( { "__ITERATING_VALUE": [ 0, 1 ] },
{
// this is a comment - it wouldn't be allowed if this were pure JSON
- "_name": "Test 1",
- "_queues": [
+ "_name": "Country",
+ "_regions": QPID.times(2,
{
- "_name": "Json-Queue-Name"
- }
- ],
-
- "_clients": QPID.times(2,
- {
- "_name": "repeatingClient__CLIENT_INDEX",
- "_connections": [
+ "_name": "repeatingRegion__REGION_INDEX",
+ "_towns": [
{
- "_name": "connection1",
- "_sessions": [
- {
- "_sessionName": "session1",
- "_acknowledgeMode": "__ACK_MODE",
- "_consumers": []
- }
- ]
+ "_name": "town1",
+ "_iteratingAttribute": "__ITERATING_VALUE",
+ "_consumers": []
}
]
},
- "__CLIENT_INDEX"
+ "__REGION_INDEX"
)
})
Modified: qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java?rev=1362891&r1=1362890&r2=1362891&view=diff
==============================================================================
--- qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java (original)
+++ qpid/trunk/qpid/java/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java Wed Jul 18 11:45:01 2012
@@ -20,10 +20,10 @@
*/
package org.apache.qpid.disttest.controller.config;
-import java.io.File;
-import java.util.TreeMap;
+import static org.apache.commons.beanutils.PropertyUtils.getProperty;
-import org.apache.qpid.util.FileUtils;
+import java.util.List;
+import java.util.TreeMap;
import junit.framework.TestCase;
@@ -37,30 +37,45 @@ public class JavaScriptConfigEvaluatorTe
String rawConfig = new JavaScriptConfigEvaluator().evaluateJavaScript(jsFilePath);
- String config = formatForComparison(rawConfig);
- assertTrue(config.contains("\"_iterationNumber\":1"));
+ Object configAsObject = getObject(rawConfig);
+
+ // Tests are produced by the QPID.iterations js function
+ assertEquals("Unexpected number of countries", 2, getPropertyAsList(configAsObject, "_countries").size());
+
+ Object country0 = getProperty(configAsObject, "_countries.[0]");
+ assertEquals("Unexpected country name", "Country", getProperty(country0, "_name"));
+ assertEquals("Unexpected country iteration number", 0, getPropertyAsInt(country0, "_iterationNumber"));
+
+ assertEquals("Unexpected number of regions", 2, getPropertyAsList(country0, "_regions").size());
+ // Region names are produced by the QPID.times js function
+ assertEquals("Unexpected region name", "repeatingRegion0", getProperty(country0, "_regions.[0]._name"));
+ assertEquals("Unexpected region name", "repeatingRegion1", getProperty(country0, "_regions.[1]._name"));
+ // Iterating attribute are produced by the QPID.iterations js function
+ assertEquals("Unexpected iterating attribute", "0", getProperty(country0, "_regions.[0]._towns.[0]._iteratingAttribute"));
+
+ Object country1 = getProperty(configAsObject, "_countries.[1]");
+ assertEquals("Unexpected country iteration number", 1, getPropertyAsInt(country1, "_iterationNumber"));
+ assertEquals("Unexpected iterating attribute", "1", getProperty(country1, "_regions.[0]._towns.[0]._iteratingAttribute"));
+ }
- File expectedJsonFile = new File(getClass().getResource("JavaScriptConfigEvaluatorTest-expected-json.json").toURI().getPath());
- String rawExpected = FileUtils.readFileAsString(expectedJsonFile);
+ private int getPropertyAsInt(Object configAsObject, String property) throws Exception
+ {
+ Number propertyValue = (Number) getProperty(configAsObject, property);
- String expected = formatForComparison(rawExpected);
+ return propertyValue.intValue();
+ }
- assertEquals("Unexpected configuration", expected, config);
+ private List<?> getPropertyAsList(Object configAsObject, String property)
+ throws Exception
+ {
+ return (List<?>)getProperty(configAsObject, property);
}
- /**
- * 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)
+ private Object getObject(String jsonStringIn)
{
Gson gson = new Gson();
-
@SuppressWarnings("rawtypes")
- TreeMap configObj = gson.fromJson(jsonStringIn, TreeMap.class);
-
- String jsonStringOut = gson.toJson(configObj);
- return jsonStringOut;
+ TreeMap object = gson.fromJson(jsonStringIn, TreeMap.class);
+ return object;
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org