Author: orudyy
Date: Tue Aug  2 17:30:27 2016
New Revision: 1754984

URL: http://svn.apache.org/viewvc?rev=1754984&view=rev
Log:
QPID-7328: Add derived attribute for broker documentation URL and fix 
evaluation of context variables in REST layer

Merged from trunk using
svn merge -c 1754251,1754550,1754741  
https://svn.apache.org/repos/asf/qpid/java/trunk
Merge conflicts resolved manually

Modified:
    qpid/java/branches/6.0.x/   (props changed)
    
qpid/java/branches/6.0.x/broker-core/src/main/java/org/apache/qpid/server/model/Broker.java
    
qpid/java/branches/6.0.x/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
    
qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementConfiguration.java
    
qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java
    
qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/resources/index.html
    
qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/resources/js/qpid/common/ConsoleHelper.js
    
qpid/java/branches/6.0.x/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java
    
qpid/java/branches/6.0.x/systests/src/test/java/org/apache/qpid/systest/rest/BrokerRestTest.java

Propchange: qpid/java/branches/6.0.x/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug  2 17:30:27 2016
@@ -9,5 +9,5 @@
 /qpid/branches/java-broker-vhost-refactor/java:1493674-1494547
 /qpid/branches/java-network-refactor/qpid/java:805429-821809
 /qpid/branches/qpid-2935/qpid/java:1061302-1072333
-/qpid/java/trunk:1715445-1715447,1715586,1715940,1716086-1716087,1716127-1716128,1716141,1716153,1716155,1716194,1716204,1716209,1716227,1716277,1716357,1716368,1716370,1716374,1716432,1716444-1716445,1716455,1716461,1716474,1716489,1716497,1716515,1716555,1716602,1716606-1716610,1716619,1716636,1717269,1717299,1717401,1717446,1717449,1717626,1717691,1717735,1717780,1718744,1718889,1718893,1718918,1718922,1719026,1719028,1719033,1719037,1719047,1719051,1720340,1720664,1721151,1721198,1722019-1722020,1722246,1722339,1722416,1722674,1722678,1722683,1722711,1723064,1723194,1723563,1724216,1724251,1724257,1724292,1724375,1724397,1724432,1724582,1724603,1724780,1724843-1724844,1725295,1725569,1725760,1726176,1726244-1726246,1726249,1726358,1726436,1726449,1726456,1726646,1726653,1726755,1726778,1727532,1727555,1727608,1727951,1727954,1728089,1728167,1728302,1728497,1728501,1728524,1728639,1728651,1728772,1729215,1729297,1729347,1729356,1729406,1729408,1729412,1729515,1729638,1729656-1729
 
657,1729783,1729828,1729832,1729841,1729851,1729886,1729904,1729973,1730019,1730025,1730052,1730072,1730088,1730494,1730499,1730547,1730559,1730567,1730578,1730585,1730651,1730697,1730712-1730713,1730805,1731029,1731110,1731210,1731225,1731444,1731551,1731612,1732184,1732452,1732461,1732465,1732525,1732812,1733467,1734452,1736478,1736751,1736838,1737804,1737835,1737853,1737984,1737992,1738119,1738135,1738231,1738271,1738607,1738610,1738731,1738914,1741702,1742257,1742284,1742544,1742900,1742926,1743161,1743228,1743383,1743982,1744012-1744013,1744046,1744123,1744157,1744276,1744403,1745424,1745450,1746140,1746273,1747526,1748254,1748723,1748818,1749349,1749399,1749482,1749524,1750359-1750360,1750943,1751433,1754354,1754392,1754429,1754510
+/qpid/java/trunk:1715445-1715447,1715586,1715940,1716086-1716087,1716127-1716128,1716141,1716153,1716155,1716194,1716204,1716209,1716227,1716277,1716357,1716368,1716370,1716374,1716432,1716444-1716445,1716455,1716461,1716474,1716489,1716497,1716515,1716555,1716602,1716606-1716610,1716619,1716636,1717269,1717299,1717401,1717446,1717449,1717626,1717691,1717735,1717780,1718744,1718889,1718893,1718918,1718922,1719026,1719028,1719033,1719037,1719047,1719051,1720340,1720664,1721151,1721198,1722019-1722020,1722246,1722339,1722416,1722674,1722678,1722683,1722711,1723064,1723194,1723563,1724216,1724251,1724257,1724292,1724375,1724397,1724432,1724582,1724603,1724780,1724843-1724844,1725295,1725569,1725760,1726176,1726244-1726246,1726249,1726358,1726436,1726449,1726456,1726646,1726653,1726755,1726778,1727532,1727555,1727608,1727951,1727954,1728089,1728167,1728302,1728497,1728501,1728524,1728639,1728651,1728772,1729215,1729297,1729347,1729356,1729406,1729408,1729412,1729515,1729638,1729656-1729
 
657,1729783,1729828,1729832,1729841,1729851,1729886,1729904,1729973,1730019,1730025,1730052,1730072,1730088,1730494,1730499,1730547,1730559,1730567,1730578,1730585,1730651,1730697,1730712-1730713,1730805,1731029,1731110,1731210,1731225,1731444,1731551,1731612,1732184,1732452,1732461,1732465,1732525,1732812,1733467,1734452,1736478,1736751,1736838,1737804,1737835,1737853,1737984,1737992,1738119,1738135,1738231,1738271,1738607,1738610,1738731,1738914,1741702,1742257,1742284,1742544,1742900,1742926,1743161,1743228,1743383,1743982,1744012-1744013,1744046,1744123,1744157,1744276,1744403,1745424,1745450,1746140,1746273,1747526,1748254,1748723,1748818,1749349,1749399,1749482,1749524,1750359-1750360,1750943,1751433,1754251,1754354,1754392,1754429,1754510,1754550
 /qpid/trunk/qpid:796646-796653

