summaryrefslogtreecommitdiff
path: root/qpid/java
diff options
context:
space:
mode:
authorRobert Godfrey <rgodfrey@apache.org>2014-07-29 12:58:37 +0000
committerRobert Godfrey <rgodfrey@apache.org>2014-07-29 12:58:37 +0000
commit2db948b9045d5c13919db8db3bfeca3712203a56 (patch)
tree69e9fdc687a976e60d3d3648dd4bf9825dc2ce2d /qpid/java
parent14e411f0f8fbbd10aa8bf08e8926332265e04b1c (diff)
downloadqpid-python-2db948b9045d5c13919db8db3bfeca3712203a56.tar.gz
QPID-5937 : [Java Broker] Add parameters to REST servlet to allow return of actual vs. effective attribute values
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1614333 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
-rw-r--r--qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/StandardEnvironmentFacadeFactory.java2
-rw-r--r--qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeFactory.java2
-rw-r--r--qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java2
-rw-r--r--qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreQuotaEventsTest.java2
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java7
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java2
-rw-r--r--qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNode.java2
-rw-r--r--qpid/java/broker-plugins/derby-store/src/test/java/org/apache/qpid/server/store/derby/DerbyMessageStoreQuotaEventsTest.java2
-rw-r--r--qpid/java/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/GenericJDBCConfigurationStore.java2
-rw-r--r--qpid/java/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/GenericJDBCMessageStore.java2
-rw-r--r--qpid/java/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/JDBCDetails.java2
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java39
-rw-r--r--qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java25
-rw-r--r--qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java70
14 files changed, 135 insertions, 26 deletions
diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/StandardEnvironmentFacadeFactory.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/StandardEnvironmentFacadeFactory.java
index 4c3b72a29b..6d3238728e 100644
--- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/StandardEnvironmentFacadeFactory.java
+++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/StandardEnvironmentFacadeFactory.java
@@ -71,7 +71,7 @@ public class StandardEnvironmentFacadeFactory implements EnvironmentFacadeFactor
for (ConfigParam cp : EnvironmentParams.SUPPORTED_PARAMS.values())
{
final String parameterName = cp.getName();
- Set<String> contextKeys = parent.getContextKeys();
+ Set<String> contextKeys = parent.getContextKeys(false);
if (!cp.isForReplication() && contextKeys.contains(parameterName))
{
envConfigMap.put(parameterName, parent.getContextValue(String.class, parameterName));
diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeFactory.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeFactory.java
index 37d53319b5..109bfe6978 100644
--- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeFactory.java
+++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/store/berkeleydb/replication/ReplicatedEnvironmentFacadeFactory.java
@@ -126,7 +126,7 @@ public class ReplicatedEnvironmentFacadeFactory implements EnvironmentFacadeFact
private Map<String, String> buildConfig(ConfiguredObject<?> parent, Pattern paramName)
{
Map<String, String> targetMap = new HashMap<>();
- for (String name : parent.getContextKeys())
+ for (String name : parent.getContextKeys(false))
{
if (paramName.matcher(name).matches())
{
diff --git a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java
index 061fa12768..2cdb6ec635 100644
--- a/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java
+++ b/qpid/java/bdbstore/src/main/java/org/apache/qpid/server/virtualhostnode/berkeleydb/BDBHAVirtualHostNodeImpl.java
@@ -418,7 +418,7 @@ public class BDBHAVirtualHostNodeImpl extends AbstractVirtualHostNode<BDBHAVirtu
LOGGER.debug("Creating new virtualhost with name : " + getGroupName());
}
- boolean hasBlueprint = getContextKeys().contains(VIRTUALHOST_BLUEPRINT_CONTEXT_VAR);
+ boolean hasBlueprint = getContextKeys(false).contains(VIRTUALHOST_BLUEPRINT_CONTEXT_VAR);
boolean blueprintUtilised = getContext().containsKey(VIRTUALHOST_BLUEPRINT_UTILISED_CONTEXT_VAR)
&& Boolean.parseBoolean(String.valueOf(getContext().get(
VIRTUALHOST_BLUEPRINT_UTILISED_CONTEXT_VAR)));
diff --git a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreQuotaEventsTest.java b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreQuotaEventsTest.java
index 1c5b705fa0..ee0edb5e59 100644
--- a/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreQuotaEventsTest.java
+++ b/qpid/java/bdbstore/src/test/java/org/apache/qpid/server/store/berkeleydb/BDBMessageStoreQuotaEventsTest.java
@@ -64,7 +64,7 @@ public class BDBMessageStoreQuotaEventsTest extends MessageStoreQuotaEventsTestB
final BDBVirtualHost parent = mock(BDBVirtualHost.class);
Map<String, String> contextMap = Collections.singletonMap("je.log.fileMax", MAX_BDB_LOG_SIZE);
when(parent.getContext()).thenReturn(contextMap);
- when(parent.getContextKeys()).thenReturn(contextMap.keySet());
+ when(parent.getContextKeys(false)).thenReturn(contextMap.keySet());
when(parent.getContextValue(eq(String.class),eq("je.log.fileMax"))).thenReturn(MAX_BDB_LOG_SIZE);
when(parent.getStorePath()).thenReturn(storeLocation);
when(parent.getStoreOverfullSize()).thenReturn(OVERFULL_SIZE);
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
index 49d3fea8fd..e886f913c1 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/AbstractConfiguredObject.java
@@ -1340,9 +1340,14 @@ public abstract class AbstractConfiguredObject<X extends ConfiguredObject<X>> im
}
@Override
- public Set<String> getContextKeys()
+ public Set<String> getContextKeys(final boolean excludeSystem)
{
Map<String,String> inheritedContext = new HashMap<>();
+ if(!excludeSystem)
+ {
+ inheritedContext.putAll(System.getenv());
+ inheritedContext.putAll((Map) System.getProperties());
+ }
generateInheritedContext(getModel(), this, inheritedContext);
return Collections.unmodifiableSet(inheritedContext.keySet());
}
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java
index 01ca2fa646..2ff6d80427 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/model/ConfiguredObject.java
@@ -79,7 +79,7 @@ public interface ConfiguredObject<X extends ConfiguredObject<X>>
<T> T getContextValue(Class<T> clazz, String propertyName);
- Set<String> getContextKeys();
+ Set<String> getContextKeys(final boolean includeSystem);
@DerivedAttribute( persist = true )
String getLastUpdatedBy();
diff --git a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNode.java b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNode.java
index df9ffda3a3..b4374af0f0 100644
--- a/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNode.java
+++ b/qpid/java/broker-core/src/main/java/org/apache/qpid/server/virtualhostnode/AbstractStandardVirtualHostNode.java
@@ -90,7 +90,7 @@ public abstract class AbstractStandardVirtualHostNode<X extends AbstractStandard
if (host == null)
{
- boolean hasBlueprint = getContextKeys().contains(VIRTUALHOST_BLUEPRINT_CONTEXT_VAR);
+ boolean hasBlueprint = getContextKeys(false).contains(VIRTUALHOST_BLUEPRINT_CONTEXT_VAR);
boolean blueprintUtilised = getContext().containsKey(VIRTUALHOST_BLUEPRINT_UTILISED_CONTEXT_VAR)
&& Boolean.parseBoolean(String.valueOf(getContext().get(VIRTUALHOST_BLUEPRINT_UTILISED_CONTEXT_VAR)));
diff --git a/qpid/java/broker-plugins/derby-store/src/test/java/org/apache/qpid/server/store/derby/DerbyMessageStoreQuotaEventsTest.java b/qpid/java/broker-plugins/derby-store/src/test/java/org/apache/qpid/server/store/derby/DerbyMessageStoreQuotaEventsTest.java
index e39a35f9a4..0aeb6bd0e8 100644
--- a/qpid/java/broker-plugins/derby-store/src/test/java/org/apache/qpid/server/store/derby/DerbyMessageStoreQuotaEventsTest.java
+++ b/qpid/java/broker-plugins/derby-store/src/test/java/org/apache/qpid/server/store/derby/DerbyMessageStoreQuotaEventsTest.java
@@ -54,7 +54,7 @@ public class DerbyMessageStoreQuotaEventsTest extends MessageStoreQuotaEventsTes
{
final DerbyVirtualHost parent = mock(DerbyVirtualHost.class);
when(parent.getContext()).thenReturn(createContextSettings());
- when(parent.getContextKeys()).thenReturn(Collections.emptySet());
+ when(parent.getContextKeys(false)).thenReturn(Collections.emptySet());
when(parent.getStorePath()).thenReturn(storeLocation);
when(parent.getStoreOverfullSize()).thenReturn(OVERFULL_SIZE);
when(parent.getStoreUnderfullSize()).thenReturn(UNDERFULL_SIZE);
diff --git a/qpid/java/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/GenericJDBCConfigurationStore.java b/qpid/java/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/GenericJDBCConfigurationStore.java
index 9453c135e9..554caebf5f 100644
--- a/qpid/java/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/GenericJDBCConfigurationStore.java
+++ b/qpid/java/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/GenericJDBCConfigurationStore.java
@@ -114,7 +114,7 @@ public class GenericJDBCConfigurationStore extends AbstractJDBCConfigurationStor
{
Map<String, String> providerAttributes = new HashMap<>();
Set<String> providerAttributeNames = connectionProviderFactory.getProviderAttributeNames();
- providerAttributeNames.retainAll(parent.getContextKeys());
+ providerAttributeNames.retainAll(parent.getContextKeys(false));
for(String attr : providerAttributeNames)
{
providerAttributes.put(attr, parent.getContextValue(String.class, attr));
diff --git a/qpid/java/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/GenericJDBCMessageStore.java b/qpid/java/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/GenericJDBCMessageStore.java
index 3304d01d86..338ef52078 100644
--- a/qpid/java/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/GenericJDBCMessageStore.java
+++ b/qpid/java/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/GenericJDBCMessageStore.java
@@ -93,7 +93,7 @@ public class GenericJDBCMessageStore extends GenericAbstractJDBCMessageStore
{
Map<String, String> providerAttributes = new HashMap<>();
Set<String> providerAttributeNames = connectionProviderFactory.getProviderAttributeNames();
- providerAttributeNames.retainAll(parent.getContextKeys());
+ providerAttributeNames.retainAll(parent.getContextKeys(false));
for(String attr : providerAttributeNames)
{
providerAttributes.put(attr, parent.getContextValue(String.class, attr));
diff --git a/qpid/java/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/JDBCDetails.java b/qpid/java/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/JDBCDetails.java
index 8cd4996033..eec2d49a80 100644
--- a/qpid/java/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/JDBCDetails.java
+++ b/qpid/java/broker-plugins/jdbc-store/src/main/java/org/apache/qpid/server/store/jdbc/JDBCDetails.java
@@ -224,7 +224,7 @@ public abstract class JDBCDetails
public static JDBCDetails getDetailsForJdbcUrl(String jdbcUrl, final ConfiguredObject<?> object)
{
- final Set<String> contextKeys = object.getContextKeys();
+ final Set<String> contextKeys = object.getContextKeys(false);
Map<String,String> mapConversion = new AbstractMap<String, String>()
{
@Override
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java
index 7c5ba5a6be..bc563c141e 100644
--- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java
+++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java
@@ -21,6 +21,7 @@ package org.apache.qpid.server.management.plugin.servlet.rest;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@@ -33,32 +34,54 @@ public class ConfiguredObjectToMapConverter
public static final String STATISTICS_MAP_KEY = "statistics";
public Map<String, Object> convertObjectToMap(final ConfiguredObject<?> confObject,
- Class<? extends ConfiguredObject> clazz,
- int depth)
+ Class<? extends ConfiguredObject> clazz,
+ int depth,
+ final boolean useActualValues,
+ final boolean includeSystemContext)
{
Map<String, Object> object = new LinkedHashMap<String, Object>();
- incorporateAttributesIntoMap(confObject, object);
+ incorporateAttributesIntoMap(confObject, object, useActualValues, includeSystemContext);
incorporateStatisticsIntoMap(confObject, object);
if(depth > 0)
{
- incorporateChildrenIntoMap(confObject, clazz, depth, object);
+ incorporateChildrenIntoMap(confObject, clazz, depth, object, useActualValues, includeSystemContext);
}
return object;
}
private void incorporateAttributesIntoMap(
- final ConfiguredObject<?> confObject, Map<String, Object> object)
+ final ConfiguredObject<?> confObject,
+ Map<String, Object> object,
+ final boolean useActualValues,
+ final boolean includeSystemContext)
{
+
for(String name : confObject.getAttributeNames())
{
- Object value = confObject.getAttribute(name);
+ Object value = useActualValues ? confObject.getActualAttributes().get(name) : confObject.getAttribute(name);
if(value instanceof ConfiguredObject)
{
object.put(name, ((ConfiguredObject) value).getName());
}
+ else if(ConfiguredObject.CONTEXT.equals(name))
+ {
+ Map<String,Object> contextValues = new HashMap<>();
+ if(useActualValues)
+ {
+ contextValues.putAll(confObject.getContext());
+ }
+ else
+ {
+ for(String contextName : confObject.getContextKeys(!includeSystemContext))
+ {
+ contextValues.put(contextName, confObject.getContextValue(String.class, contextName));
+ }
+ }
+ object.put(ConfiguredObject.CONTEXT, contextValues);
+ }
else if(value instanceof Collection)
{
List<Object> converted = new ArrayList();
@@ -98,7 +121,7 @@ public class ConfiguredObjectToMapConverter
private void incorporateChildrenIntoMap(
final ConfiguredObject confObject,
Class<? extends ConfiguredObject> clazz, int depth,
- Map<String, Object> object)
+ Map<String, Object> object, final boolean useActualValues, final boolean includeSystemContext)
{
for(Class<? extends ConfiguredObject> childClass : confObject.getModel().getChildTypes(clazz))
{
@@ -109,7 +132,7 @@ public class ConfiguredObjectToMapConverter
for(ConfiguredObject child : children)
{
- childObjects.add(convertObjectToMap(child, childClass, depth-1));
+ childObjects.add(convertObjectToMap(child, childClass, depth-1, useActualValues, includeSystemContext));
}
if(!childObjects.isEmpty())
diff --git a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
index b261927ee7..87a4b6fb1a 100644
--- a/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
+++ b/qpid/java/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
@@ -53,9 +53,11 @@ public class RestServlet extends AbstractServlet
private static final String HIERARCHY_INIT_PARAMETER = "hierarchy";
public static final String DEPTH_PARAM = "depth";
+ public static final String ACTUALS_PARAM = "actuals";
public static final String SORT_PARAM = "sort";
+ public static final String INCLUDE_SYS_CONTEXT_PARAM = "includeSysContext";
- public static final Set<String> RESERVED_PARAMS = new HashSet<String>(Arrays.asList(DEPTH_PARAM, SORT_PARAM));
+ public static final Set<String> RESERVED_PARAMS = new HashSet<String>(Arrays.asList(DEPTH_PARAM, SORT_PARAM, ACTUALS_PARAM, INCLUDE_SYS_CONTEXT_PARAM));
private Class<? extends ConfiguredObject>[] _hierarchy;
@@ -311,12 +313,14 @@ public class RestServlet extends AbstractServlet
// TODO - sort special params, everything else should act as a filter
int depth = getDepthParameterFromRequest(request);
+ boolean actuals = getBooleanParameterFromRequest(request, ACTUALS_PARAM);
+ boolean includeSystemContext = getBooleanParameterFromRequest(request, INCLUDE_SYS_CONTEXT_PARAM);
List<Map<String, Object>> output = new ArrayList<Map<String, Object>>();
for(ConfiguredObject configuredObject : allObjects)
{
output.add(_objectConverter.convertObjectToMap(configuredObject, getConfiguredClass(),
- depth));
+ depth, actuals, includeSystemContext));
}
final Writer writer = new BufferedWriter(response.getWriter());
@@ -576,5 +580,22 @@ public class RestServlet extends AbstractServlet
return depth;
}
+ private boolean getBooleanParameterFromRequest(HttpServletRequest request, final String paramName)
+ {
+ boolean value = false;
+ final String stringValue = request.getParameter(paramName);
+ if(stringValue!=null)
+ {
+ try
+ {
+ value = Boolean.parseBoolean(stringValue);
+ }
+ catch (NumberFormatException e)
+ {
+ LOGGER.warn("Could not parse " + stringValue + " as integer");
+ }
+ }
+ return value;
+ }
}
diff --git a/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java b/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java
index 82c8d01379..39e8ff6185 100644
--- a/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java
+++ b/qpid/java/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java
@@ -19,15 +19,19 @@
*/
package org.apache.qpid.server.management.plugin.servlet.rest;
+import static org.apache.qpid.server.management.plugin.servlet.rest.ConfiguredObjectToMapConverter.STATISTICS_MAP_KEY;
+import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import static org.apache.qpid.server.management.plugin.servlet.rest.ConfiguredObjectToMapConverter.STATISTICS_MAP_KEY;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import junit.framework.TestCase;
@@ -52,7 +56,8 @@ public class ConfiguredObjectToMapConverterTest extends TestCase
when(_configuredObject.getStatistics()).thenReturn(Collections.singletonMap(statisticName, (Number) statisticValue));
- Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject, ConfiguredObject.class, 0);
+ Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject, ConfiguredObject.class, 0,
+ false, false);
Map<String, Object> statsAsMap = (Map<String, Object>) resultMap.get(STATISTICS_MAP_KEY);
assertNotNull("Statistics should be part of map", statsAsMap);
assertEquals("Unexpected number of statistics", 1, statsAsMap.size());
@@ -65,7 +70,8 @@ public class ConfiguredObjectToMapConverterTest extends TestCase
final String attributeValue = "value";
configureMockToReturnOneAttribute(_configuredObject, attributeName, attributeValue);
- Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject, ConfiguredObject.class, 0);
+ Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject, ConfiguredObject.class, 0,
+ false, false);
assertEquals("Unexpected number of attributes", 1, resultMap.size());
assertEquals("Unexpected attribute value", attributeValue, resultMap.get(attributeName));
}
@@ -82,7 +88,8 @@ public class ConfiguredObjectToMapConverterTest extends TestCase
configureMockToReturnOneAttribute(_configuredObject, attributeName, attributeValue);
- Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject, ConfiguredObject.class, 0);
+ Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject, ConfiguredObject.class, 0,
+ false, false);
assertEquals("Unexpected number of attributes", 1, resultMap.size());
assertEquals("Unexpected attribute value", "attributeConfiguredObjectName", resultMap.get(attributeName));
}
@@ -100,7 +107,8 @@ public class ConfiguredObjectToMapConverterTest extends TestCase
configureMockToReturnOneAttribute(mockChild, childAttributeName, childAttributeValue);
when(_configuredObject.getChildren(TestChild.class)).thenReturn(Arrays.asList(mockChild));
- Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject, ConfiguredObject.class, 1);
+ Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject, ConfiguredObject.class, 1,
+ false, false);
assertEquals("Unexpected parent map size", 1, resultMap.size());
final List<Map<String, Object>> childList = (List<Map<String, Object>>) resultMap.get("testchilds");
@@ -112,6 +120,58 @@ public class ConfiguredObjectToMapConverterTest extends TestCase
assertEquals("Unexpected child attribute value", childAttributeValue, childMap.get(childAttributeName));
}
+ public void testActuals()
+ {
+ final String childAttributeName = "childattribute";
+ final String childAttributeValue = "childvalue";
+ final String childActualAttributeValue = "${actualvalue}";
+ final Map<String,Object> actualContext = Collections.<String,Object>singletonMap("key","value");
+ final Set<String> inheritedKeys = new HashSet<>(Arrays.asList("key","inheritedkey"));
+
+ Model model = createTestModel();
+
+ TestChild mockChild = mock(TestChild.class);
+ when(mockChild.getModel()).thenReturn(model);
+ when(_configuredObject.getModel()).thenReturn(model);
+ when(_configuredObject.getAttributeNames()).thenReturn(Collections.singletonList(ConfiguredObject.CONTEXT));
+ when(_configuredObject.getContextValue(eq(String.class), eq("key"))).thenReturn("value");
+ when(_configuredObject.getContextValue(eq(String.class),eq("inheritedkey"))).thenReturn("foo");
+ when(_configuredObject.getContextKeys(false)).thenReturn(inheritedKeys);
+ when(_configuredObject.getContext()).thenReturn(actualContext);
+ when(mockChild.getAttributeNames()).thenReturn(Arrays.asList(childAttributeName, ConfiguredObject.CONTEXT));
+ when(mockChild.getAttribute(childAttributeName)).thenReturn(childAttributeValue);
+ when(mockChild.getActualAttributes()).thenReturn(Collections.singletonMap(childAttributeName, childActualAttributeValue));
+ when(_configuredObject.getChildren(TestChild.class)).thenReturn(Arrays.asList(mockChild));
+
+
+ Map<String, Object> resultMap = _converter.convertObjectToMap(_configuredObject, ConfiguredObject.class, 1, true,
+ false);
+ assertEquals("Unexpected parent map size", 2, resultMap.size());
+ assertEquals("Incorrect context", resultMap.get(ConfiguredObject.CONTEXT), actualContext);
+ List<Map<String, Object>> childList = (List<Map<String, Object>>) resultMap.get("testchilds");
+ assertEquals("Unexpected number of children", 1, childList.size());
+ Map<String, Object> childMap = childList.get(0);
+ assertEquals("Unexpected child map size", 2, childMap.size());
+ assertNotNull(childMap);
+
+ assertEquals("Unexpected child attribute value", childActualAttributeValue, childMap.get(childAttributeName));
+
+ resultMap = _converter.convertObjectToMap(_configuredObject, ConfiguredObject.class, 1, false, false);
+ assertEquals("Unexpected parent map size", 2, resultMap.size());
+ Map<String, Object> inheritedContext = new HashMap<>();
+ inheritedContext.put("key","value");
+ inheritedContext.put("inheritedkey","foo");
+ assertEquals("Incorrect context", resultMap.get(ConfiguredObject.CONTEXT), inheritedContext);
+ childList = (List<Map<String, Object>>) resultMap.get("testchilds");
+ assertEquals("Unexpected number of children", 1, childList.size());
+ childMap = childList.get(0);
+ assertEquals("Unexpected child map size", 2, childMap.size());
+ assertNotNull(childMap);
+
+ assertEquals("Unexpected child attribute value", childAttributeValue, childMap.get(childAttributeName));
+
+ }
+
private Model createTestModel()
{
Model model = mock(Model.class);