Author: rgodfrey
Date: Tue Apr 28 17:17:51 2015
New Revision: 1676579
URL: http://svn.apache.org/r1676579
Log:
QPID-6515 : [Java Broker, Java Performance Tests] Eliminate dependencies that
require commons-logging (patch by Lorenz Quack)
Added:
qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/client/utils/BeanUtils.java
(with props)
Modified:
qpid/java/trunk/broker-plugins/management-jmx/pom.xml
qpid/java/trunk/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/MBeanTestUtils.java
qpid/java/trunk/perftests/pom.xml
qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/client/MessageProvider.java
qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/controller/ParticipatingClients.java
qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/controller/config/IterationValue.java
qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/message/ParticipantAttributeExtractor.java
qpid/java/trunk/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java
Modified: qpid/java/trunk/broker-plugins/management-jmx/pom.xml
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-jmx/pom.xml?rev=1676579&r1=1676578&r2=1676579&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-jmx/pom.xml (original)
+++ qpid/java/trunk/broker-plugins/management-jmx/pom.xml Tue Apr 28 17:17:51
2015
@@ -64,13 +64,6 @@
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>commons-beanutils</groupId>
- <artifactId>commons-beanutils-core</artifactId>
- <version>${commons-beanutils-version}</version>
- <scope>test</scope>
- </dependency>
-
</dependencies>
<build>
Modified:
qpid/java/trunk/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/MBeanTestUtils.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/MBeanTestUtils.java?rev=1676579&r1=1676578&r2=1676579&view=diff
==============================================================================
---
qpid/java/trunk/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/MBeanTestUtils.java
(original)
+++
qpid/java/trunk/broker-plugins/management-jmx/src/test/java/org/apache/qpid/server/jmx/mbeans/MBeanTestUtils.java
Tue Apr 28 17:17:51 2015
@@ -21,20 +21,56 @@ package org.apache.qpid.server.jmx.mbean
import junit.framework.TestCase;
-import org.apache.commons.beanutils.PropertyUtils;
import org.apache.qpid.server.jmx.DefaultManagedObject;
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.InvocationTargetException;
+
public class MBeanTestUtils
{
public static void assertMBeanAttribute(DefaultManagedObject
managedObject, String jmxAttributeName, Object expectedValue) throws Exception
{
- Object actualValue = PropertyUtils.getSimpleProperty(managedObject,
jmxAttributeName);
- TestCase.assertEquals("Attribute " + jmxAttributeName + " has
unexpected value", expectedValue, actualValue);
+ Object actualValue = getProperty(managedObject, jmxAttributeName);
+ TestCase.assertEquals("Attribute " + jmxAttributeName + " has
unexpected value", expectedValue, actualValue);
}
public static void setMBeanAttribute(DefaultManagedObject managedObject,
String jmxAttributeName, Object newValue) throws Exception
{
- PropertyUtils.setSimpleProperty(managedObject, jmxAttributeName,
newValue);
+ setProperty(managedObject, jmxAttributeName, newValue);
+ }
+
+ private static void setProperty(Object bean, String propertyName, Object
propertyValue) throws IllegalAccessException, InvocationTargetException,
IntrospectionException, NoSuchMethodException
+ {
+ PropertyDescriptor propertyDescriptor = getPropertyDescriptor(bean,
propertyName);
+ propertyDescriptor.getWriteMethod().invoke(bean, propertyValue);
+ }
+
+ private static Object getProperty(Object bean, String propertyName) throws
IntrospectionException, IllegalAccessException, InvocationTargetException,
NoSuchMethodException
+ {
+ PropertyDescriptor propertyDescriptor = getPropertyDescriptor(bean,
propertyName);
+ return propertyDescriptor.getReadMethod().invoke(bean);
}
+
+ private static PropertyDescriptor getPropertyDescriptor(Object bean,
String propertyName) throws IntrospectionException, NoSuchMethodException
+ {
+ for (PropertyDescriptor propertyDescriptor :
getPropertyDescriptors(bean))
+ {
+ if (propertyDescriptor.getName().equals(propertyName))
+ {
+ return propertyDescriptor;
+ }
+ }
+ throw new NoSuchMethodException(propertyName);
+ }
+
+ private static PropertyDescriptor[] getPropertyDescriptors(Object bean)
throws IntrospectionException
+ {
+ BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass());
+ return beanInfo.getPropertyDescriptors();
+ }
+
}
Modified: qpid/java/trunk/perftests/pom.xml
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/perftests/pom.xml?rev=1676579&r1=1676578&r2=1676579&view=diff
==============================================================================
--- qpid/java/trunk/perftests/pom.xml (original)
+++ qpid/java/trunk/perftests/pom.xml Tue Apr 28 17:17:51 2015
@@ -68,24 +68,18 @@
</dependency>
<dependency>
- <groupId>commons-collections</groupId>
- <artifactId>commons-collections</artifactId>
- <version>${commons-collections-version}</version>
- </dependency>
-
- <dependency>
- <groupId>commons-beanutils</groupId>
- <artifactId>commons-beanutils-core</artifactId>
- <version>${commons-beanutils-version}</version>
- </dependency>
-
- <dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>${gson-version}</version>
</dependency>
<dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>${guava-version}</version>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>${derby-version}</version>
Modified:
qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/client/MessageProvider.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/client/MessageProvider.java?rev=1676579&r1=1676578&r2=1676579&view=diff
==============================================================================
---
qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/client/MessageProvider.java
(original)
+++
qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/client/MessageProvider.java
Tue Apr 28 17:17:51 2015
@@ -18,6 +18,7 @@
*/
package org.apache.qpid.disttest.client;
+import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;
import java.util.Map.Entry;
@@ -32,10 +33,10 @@ import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;
-import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.qpid.disttest.DistributedTestException;
import org.apache.qpid.disttest.client.property.PropertyValue;
+import org.apache.qpid.disttest.client.utils.BeanUtils;
import org.apache.qpid.disttest.message.CreateProducerCommand;
public class MessageProvider
@@ -137,7 +138,7 @@ public class MessageProvider
{
BeanUtils.setProperty(message, propertyName, propertyValue);
}
- catch (IllegalAccessException e)
+ catch (IntrospectionException | NoSuchMethodException |
IllegalAccessException e)
{
throw new DistributedTestException("Unable to set property " +
propertyName + " :" + e.getMessage(), e);
}
Added:
qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/client/utils/BeanUtils.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/client/utils/BeanUtils.java?rev=1676579&view=auto
==============================================================================
---
qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/client/utils/BeanUtils.java
(added)
+++
qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/client/utils/BeanUtils.java
Tue Apr 28 17:17:51 2015
@@ -0,0 +1,138 @@
+package org.apache.qpid.disttest.client.utils;
+
+import java.beans.BeanInfo;
+import java.beans.IntrospectionException;
+import java.beans.Introspector;
+import java.beans.PropertyDescriptor;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+public class BeanUtils
+{
+ private static final Map<Class, Class> PRIMITIVE_TYPES =
Collections.synchronizedMap(new HashMap<Class, Class>());
+
+ static
+ {
+ PRIMITIVE_TYPES.put(Boolean.TYPE, Boolean.class);
+ PRIMITIVE_TYPES.put(Byte.TYPE, Byte.class);
+ PRIMITIVE_TYPES.put(Character.TYPE, Character.class);
+ PRIMITIVE_TYPES.put(Short.TYPE, Short.class);
+ PRIMITIVE_TYPES.put(Integer.TYPE, Integer.class);
+ PRIMITIVE_TYPES.put(Long.TYPE, Long.class);
+ PRIMITIVE_TYPES.put(Float.TYPE, Float.class);
+ PRIMITIVE_TYPES.put(Double.TYPE, Double.class);
+ }
+
+ public static void setProperty(Object bean, String propertyName, Object
propertyValue) throws IllegalAccessException, InvocationTargetException,
IntrospectionException, NoSuchMethodException
+ {
+ PropertyDescriptor propertyDescriptor = getPropertyDescriptor(bean,
propertyName);
+ Method writeMethod = propertyDescriptor.getWriteMethod();
+ Class expectedType = writeMethod.getParameterTypes()[0];
+ if (expectedType.isPrimitive())
+ {
+ expectedType = PRIMITIVE_TYPES.get(expectedType);
+ }
+ if (propertyValue != null &&
!expectedType.isAssignableFrom(propertyValue.getClass()))
+ {
+ propertyValue = convertPropertyValue(propertyValue, expectedType);
+ }
+ try
+ {
+ propertyDescriptor.getWriteMethod().invoke(bean, propertyValue);
+ }
+ catch (IllegalArgumentException e)
+ {
+ System.err.println("expectedType.getName(): " +
expectedType.getName());
+ System.err.println("propertyValue.getClass(): " + (propertyValue
== null ? "null" : propertyValue.getClass().getName()));
+
+ throw e;
+ }
+ }
+
+ private static Object convertPropertyValue(Object propertyValue, Class
expectedType) throws IllegalAccessException, InvocationTargetException
+ {
+ if (propertyValue.getClass() == String.class)
+ {
+ try
+ {
+ Constructor constructor =
expectedType.getConstructor(String.class);
+ propertyValue = constructor.newInstance(propertyValue);
+ }
+ catch (InstantiationException | NoSuchMethodException e)
+ {
+ // Ignore exceptions
+ }
+ }
+ else if (propertyValue instanceof Number &&
Number.class.isAssignableFrom(expectedType))
+ {
+ if (expectedType == Long.class)
+ {
+ propertyValue = ((Number)propertyValue).longValue();
+ }
+ else if (expectedType == Integer.class)
+ {
+ propertyValue = ((Number)propertyValue).intValue();
+ }
+ else if (expectedType == Short.class)
+ {
+ propertyValue = ((Number)propertyValue).shortValue();
+ }
+ else if (expectedType == Byte.class)
+ {
+ propertyValue = ((Number)propertyValue).byteValue();
+ }
+ else if (expectedType == Double.class)
+ {
+ propertyValue = ((Number)propertyValue).doubleValue();
+ }
+ else if (expectedType == Float.class)
+ {
+ propertyValue = ((Number)propertyValue).floatValue();
+ }
+ }
+ return propertyValue;
+ }
+
+ public static Object getProperty(Object bean, String propertyName) throws
IntrospectionException, IllegalAccessException, InvocationTargetException,
NoSuchMethodException
+ {
+ PropertyDescriptor propertyDescriptor = getPropertyDescriptor(bean,
propertyName);
+ return propertyDescriptor.getReadMethod().invoke(bean);
+ }
+
+ public static void copyProperties(Object bean, Map<String, String>
properties) throws IllegalAccessException, InvocationTargetException,
IntrospectionException
+ {
+ for (Map.Entry<String, String> entry : properties.entrySet())
+ {
+ try
+ {
+ setProperty(bean, entry.getKey(), entry.getValue());
+ }
+ catch (NoSuchMethodException e)
+ {
+ // Ignore
+ }
+ }
+ }
+
+ public static PropertyDescriptor getPropertyDescriptor(Object bean, String
propertyName) throws IntrospectionException, NoSuchMethodException
+ {
+ for (PropertyDescriptor propertyDescriptor :
getPropertyDescriptors(bean))
+ {
+ if (propertyDescriptor.getName().equals(propertyName))
+ {
+ return propertyDescriptor;
+ }
+ }
+ throw new NoSuchMethodException(propertyName);
+ }
+
+ public static PropertyDescriptor[] getPropertyDescriptors(Object bean)
throws IntrospectionException
+ {
+ BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClass());
+ return beanInfo.getPropertyDescriptors();
+ }
+}
Propchange:
qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/client/utils/BeanUtils.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/controller/ParticipatingClients.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/controller/ParticipatingClients.java?rev=1676579&r1=1676578&r2=1676579&view=diff
==============================================================================
---
qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/controller/ParticipatingClients.java
(original)
+++
qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/controller/ParticipatingClients.java
Tue Apr 28 17:17:51 2015
@@ -22,14 +22,14 @@ import java.util.Collection;
import java.util.List;
import java.util.TreeSet;
-import org.apache.commons.collections.BidiMap;
-import org.apache.commons.collections.bidimap.DualHashBidiMap;
+import com.google.common.collect.BiMap;
+import com.google.common.collect.HashBiMap;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
public class ParticipatingClients
{
- private final BidiMap _configuredToRegisteredNameMap;
+ private final BiMap<String, String> _configuredToRegisteredNameMap;
public ParticipatingClients(ClientRegistry clientRegistry, List<String>
configuredClientNamesForTest)
{
@@ -38,7 +38,7 @@ public class ParticipatingClients
public String getRegisteredNameFromConfiguredName(String
clientConfiguredName)
{
- String registeredClientName = (String)
_configuredToRegisteredNameMap.get(clientConfiguredName);
+ String registeredClientName =
_configuredToRegisteredNameMap.get(clientConfiguredName);
if (registeredClientName == null)
{
throw new IllegalArgumentException("Unrecognised client configured
name " + clientConfiguredName
@@ -49,7 +49,7 @@ public class ParticipatingClients
public String getConfiguredNameFromRegisteredName(String
registeredClientName)
{
- String clientConfiguredName = (String)
_configuredToRegisteredNameMap.getKey(registeredClientName);
+ String clientConfiguredName =
_configuredToRegisteredNameMap.inverse().get(registeredClientName);
if (clientConfiguredName == null)
{
throw new IllegalArgumentException("Unrecognised client registered
name " + registeredClientName
@@ -59,9 +59,9 @@ public class ParticipatingClients
return clientConfiguredName;
}
- private BidiMap mapConfiguredToRegisteredClientNames(List<String>
configuredClientNamesForTest, ClientRegistry clientRegistry)
+ private BiMap<String, String>
mapConfiguredToRegisteredClientNames(List<String> configuredClientNamesForTest,
ClientRegistry clientRegistry)
{
- BidiMap configuredToRegisteredNameMap = new DualHashBidiMap();
+ BiMap<String, String> configuredToRegisteredNameMap =
HashBiMap.create();
TreeSet<String> registeredClients = new
TreeSet<String>(clientRegistry.getClients());
for (String configuredClientName : configuredClientNamesForTest)
@@ -83,12 +83,19 @@ public class ParticipatingClients
return _configuredToRegisteredNameMap.values();
}
- @Override
+ /* @Override
public String toString()
{
return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
.append("configuredToRegisteredNameMap",
_configuredToRegisteredNameMap).toString();
}
+*/
-
+ @Override
+ public String toString()
+ {
+ return "ParticipatingClients{" +
+ "configuredToRegisteredNameMap=" +
_configuredToRegisteredNameMap +
+ '}';
+ }
}
Modified:
qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/controller/config/IterationValue.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/controller/config/IterationValue.java?rev=1676579&r1=1676578&r2=1676579&view=diff
==============================================================================
---
qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/controller/config/IterationValue.java
(original)
+++
qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/controller/config/IterationValue.java
Tue Apr 28 17:17:51 2015
@@ -18,14 +18,15 @@
*/
package org.apache.qpid.disttest.controller.config;
+import java.beans.IntrospectionException;
import java.lang.reflect.InvocationTargetException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
-import org.apache.commons.beanutils.BeanUtilsBean;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
+import org.apache.qpid.disttest.client.utils.BeanUtils;
import org.apache.qpid.disttest.message.Command;
public class IterationValue
@@ -52,13 +53,9 @@ public class IterationValue
try
{
Map<String, String> withoutUnderscoresToMatchCommandPropertyNames
= getIterationPropertyValuesWithoutUnderscores();
- BeanUtilsBean.getInstance().copyProperties(command,
withoutUnderscoresToMatchCommandPropertyNames);
+ BeanUtils.copyProperties(command,
withoutUnderscoresToMatchCommandPropertyNames);
}
- catch (IllegalAccessException e)
- {
- throw new RuntimeException("Couldn't copy properties from
iteration " + this + " to " + command, e);
- }
- catch (InvocationTargetException e)
+ catch (IntrospectionException | IllegalAccessException |
InvocationTargetException e)
{
throw new RuntimeException("Couldn't copy properties from
iteration " + this + " to " + command, e);
}
Modified:
qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/message/ParticipantAttributeExtractor.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/message/ParticipantAttributeExtractor.java?rev=1676579&r1=1676578&r2=1676579&view=diff
==============================================================================
---
qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/message/ParticipantAttributeExtractor.java
(original)
+++
qpid/java/trunk/perftests/src/main/java/org/apache/qpid/disttest/message/ParticipantAttributeExtractor.java
Tue Apr 28 17:17:51 2015
@@ -18,6 +18,9 @@
*/
package org.apache.qpid.disttest.message;
+import org.apache.qpid.disttest.client.utils.BeanUtils;
+
+import java.beans.IntrospectionException;
import java.beans.PropertyDescriptor;
import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
@@ -25,8 +28,6 @@ import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;
-import org.apache.commons.beanutils.PropertyUtils;
-
public class ParticipantAttributeExtractor
{
@@ -35,7 +36,15 @@ public class ParticipantAttributeExtract
Map<ParticipantAttribute, Object> attributes = new
HashMap<ParticipantAttribute, Object>();
- PropertyDescriptor[] descriptors =
PropertyUtils.getPropertyDescriptors(targetObject);
+ PropertyDescriptor[] descriptors;
+ try
+ {
+ descriptors = BeanUtils.getPropertyDescriptors(targetObject);
+ }
+ catch (IntrospectionException e)
+ {
+ throw new RuntimeException(e);
+ }
for (PropertyDescriptor propertyDescriptor : descriptors)
{
final Method readMethod = getPropertyReadMethod(targetObject,
propertyDescriptor);
@@ -70,17 +79,9 @@ public class ParticipantAttributeExtract
{
try
{
- return PropertyUtils.getProperty(targetObject, propertyName);
- }
- catch (IllegalAccessException e)
- {
- throw new RuntimeException("Couldn't get value of property " +
propertyName + " from " + targetObject, e);
- }
- catch (InvocationTargetException e)
- {
- throw new RuntimeException("Couldn't get value of property " +
propertyName + " from " + targetObject, e);
+ return BeanUtils.getProperty(targetObject, propertyName);
}
- catch (NoSuchMethodException e)
+ catch (IllegalAccessException | InvocationTargetException |
IntrospectionException | NoSuchMethodException e)
{
throw new RuntimeException("Couldn't get value of property " +
propertyName + " from " + targetObject, e);
}
Modified:
qpid/java/trunk/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java
URL:
http://svn.apache.org/viewvc/qpid/java/trunk/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java?rev=1676579&r1=1676578&r2=1676579&view=diff
==============================================================================
---
qpid/java/trunk/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java
(original)
+++
qpid/java/trunk/perftests/src/test/java/org/apache/qpid/disttest/controller/config/JavaScriptConfigEvaluatorTest.java
Tue Apr 28 17:17:51 2015
@@ -20,10 +20,9 @@
*/
package org.apache.qpid.disttest.controller.config;
-import static org.apache.commons.beanutils.PropertyUtils.getProperty;
-
import java.io.FileReader;
import java.util.List;
+import java.util.Map;
import java.util.TreeMap;
import org.apache.qpid.test.utils.QpidTestCase;
@@ -33,75 +32,60 @@ import com.google.gson.Gson;
public class JavaScriptConfigEvaluatorTest extends QpidTestCase
{
- public void testEvaluateJavaScript() throws Exception
+ private void performTest(Map configAsObject) throws Exception
{
- String jsFilePath = TestFileUtils.createTempFileFromResource(this,
"JavaScriptConfigEvaluatorTest-test-config.js").getAbsolutePath();
-
- String rawConfig = new
JavaScriptConfigEvaluator().evaluateJavaScript(jsFilePath);
-
- Object configAsObject = getObject(rawConfig);
-
// Tests are produced by the QPID.iterations js function
- assertEquals("Unexpected number of countries", 2,
getPropertyAsList(configAsObject, "_countries").size());
+ List<?> countries = getPropertyAsList(configAsObject, "_countries");
+ assertEquals("Unexpected number of countries", 2, 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"));
+ Map country0 = (Map) countries.get(0);
+ assertEquals("Unexpected country name", "Country",
country0.get("_name"));
+ assertEquals("Unexpected country iteration number", 0,
((Number)country0.get("_iterationNumber")).intValue());
- assertEquals("Unexpected number of regions", 2,
getPropertyAsList(country0, "_regions").size());
+ List<?> regions = getPropertyAsList(country0, "_regions");
+ assertEquals("Unexpected number of regions", 2, 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"));
+ Map region0 = (Map) regions.get(0);
+ assertEquals("Unexpected region name", "repeatingRegion0",
region0.get("_name"));
+ assertEquals("Unexpected region name", "repeatingRegion1",
((Map)regions.get(1)).get("_name"));
// Iterating attribute are produced by the QPID.iterations js function
- assertEquals("Unexpected iterating attribute", "0",
getProperty(country0, "_regions.[0]._towns.[0]._iteratingAttribute"));
+ assertEquals("Unexpected iterating attribute", "0",
((Map)((List)region0.get("_towns")).get(0)).get("_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"));
+ Map country1 = (Map) countries.get(1);
+ regions = getPropertyAsList(country1, "_regions");
+ region0 = (Map) regions.get(0);
+ assertEquals("Unexpected country iteration number", 1,
((Number)country1.get("_iterationNumber")).intValue());
+ assertEquals("Unexpected iterating attribute", "1",
((Map)((List)region0.get("_towns")).get(0)).get("_iteratingAttribute"));
}
- public void testEvaluateJavaScriptWithReader() throws Exception
+ public void testEvaluateJavaScript() throws Exception
{
String jsFilePath = TestFileUtils.createTempFileFromResource(this,
"JavaScriptConfigEvaluatorTest-test-config.js").getAbsolutePath();
- FileReader fileReader = new FileReader(jsFilePath);
- String rawConfig = new
JavaScriptConfigEvaluator().evaluateJavaScript(fileReader);
-
- 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"));
+ String rawConfig = new
JavaScriptConfigEvaluator().evaluateJavaScript(jsFilePath);
- 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"));
+ Map configAsObject = getObject(rawConfig);
+ performTest(configAsObject);
}
- private int getPropertyAsInt(Object configAsObject, String property)
throws Exception
+ public void testEvaluateJavaScriptWithReader() throws Exception
{
- Number propertyValue = (Number) getProperty(configAsObject, property);
+ String jsFilePath = TestFileUtils.createTempFileFromResource(this,
"JavaScriptConfigEvaluatorTest-test-config.js").getAbsolutePath();
+
+ FileReader fileReader = new FileReader(jsFilePath);
+ String rawConfig = new
JavaScriptConfigEvaluator().evaluateJavaScript(fileReader);
- return propertyValue.intValue();
+ Map configAsObject = getObject(rawConfig);
+ performTest(configAsObject);
}
- private List<?> getPropertyAsList(Object configAsObject, String property)
+ private List<?> getPropertyAsList(Map configAsMap, String property)
throws Exception
{
- return (List<?>)getProperty(configAsObject, property);
+ return (List<?>)configAsMap.get(property);
}
- private Object getObject(String jsonStringIn)
+ private Map getObject(String jsonStringIn)
{
Gson gson = new Gson();
@SuppressWarnings("rawtypes")
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]