Modified: 
qpid/java/branches/6.0.x/broker-core/src/main/java/org/apache/qpid/server/model/Broker.java
URL: 
http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/broker-core/src/main/java/org/apache/qpid/server/model/Broker.java?rev=1754984&r1=1754983&r2=1754984&view=diff
==============================================================================
--- 
qpid/java/branches/6.0.x/broker-core/src/main/java/org/apache/qpid/server/model/Broker.java
 (original)
+++ 
qpid/java/branches/6.0.x/broker-core/src/main/java/org/apache/qpid/server/model/Broker.java
 Tue Aug  2 17:30:27 2016
@@ -61,6 +61,7 @@ public interface Broker<X extends Broker
     String QPID_HTTP_PORT = "qpid.http_port";
     String QPID_RMI_PORT  = "qpid.rmi_port";
     String QPID_JMX_PORT  = "qpid.jmx_port";
+    String QPID_DOCUMENTATION_URL = "qpid.helpURL";
 
     String NETWORK_BUFFER_SIZE = "qpid.broker.networkBufferSize";
     // network buffer should at least hold a SSL/TLS frame which in jdk1.8 is 
33305 bytes
@@ -107,6 +108,9 @@ public interface Broker<X extends Broker
     @ManagedContextDefault(name = 
CommonProperties.QPID_SECURITY_TLS_CIPHER_SUITE_BLACK_LIST)
     String DEFAULT_SECURITY_TLS_CIPHER_SUITE_BLACK_LIST = "[]";
 
+    @ManagedContextDefault(name = QPID_DOCUMENTATION_URL)
+    String DEFAULT_DOCUMENTATION_URL = 
"http://qpid.apache.org/releases/qpid-java-${qpid.version}/java-broker/book/";;
+
     @DerivedAttribute
     String getBuildVersion();
 
@@ -189,6 +193,9 @@ public interface Broker<X extends Broker
     @DerivedAttribute(description = "JVM arguments specified on startup")
     List<String> getJvmArguments();
 
+    @DerivedAttribute(description = "URL to broker documentation")
+    String getDocumentationUrl();
+
     @ManagedStatistic(statisticType = StatisticType.POINT_IN_TIME,
                       units = StatisticUnit.COUNT,
                       label = "Live threads",

Modified: 
qpid/java/branches/6.0.x/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
URL: 
http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java?rev=1754984&r1=1754983&r2=1754984&view=diff
==============================================================================
--- 
qpid/java/branches/6.0.x/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
 (original)
+++ 
qpid/java/branches/6.0.x/broker-core/src/main/java/org/apache/qpid/server/model/adapter/BrokerAdapter.java
 Tue Aug  2 17:30:27 2016
@@ -130,6 +130,7 @@ public class BrokerAdapter extends Abstr
     private final long _maximumDirectMemorySize = getMaxDirectMemorySize();
     private final BufferPoolMXBean _bufferPoolMXBean;
     private final List<String> _jvmArguments;
+    private String _documentationUrl;
 
     @ManagedObjectFactoryConstructor
     public BrokerAdapter(Map<String, Object> attributes,
@@ -364,6 +365,7 @@ public class BrokerAdapter extends Abstr
             
getEventLogger().message(BrokerMessages.FAILED_CHILDREN(failedChildren.toString()));
         }
 
+        _documentationUrl = getContextValue(String.class, 
QPID_DOCUMENTATION_URL);
         final boolean brokerShutdownOnErroredChild = 
getContextValue(Boolean.class,
                                                                      
BROKER_FAIL_STARTUP_WITH_ERRORED_CHILD);
         if (!_parent.isManagementMode() && brokerShutdownOnErroredChild && 
hasBrokerAnyErroredChildren)
@@ -1075,6 +1077,12 @@ public class BrokerAdapter extends Abstr
     }
 
     @Override
+    public String getDocumentationUrl()
+    {
+        return _documentationUrl;
+    }
+
+    @Override
     public void performGC()
     {
         _securityManager.authorise(Operation.CONFIGURE, this);

Modified: 
qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementConfiguration.java
URL: 
http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementConfiguration.java?rev=1754984&r1=1754983&r2=1754984&view=diff
==============================================================================
--- 
qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementConfiguration.java
 (original)
+++ 
qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/HttpManagementConfiguration.java
 Tue Aug  2 17:30:27 2016
@@ -45,10 +45,6 @@ public interface HttpManagementConfigura
     @ManagedAttribute( defaultValue = "600" )
     public int getSessionTimeout();
 
-    String QPID_HELP_URL = "qpid.helpURL";
-    @ManagedContextDefault(name = QPID_HELP_URL)
-    String DEFAULT_HELP_URL = 
"http://qpid.apache.org/releases/qpid-java-${qpid.version}/java-broker/book/index.html";;
-
     String HTTP_MANAGEMENT_COMPRESS_RESPONSES = 
"httpManagement.compressResponses";
     @ManagedContextDefault(name = HTTP_MANAGEMENT_COMPRESS_RESPONSES)
     boolean DEFAULT_COMPRESS_RESPONSES = true;

Modified: 
qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java
URL: 
http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java?rev=1754984&r1=1754983&r2=1754984&view=diff
==============================================================================
--- 
qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java
 (original)
+++ 
qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverter.java
 Tue Aug  2 17:30:27 2016
@@ -109,14 +109,9 @@ public class ConfiguredObjectToMapConver
                 }
                 else if (ConfiguredObject.CONTEXT.equals(name))
                 {
-                    Map<String, Object> contextValues = new HashMap<>();
-                    if (!converterOptions.isExcludeInheritedContext())
-                    {
-                        
contextValues.putAll(confObject.getModel().getTypeRegistry().getDefaultContext());
-                        contextValues.putAll(System.getenv());
-                        contextValues.putAll((Map) System.getProperties());
-                    }
-                    collectContext(contextValues, confObject, 
converterOptions);
+                    Map<String, Object> contextValues = 
collectContext(confObject,
+                                                                       
converterOptions.isExcludeInheritedContext(),
+                                                                       
converterOptions.isUseActualValues());
 
                     if (!contextValues.isEmpty())
                     {
@@ -191,36 +186,59 @@ public class ConfiguredObjectToMapConver
         }
     }
 
-    private void collectContext(Map<String, Object> contextValues, 
ConfiguredObject<?> confObject, ConverterOptions options)
+    private Map<String, Object> collectContext(ConfiguredObject<?> 
configuredObject,
+                                               boolean excludeInheritedContext,
+                                               boolean useActualValues)
     {
-        Model model = confObject.getModel();
-        Object value = 
confObject.getActualAttributes().get(ConfiguredObject.CONTEXT);
-        if (!options.isExcludeInheritedContext())
+        Map<String, Object> actualContext = new HashMap<>();
+        if (excludeInheritedContext)
         {
-            Collection<Class<? extends ConfiguredObject>> parents = 
model.getParentTypes(confObject.getCategoryClass());
-            if(parents != null && !parents.isEmpty())
+            Object value = 
configuredObject.getActualAttributes().get(ConfiguredObject.CONTEXT);
+            if (value instanceof Map)
             {
-                ConfiguredObject parent = 
confObject.getParent(parents.iterator().next());
-                if(parent != null)
-                {
-                    collectContext(contextValues, parent, options);
-                }
+                actualContext.putAll((Map<String, String>) value);
             }
         }
-        if (value instanceof Map)
+        else
+        {
+            
actualContext.putAll(configuredObject.getModel().getTypeRegistry().getDefaultContext());
+            actualContext.putAll(System.getenv());
+            actualContext.putAll((Map) System.getProperties());
+            collectInheritedActualContext(configuredObject, actualContext);
+        }
+
+        if (useActualValues)
+        {
+            return actualContext;
+        }
+        else
         {
-            if (options.isUseActualValues())
+            Map<String, Object> effectiveContext = new HashMap<>();
+            for (String contextKey : actualContext.keySet())
             {
-                contextValues.putAll((Map<String,String>)value);
+                effectiveContext.put(contextKey, 
configuredObject.getContextValue(String.class, contextKey));
             }
-            else
+            return effectiveContext;
+        }
+    }
+
+    private void collectInheritedActualContext(ConfiguredObject<?> confObject, 
Map<String, Object> contextValues)
+    {
+        Model model = confObject.getModel();
+        Collection<Class<? extends ConfiguredObject>> parents = 
model.getParentTypes(confObject.getCategoryClass());
+        if(parents != null && !parents.isEmpty())
+        {
+            ConfiguredObject parent = 
confObject.getParent(parents.iterator().next());
+            if(parent != null)
             {
-                for (String contextKey : ((Map<String,String>)value).keySet())
-                {
-                    contextValues.put(contextKey, 
confObject.getContextValue(String.class, contextKey));
-                }
+                collectInheritedActualContext(parent, contextValues);
             }
         }
+        Object value = 
confObject.getActualAttributes().get(ConfiguredObject.CONTEXT);
+        if (value instanceof Map)
+        {
+            contextValues.putAll((Map<String, Object>)value);
+        }
     }
 
     private void incorporateStatisticsIntoMap(

Modified: 
qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/resources/index.html
URL: 
http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/resources/index.html?rev=1754984&r1=1754983&r2=1754984&view=diff
==============================================================================
--- 
qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/resources/index.html
 (original)
+++ 
qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/resources/index.html
 Tue Aug  2 17:30:27 2016
@@ -108,7 +108,7 @@
                     data-dojo-props="iconClass:'dijitIconFunction',onClick: 
function(){qpidManagementHelper.showPreferencesDialog();}">Preferences</div>
                 <div data-dojo-type="dijit.MenuItem" data-dojo-props="onClick: 
function(){qpidManagementHelper.showAPI();}">REST API</div>
                 <div data-dojo-type="dijit.MenuItem"
-                     data-dojo-props="iconClass: 'helpIcon', onClick: 
function(){qpidManagementHelper.showHelp();}">Help</div>
+                     data-dojo-props="iconClass: 'helpIcon', onClick: 
function(){qpidManagementHelper.showDocumentation();}">Documentation</div>
             </div>
           </div>
         </div>

Modified: 
qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/resources/js/qpid/common/ConsoleHelper.js
URL: 
http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/resources/js/qpid/common/ConsoleHelper.js?rev=1754984&r1=1754983&r2=1754984&view=diff
==============================================================================
--- 
qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/resources/js/qpid/common/ConsoleHelper.js
 (original)
+++ 
qpid/java/branches/6.0.x/broker-plugins/management-http/src/main/java/resources/js/qpid/common/ConsoleHelper.js
 Tue Aug  2 17:30:27 2016
@@ -23,6 +23,18 @@ define(["dojo/domReady!"], function () {
     var preferencesDialog = null;
     var helpURL = null;
 
+    var documentationUrl = null;
+
+    var openWindow = function (url, title)
+    {
+        var newWindow = window.open(
+            url,
+            title,
+            
'height=600,width=600,scrollbars=1,location=1,resizable=1,status=0,toolbar=0,titlebar=1,menubar=0',
+            true);
+        newWindow.focus();
+    };
+
     return {
         showPreferencesDialog: function () {
           if (preferencesDialog == null)
@@ -39,51 +51,33 @@ define(["dojo/domReady!"], function () {
               preferencesDialog.showDialog();
           }
         },
-        getHelpUrl: function(callback)
+        showDocumentation: function ()
         {
-            this.management.load({type: "broker"}, {depth: 0}).then(
-             function(data) {
-              var broker = data[0];
-              if ("context" in broker && "qpid.helpURL" in broker["context"] )
-              {
-                helpURL = broker["context"]["qpid.helpURL"];
-              }
-              else
-              {
-                helpURL = "http://qpid.apache.org/";;
-              }
-              if (callback)
-              {
-                callback(helpURL);
-              }
-             });
-        },
-        showHelp: function()
-        {
-          var openWindow = function(url)
-          {
-              var newWindow = 
window.open(url,'QpidHelp','height=600,width=600,scrollbars=1,location=1,resizable=1,status=0,toolbar=0,titlebar=1,menubar=0',
 true);
-              newWindow.focus();
-          }
-
-          if (helpURL)
-          {
-            openWindow(helpURL)
-          }
-          else
-          {
-            this.getHelpUrl(openWindow);
-          }
+            if (documentationUrl)
+            {
+                openWindow(documentationUrl, "Qpid Documentation");
+            }
+            else
+            {
+                this.management.load({type: "broker"}, {depth: 0, 
excludeInheritedContext: true})
+                    .then(function (data)
+                    {
+                        var broker = data[0];
+                        if (broker.documentationUrl)
+                        {
+                            documentationUrl = broker.documentationUrl;
+                        }
+                        else
+                        {
+                            documentationUrl = 
"http://qpid.apache.org/components/java-broker/";;
+                        }
+                        openWindow(documentationUrl, "Qpid Documentation")
+                    });
+            }
         },
         showAPI: function()
         {
-          var openWindow = function(url)
-          {
-            var newWindow = window.open(url,'Qpid REST 
API','height=800,width=800,scrollbars=1,location=1,resizable=1,status=0,toolbar=1,titlebar=1,menubar=1',
 true);
-            newWindow.focus();
-          }
-
-          openWindow("/apidocs");
+            openWindow("/apidocs", 'Qpid REST API');
         }
 
     };

Modified: 
qpid/java/branches/6.0.x/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java
URL: 
http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java?rev=1754984&r1=1754983&r2=1754984&view=diff
==============================================================================
--- 
qpid/java/branches/6.0.x/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java
 (original)
+++ 
qpid/java/branches/6.0.x/broker-plugins/management-http/src/test/java/org/apache/qpid/server/management/plugin/servlet/rest/ConfiguredObjectToMapConverterTest.java
 Tue Aug  2 17:30:27 2016
@@ -48,6 +48,23 @@ import org.apache.qpid.test.utils.QpidTe
 
 public class ConfiguredObjectToMapConverterTest extends QpidTestCase
 {
+    private static final String TEST_SYSTEM_PROPERTY1_NAME = "qpid.test.name";
+    private static final String TEST_SYSTEM_PROPERTY1_ACTUAL_VALUE = 
"context-test";
+    private static final String TEST_SYSTEM_PROPERTY2_NAME = "qpid.test.name2";
+    private static final String TEST_SYSTEM_PROPERTY2_ACTUAL_VALUE = "${" + 
TEST_SYSTEM_PROPERTY1_NAME + "}-value2";
+    private static final String TEST_SYSTEM_PROPERTY2_EFFECTIVE_VALUE = 
TEST_SYSTEM_PROPERTY1_ACTUAL_VALUE + "-value2";
+    private static final String PARENT_CONTEXT_PROPERTY1_NAME = "parentTest";
+    private static final String PARENT_CONTEXT_PROPERTY1_ACTUAL_VALUE = 
"carTestValue";
+    private static final String PARENT_CONTEXT_PROPERTY2_NAME = 
"parentTestExpression";
+    private static final String PARENT_CONTEXT_PROPERTY2_ACTUAL_VALUE =
+            "${" + PARENT_CONTEXT_PROPERTY1_NAME + "}-${" + 
TEST_SYSTEM_PROPERTY2_NAME + "}";
+    private static final String PARENT_CONTEXT_PROPERTY2_EFFECTIVE_VALUE =
+            PARENT_CONTEXT_PROPERTY1_ACTUAL_VALUE + "-" + 
TEST_SYSTEM_PROPERTY2_EFFECTIVE_VALUE;
+    private static final String CHILD_CONTEXT_PROPERTY_NAME = "test";
+    private static final String CHILD_CONTEXT_PROPERTY_ACTUAL_VALUE =
+            "test-${" + PARENT_CONTEXT_PROPERTY2_NAME + "}";
+    private static final String CHILD_CONTEXT_PROPERTY_EFFECTIVE_VALUE =
+            "test-" + PARENT_CONTEXT_PROPERTY2_EFFECTIVE_VALUE;
     private ConfiguredObjectToMapConverter _converter = new 
ConfiguredObjectToMapConverter();
     private ConfiguredObject _configuredObject = mock(ConfiguredObject.class);
 
@@ -381,112 +398,128 @@ public class ConfiguredObjectToMapConver
         assertEquals("*****", ((Map) attrs).get("secureAttribute"));
     }
 
-    public void testExcludeInheritedContext()
+    public void testIncludeInheritedContextAndEffective()
     {
-        Model model = 
org.apache.qpid.server.model.testmodels.hierarchy.TestModel.getInstance();
-        final Map<String, Object> carAttributes = new HashMap<>();
-        carAttributes.put(ConfiguredObject.NAME, "myCar");
-        carAttributes.put(ConfiguredObject.CONTEXT, 
Collections.singletonMap("parentTest", "parentTestValue"));
-        TestCar car = model.getObjectFactory().create(TestCar.class,
-                                                      carAttributes);
-        final Map<String, Object> engineAttributes = new HashMap<>();
-        engineAttributes.put(ConfiguredObject.NAME, "myEngine");
-        engineAttributes.put(ConfiguredObject.TYPE, 
TestElecEngineImpl.TEST_ELEC_ENGINE_TYPE);
-        engineAttributes.put(ConfiguredObject.CONTEXT, 
Collections.singletonMap("test", "testValue"));
-        TestEngine engine = (TestEngine) car.createChild(TestEngine.class, 
engineAttributes);
-
-        Map<String, Object> resultMap = _converter.convertObjectToMap(engine,
-                                                                      
ConfiguredObject.class,
-                                                                      new 
ConfiguredObjectToMapConverter.ConverterOptions(
-                                                                              
1,
-                                                                              
false,
-                                                                              
false,
-                                                                              
0,
-                                                                              
false,
-                                                                              
false));
-        Object contextValue = resultMap.get("context");
-        assertTrue("Unexpected type of context", contextValue instanceof Map);
-        assertTrue("Unexpected size of context", ((Map)contextValue).size() > 
1);
-        assertEquals("Unexpected context content", "testValue", 
((Map)contextValue).get("test"));
-        assertEquals("Unexpected context content", "parentTestValue", 
((Map)contextValue).get("parentTest"));
-
-        resultMap = _converter.convertObjectToMap(engine,
-                                                  ConfiguredObject.class,
-                                                  new 
ConfiguredObjectToMapConverter.ConverterOptions(1,
-                                                                               
                       false,
-                                                                               
                       false,
-                                                                               
                       0,
-                                                                               
                       false,
-                                                                               
                       true));
-        contextValue = resultMap.get("context");
-        assertTrue("Unexpected type of context", contextValue instanceof Map);
-        assertEquals("Unexpected size of context", 1, 
((Map)contextValue).size());
-        assertEquals("Unexpected context content","testValue", 
((Map)contextValue).get("test"));
-
-
-
-
-
-        /*
-
-
-
-//        Model model = createTestModel();
-        ConfiguredObjectTypeRegistry typeRegistry = model.getTypeRegistry();
-        Map<String, ConfiguredObjectAttribute<?, ?>> attributeTypes = 
typeRegistry.getAttributeTypes(TestChild.class);
-        ConfiguredObjectAttribute contextAttribute = 
mock(ConfiguredObjectMethodAttribute.class);
-        when(attributeTypes.get(eq("context"))).thenReturn(contextAttribute);
+        TestEngine engine = createEngineWithContext();
+        ConfiguredObjectToMapConverter.ConverterOptions options = new 
ConfiguredObjectToMapConverter.ConverterOptions(
+                1,
+                false,
+                false,
+                0,
+                false,
+                false);
+        Map<String, Object> resultMap = _converter.convertObjectToMap(engine, 
TestEngine.class, options);
+        Map<String, String> context = getContext(resultMap);
+
+        assertTrue("Unexpected size of context", context.size() >= 5);
+        assertEquals("Unexpected engine context content",
+                     CHILD_CONTEXT_PROPERTY_EFFECTIVE_VALUE,
+                     context.get(CHILD_CONTEXT_PROPERTY_NAME));
+        assertEquals("Unexpected car context content",
+                     PARENT_CONTEXT_PROPERTY1_ACTUAL_VALUE, 
context.get(PARENT_CONTEXT_PROPERTY1_NAME));
+        assertEquals("Unexpected car context content",
+                     PARENT_CONTEXT_PROPERTY2_EFFECTIVE_VALUE,
+                     context.get(PARENT_CONTEXT_PROPERTY2_NAME));
+        assertEquals("Unexpected system context content",
+                     TEST_SYSTEM_PROPERTY1_ACTUAL_VALUE,
+                     context.get(TEST_SYSTEM_PROPERTY1_NAME));
+        assertEquals("Unexpected system context content",
+                     TEST_SYSTEM_PROPERTY2_EFFECTIVE_VALUE,
+                     context.get(TEST_SYSTEM_PROPERTY2_NAME));
+    }
 
-        TestChild mockChild = mock(TestChild.class);
-        when(mockChild.getModel()).thenReturn(model);
-        when(mockChild.getCategoryClass()).thenReturn(TestChild.class);
-        
when(mockChild.getParent(Matchers.<Class>any())).thenReturn(_configuredObject);
-        when(_configuredObject.getModel()).thenReturn(model);
-        
when(_configuredObject.getChildren(TestChild.class)).thenReturn(Arrays.asList(mockChild));
-        
when(model.getParentTypes(TestChild.class)).thenReturn(Collections.<Class<? 
extends ConfiguredObject>>singleton(TestChild.class));
-        when(_configuredObject.getCategoryClass()).thenReturn(TestChild.class);
+    public void testIncludeInheritedContextAndActual()
+    {
+        TestEngine engine = createEngineWithContext();
+        ConfiguredObjectToMapConverter.ConverterOptions options = new 
ConfiguredObjectToMapConverter.ConverterOptions(
+                1,
+                true,
+                false,
+                0,
+                false,
+                false);
+        Map<String, Object> resultMap = _converter.convertObjectToMap(engine, 
TestEngine.class, options);
+        Map<String, String> context = getContext(resultMap);
+        assertTrue("Unexpected size of context", context.size() >= 5);
+        assertEquals("Unexpected engine context content",
+                     CHILD_CONTEXT_PROPERTY_ACTUAL_VALUE,
+                     context.get(CHILD_CONTEXT_PROPERTY_NAME));
+        assertEquals("Unexpected car context content",
+                     PARENT_CONTEXT_PROPERTY1_ACTUAL_VALUE, 
context.get(PARENT_CONTEXT_PROPERTY1_NAME));
+        assertEquals("Unexpected car context content",
+                     PARENT_CONTEXT_PROPERTY2_ACTUAL_VALUE,
+                     context.get(PARENT_CONTEXT_PROPERTY2_NAME));
+        assertEquals("Unexpected system context content",
+                     TEST_SYSTEM_PROPERTY1_ACTUAL_VALUE,
+                     context.get(TEST_SYSTEM_PROPERTY1_NAME));
+        assertEquals("Unexpected system context content",
+                     TEST_SYSTEM_PROPERTY2_ACTUAL_VALUE,
+                     context.get(TEST_SYSTEM_PROPERTY2_NAME));
+    }
 
+    public void testExcludeInheritedContextAndEffective()
+    {
+        TestEngine engine = createEngineWithContext();
+        ConfiguredObjectToMapConverter.ConverterOptions options = new 
ConfiguredObjectToMapConverter.ConverterOptions(
+                1,
+                false,
+                false,
+                0,
+                false,
+                true);
+        Map<String, Object> resultMap = _converter.convertObjectToMap(engine, 
TestEngine.class, options);
+        Map<String, String> context = getContext(resultMap);
+        assertEquals("Unexpected size of context", 1, context.size());
+        assertEquals("Unexpected context content",
+                     CHILD_CONTEXT_PROPERTY_EFFECTIVE_VALUE,
+                     context.get(CHILD_CONTEXT_PROPERTY_NAME));
+    }
 
-        // set encoded value
-        final Map<String,String> context = new HashMap<>();
-        context.put("test", "testValue");
-        configureMockToReturnOneAttribute(mockChild, "context", context);
-        
when(mockChild.getContextKeys(anyBoolean())).thenReturn(context.keySet());
-        when(mockChild.getContextValue(String.class, 
"test")).thenReturn(context.get("test"));
-
-        final Map<String, String> parentContext = new HashMap<>();
-        parentContext.put("parentTest", "parentTestValue");
-        configureMockToReturnOneAttribute(_configuredObject, "context", 
parentContext);
-        
when(_configuredObject.getContextKeys(anyBoolean())).thenReturn(parentContext.keySet());
-        when(_configuredObject.getContextValue(String.class, 
"parentTest")).thenReturn(parentContext.get("parentTest"));
+    public void testExcludeInheritedContextAndActual()
+    {
+        TestEngine engine = createEngineWithContext();
+        ConfiguredObjectToMapConverter.ConverterOptions options = new 
ConfiguredObjectToMapConverter.ConverterOptions(
+                1,
+                true,
+                false,
+                0,
+                false,
+                true);
+        Map<String, Object> resultMap = _converter.convertObjectToMap(engine, 
TestEngine.class, options);
+        Map<String, String> context = getContext(resultMap);
+        assertEquals("Unexpected size of context", 1, context.size());
+        assertEquals("Unexpected context content",
+                     CHILD_CONTEXT_PROPERTY_ACTUAL_VALUE,
+                     context.get(CHILD_CONTEXT_PROPERTY_NAME));
+    }
 
-        Map<String, Object> resultMap = 
_converter.convertObjectToMap(mockChild,
-                                                                      
ConfiguredObject.class,
-                                                                      new 
ConfiguredObjectToMapConverter.ConverterOptions(
-                                                                              
1,
-                                                                              
false,
-                                                                              
false,
-                                                                              
0,
-                                                                              
false,
-                                                                              
false));
-        Object contextValue = resultMap.get("context");
+    private Map<String, String> getContext(final Map<String, Object> resultMap)
+    {
+        Object contextValue = resultMap.get(ConfiguredObject.CONTEXT);
         assertTrue("Unexpected type of context", contextValue instanceof Map);
-        assertEquals("Unexpected size of context", 2, 
((Map)contextValue).size());
-        assertEquals("Unexpected context content", "testValue", 
((Map)contextValue).get("test"));
-        assertEquals("Unexpected context content", "parentTestValue", 
((Map)contextValue).get("parentTest"));
+        Map<String, String> context = (Map<String, String>) contextValue;
+        return context;
+    }
 
-        resultMap = _converter.convertObjectToMap(mockChild,
-                                                  ConfiguredObject.class,
-                                                  new 
ConfiguredObjectToMapConverter.ConverterOptions(1,
-                                                                               
                       false,
-                                                                               
                       false,
-                                                                               
                       0,
-                                                                               
                       false,
-                                                                               
                       true));
-        contextValue = resultMap.get("context");
-        assertTrue("Unexpected type of context", contextValue instanceof Map);
-        assertEquals("Unexpected size of context", 1, 
((Map)contextValue).size());
-        assertEquals("Unexpected context content","testValue", 
((Map)contextValue).get("test"));*/
+    private TestEngine createEngineWithContext()
+    {
+        setTestSystemProperty(TEST_SYSTEM_PROPERTY1_NAME, 
TEST_SYSTEM_PROPERTY1_ACTUAL_VALUE);
+        setTestSystemProperty(TEST_SYSTEM_PROPERTY2_NAME, 
TEST_SYSTEM_PROPERTY2_ACTUAL_VALUE);
+        Model model = 
org.apache.qpid.server.model.testmodels.hierarchy.TestModel.getInstance();
+        final Map<String, Object> carAttributes = new HashMap<>();
+        carAttributes.put(ConfiguredObject.NAME, "myCar");
+        Map<String, String> carContext = new HashMap<>();
+        carContext.put(PARENT_CONTEXT_PROPERTY1_NAME, 
PARENT_CONTEXT_PROPERTY1_ACTUAL_VALUE);
+        carContext.put(PARENT_CONTEXT_PROPERTY2_NAME, 
PARENT_CONTEXT_PROPERTY2_ACTUAL_VALUE);
+        carAttributes.put(ConfiguredObject.CONTEXT, carContext);
+        TestCar car = model.getObjectFactory().create(TestCar.class, 
carAttributes);
+        final Map<String, Object> engineAttributes = new HashMap<>();
+        engineAttributes.put(ConfiguredObject.NAME, "myEngine");
+        engineAttributes.put(ConfiguredObject.TYPE, 
TestElecEngineImpl.TEST_ELEC_ENGINE_TYPE);
+        Map<String, String> engineContext = new HashMap<>();
+        engineContext.put(CHILD_CONTEXT_PROPERTY_NAME, 
CHILD_CONTEXT_PROPERTY_ACTUAL_VALUE);
+        engineAttributes.put(ConfiguredObject.CONTEXT, engineContext);
+        return (TestEngine) car.createChild(TestEngine.class, 
engineAttributes);
     }
 
     private Model createTestModel()

Modified: 
qpid/java/branches/6.0.x/systests/src/test/java/org/apache/qpid/systest/rest/BrokerRestTest.java
URL: 
http://svn.apache.org/viewvc/qpid/java/branches/6.0.x/systests/src/test/java/org/apache/qpid/systest/rest/BrokerRestTest.java?rev=1754984&r1=1754983&r2=1754984&view=diff
==============================================================================
--- 
qpid/java/branches/6.0.x/systests/src/test/java/org/apache/qpid/systest/rest/BrokerRestTest.java
 (original)
+++ 
qpid/java/branches/6.0.x/systests/src/test/java/org/apache/qpid/systest/rest/BrokerRestTest.java
 Tue Aug  2 17:30:27 2016
@@ -20,8 +20,10 @@
  */
 package org.apache.qpid.systest.rest;
 
+import java.io.IOException;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
@@ -51,6 +53,27 @@ public class BrokerRestTest extends Qpid
     private static final String BROKER_PORTS_ATTRIBUTE = "ports";
     private static final String BROKER_VIRTUALHOST_NODES_ATTRIBUTE = 
"virtualhostnodes";
     private static final String BROKER_STATISTICS_ATTRIBUTE = "statistics";
+    private static final String SYSTEM_PROPERTY_NAME = "qpid.rest.test.name";
+    private static final String SYSTEM_PROPERTY_ACTUAL_VALUE = 
"qpid.rest.test.name.value";
+    private static final String SYSTEM_PROPERTY2_NAME = "qpid.rest.test.var";
+    private static final String SYSTEM_PROPERTY2_ACTUAL_VALUE = 
"qpid.rest.test.name=${" + SYSTEM_PROPERTY_NAME + "}";
+    private static final String SYSTEM_PROPERTY2_EFFECTIVE_VALUE = 
"qpid.rest.test.name=" + SYSTEM_PROPERTY_ACTUAL_VALUE;
+    private static final String SYSTEM_PROPERTY3_NAME = "qpid.rest.test.var2";
+    private static final String SYSTEM_PROPERTY3_ACTUAL_VALUE = "${" + 
SYSTEM_PROPERTY2_NAME + "}2";
+    private static final String SYSTEM_PROPERTY3_EFFECTIVE_VALUE = 
SYSTEM_PROPERTY2_EFFECTIVE_VALUE + "2";
+
+    @Override
+    public void setUp() throws Exception
+    {
+        HashMap<String, String> _testSystemContext = new HashMap<>();
+        _testSystemContext.put(SYSTEM_PROPERTY_NAME, 
SYSTEM_PROPERTY_ACTUAL_VALUE);
+        _testSystemContext.put(SYSTEM_PROPERTY2_NAME, 
SYSTEM_PROPERTY2_ACTUAL_VALUE);
+        for (Map.Entry<String,String> testContextEntry: 
_testSystemContext.entrySet())
+        {
+            setSystemProperty(testContextEntry.getKey(), 
testContextEntry.getValue());
+        }
+        super.setUp();
+    }
 
     public void testGet() throws Exception
     {
@@ -177,6 +200,79 @@ public class BrokerRestTest extends Qpid
         exceptionListener.assertReceivedNoRouteWithReturnedMessage(message, 
getTestQueueName());
     }
 
+
+    public void testActualInheritedContext() throws IOException
+    {
+        Map<String, Object> brokerDetails =
+                
getRestTestHelper().getJsonAsSingletonList("broker?inheritedActuals=true&actuals=true");
+        Map<String, String> brokerContext = (Map<String, String>) 
brokerDetails.get(ConfiguredObject.CONTEXT);
+        assertEquals("Unexpected test context variable value",
+                     SYSTEM_PROPERTY_ACTUAL_VALUE,
+                     brokerContext.get(SYSTEM_PROPERTY_NAME));
+        assertEquals("Unexpected test context expression value",
+                     SYSTEM_PROPERTY2_ACTUAL_VALUE,
+                     brokerContext.get(SYSTEM_PROPERTY2_NAME));
+    }
+
+    public void testEffectiveInheritedContext() throws IOException
+    {
+        Map<String, Object> brokerDetails =
+                
getRestTestHelper().getJsonAsSingletonList("broker?inheritedActuals=false&actuals=false");
+        Map<String, String> brokerContext = (Map<String, String>) 
brokerDetails.get(ConfiguredObject.CONTEXT);
+        assertEquals("Unexpected test context variable value",
+                     SYSTEM_PROPERTY_ACTUAL_VALUE,
+                     brokerContext.get(SYSTEM_PROPERTY_NAME));
+        assertEquals("Unexpected test context expression value",
+                     SYSTEM_PROPERTY2_EFFECTIVE_VALUE,
+                     brokerContext.get(SYSTEM_PROPERTY2_NAME));
+    }
+
+    public void testActualNotInheritedContext() throws IOException
+    {
+        Map<String, Object> brokerDetails =
+                
getRestTestHelper().getJsonAsSingletonList("broker?excludeInheritedContext=true&actuals=true");
+
+        assertFalse("Unexpected context", 
brokerDetails.containsKey(ConfiguredObject.CONTEXT));
+
+        Map<String, Object> attributes = Collections.<String, 
Object>singletonMap(
+                ConfiguredObject.CONTEXT,
+                Collections.singletonMap(SYSTEM_PROPERTY3_NAME, 
SYSTEM_PROPERTY3_ACTUAL_VALUE));
+        getRestTestHelper().submitRequest("broker", "POST", attributes);
+
+        brokerDetails =
+                
getRestTestHelper().getJsonAsSingletonList("broker?excludeInheritedContext=true&actuals=true");
+        Map<String, Object> brokerContext =
+                new HashMap<>((Map<String, Object>) 
brokerDetails.get(ConfiguredObject.CONTEXT));
+        Map<String, String> expectedContext = new HashMap<>();
+        expectedContext.put(SYSTEM_PROPERTY3_NAME, 
SYSTEM_PROPERTY3_ACTUAL_VALUE);
+
+        assertEquals("Unexpected context", expectedContext, brokerContext);
+    }
+
+    public void testEffectiveNotInheritedContext() throws IOException
+    {
+        Map<String, Object> brokerDetails =
+                
getRestTestHelper().getJsonAsSingletonList("broker?excludeInheritedContext=true&actuals=false");
+
+        assertFalse("Unexpected context", 
brokerDetails.containsKey(ConfiguredObject.CONTEXT));
+
+        Map<String, Object> attributes = Collections.<String, 
Object>singletonMap(
+                ConfiguredObject.CONTEXT,
+                Collections.singletonMap(SYSTEM_PROPERTY3_NAME, 
SYSTEM_PROPERTY3_ACTUAL_VALUE));
+        getRestTestHelper().submitRequest("broker", "POST", attributes);
+
+        brokerDetails =
+                
getRestTestHelper().getJsonAsSingletonList("broker?excludeInheritedContext=true&actuals=false");
+
+        Map<String, String> expectedContext = new HashMap<>();
+        Map<String, Object> brokerContext =
+                new HashMap<>((Map<String, Object>) 
brokerDetails.get(ConfiguredObject.CONTEXT));
+
+        expectedContext.put(SYSTEM_PROPERTY3_NAME, 
SYSTEM_PROPERTY3_EFFECTIVE_VALUE);
+
+        assertEquals("Unexpected context", expectedContext, brokerContext);
+    }
+
     private Map<String, Object> getValidBrokerAttributes()
     {
         Map<String, Object> brokerAttributes = new HashMap<String, Object>();




---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to