[jboss-cvs] JBossAS SVN: r89131 - in branches/Branch_5_x: server/src/etc/conf/all and 6 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue May 19 16:18:53 EDT 2009
Author: scott.stark at jboss.org
Date: 2009-05-19 16:18:52 -0400 (Tue, 19 May 2009)
New Revision: 89131
Added:
branches/Branch_5_x/server/src/etc/conf/all/bindingservice.beans/
branches/Branch_5_x/server/src/etc/conf/minimal/bindingservice.beans/
branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/override/restart/test/ServiceBindingManagedObjectsTestCase.java
branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/override/test/ServiceBindingManagedObjectsTestCase.java
Removed:
branches/Branch_5_x/server/src/etc/conf/all/bindingservice.sar/
branches/Branch_5_x/server/src/etc/conf/minimal/bindingservice.sar/
Modified:
branches/Branch_5_x/build/build-distr.xml
branches/Branch_5_x/server/src/etc/conf/all/bootstrap/profile.xml
branches/Branch_5_x/server/src/etc/conf/default/bootstrap/profile.xml
branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ServiceBindingManagedObjectsTestCase.java
Log:
JBAS-6259, Use bindingservice.beans and update ServiceBindingManagedObjectsTestCase tests to validate persistence across restarts
Modified: branches/Branch_5_x/build/build-distr.xml
===================================================================
--- branches/Branch_5_x/build/build-distr.xml 2009-05-19 18:35:20 UTC (rev 89130)
+++ branches/Branch_5_x/build/build-distr.xml 2009-05-19 20:18:52 UTC (rev 89131)
@@ -1053,7 +1053,7 @@
</copy>
<!-- copy the service binding manager to it's deployment -->
- <copy todir="${install.server}/all/conf/bindingservice.sar">
+ <copy todir="${install.server}/all/conf/bindingservice.beans">
<fileset dir="${_module.output}/lib">
<include name="jboss-bindingservice.jar"/>
</fileset>
Copied: branches/Branch_5_x/server/src/etc/conf/all/bindingservice.beans (from rev 89127, branches/Branch_5_x/server/src/etc/conf/all/bindingservice.sar)
Modified: branches/Branch_5_x/server/src/etc/conf/all/bootstrap/profile.xml
===================================================================
--- branches/Branch_5_x/server/src/etc/conf/all/bootstrap/profile.xml 2009-05-19 18:35:20 UTC (rev 89130)
+++ branches/Branch_5_x/server/src/etc/conf/all/bootstrap/profile.xml 2009-05-19 20:18:52 UTC (rev 89131)
@@ -19,7 +19,7 @@
The uri to the deployers folder.
A list of uris to deploy folders. -->
<bean name="BootstrapProfileFactory" class="org.jboss.system.server.profileservice.StaticClusteredProfileFactory">
- <property name="bindingsURI">${jboss.server.home.url}conf/bindingservice.sar</property>
+ <property name="bindingsURI">${jboss.server.home.url}conf/bindingservice.beans</property>
<property name="bootstrapURI">${jboss.server.home.url}conf/jboss-service.xml</property>
<property name="deployersURI">${jboss.server.home.url}deployers</property>
<property name="applicationURIs">
Modified: branches/Branch_5_x/server/src/etc/conf/default/bootstrap/profile.xml
===================================================================
--- branches/Branch_5_x/server/src/etc/conf/default/bootstrap/profile.xml 2009-05-19 18:35:20 UTC (rev 89130)
+++ branches/Branch_5_x/server/src/etc/conf/default/bootstrap/profile.xml 2009-05-19 20:18:52 UTC (rev 89131)
@@ -19,7 +19,7 @@
The uri to the deployers folder.
A list of uris to deploy folders. -->
<bean name="BootstrapProfileFactory" class="org.jboss.system.server.profileservice.repository.StaticProfileFactory">
- <property name="bindingsURI">${jboss.server.home.url}conf/bindingservice.sar</property>
+ <property name="bindingsURI">${jboss.server.home.url}conf/bindingservice.beans</property>
<property name="bootstrapURI">${jboss.server.home.url}conf/jboss-service.xml</property>
<property name="deployersURI">${jboss.server.home.url}deployers</property>
<property name="applicationURIs">
Copied: branches/Branch_5_x/server/src/etc/conf/minimal/bindingservice.beans (from rev 89127, branches/Branch_5_x/server/src/etc/conf/minimal/bindingservice.sar)
Added: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/override/restart/test/ServiceBindingManagedObjectsTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/override/restart/test/ServiceBindingManagedObjectsTestCase.java (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/override/restart/test/ServiceBindingManagedObjectsTestCase.java 2009-05-19 20:18:52 UTC (rev 89131)
@@ -0,0 +1,631 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.profileservice.override.restart.test;
+
+import java.net.InetAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.deployers.spi.management.ManagementView;
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.ManagedCommon;
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.types.CompositeMetaType;
+import org.jboss.metatype.api.types.ImmutableCompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.ArrayValue;
+import org.jboss.metatype.api.values.CollectionValue;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.MapCompositeValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.services.binding.ServiceBindingMetadata;
+import org.jboss.services.binding.impl.ServiceBindingSet;
+import org.jboss.services.binding.managed.ServiceBindingMetadataMapper;
+import org.jboss.test.profileservice.test.AbstractProfileServiceTest;
+
+/**
+ * <p>
+ * Profile service ServiceBindingManager persistent update tests.
+ * </p>
+ *
+ * @see org.jboss.test.profileservice.override.test.ServiceBindingManagedObjectsTestCase
+ * for the tests that add and update the service binding metadata.
+ *
+ * @author Brian Stansberry
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 88921 $
+ */
+public class ServiceBindingManagedObjectsTestCase extends AbstractProfileServiceTest
+{
+ public static final CompositeMetaType SERVICE_BINDING_METADATA_TYPE;
+ public static final CompositeMetaType SERVICE_BINDING_SET_TYPE;
+
+ static
+ {
+ String[] itemNames = {
+ "bindingSetName",
+ "serviceName",
+ "bindingName",
+ "fullyQualifiedName",
+ "description",
+ "hostName",
+ "port",
+ "fixedHostName",
+ "fixedPort"//,
+// "serviceBindingValueSourceClassName",
+// "serviceBindingValueSourceConfig"
+ };
+ String[] itemDescriptions = {
+ "binding set to which this binding applies, or null for all sets",
+ "the name of the service to which this binding applies",
+ "a qualifier identifying which particular binding within the service this is",
+ "the fully qualified binding name",
+ "description of the binding",
+ "the host name or string notation IP address to use for the binding",
+ "the port to use for the binding",
+ "whether the host name should remain fixed in all binding sets",
+ "whether the port should remain fixed in all binding sets"//,
+// "fully qualified classname of specialized object used to process binding results",
+// ""
+ };
+ MetaType[] itemTypes = {
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.INTEGER_PRIMITIVE,
+ SimpleMetaType.BOOLEAN_PRIMITIVE,
+ SimpleMetaType.BOOLEAN_PRIMITIVE//,
+// SimpleMetaType.STRING,
+// new GenericMetaType(ManagedObject)
+ };
+ SERVICE_BINDING_METADATA_TYPE = new ImmutableCompositeMetaType(ServiceBindingMetadata.class.getName(),
+ "Service Binding Metadata",
+ itemNames, itemDescriptions, itemTypes);
+
+
+ String[] itemNames2 = {
+ "name",
+ "defaultHostName",
+ "portOffset",
+ "overrideBindings"
+ };
+ String[] itemDescriptions2 = {
+ "the name of the binding set",
+ "the host name that should be used for all bindings whose configuration " +
+ "does not specify fixedHostName=\"true\"",
+ "value to add to the port configuration for a standard binding to " +
+ "derive the port to use in this binding set",
+ "binding configurations that apply only to this binding set, either " +
+ "non-standard bindings or ones that override standard binding configurations",
+ };
+ MetaType[] itemTypes2 = {
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.INTEGER_PRIMITIVE,
+ ServiceBindingMetadataMapper.TYPE
+ };
+ SERVICE_BINDING_SET_TYPE = new ImmutableCompositeMetaType(ServiceBindingSet.class.getName(),
+ "Service Binding Set", itemNames2, itemDescriptions2, itemTypes2);
+ }
+
+ /**
+ * <p>
+ * Creates an instance of {@code SecurityManagedObjectsTestCase} with the specified name.
+ * </p>
+ *
+ * @param name a {@code String} representing the name of this {@code TestCase}.
+ */
+ public ServiceBindingManagedObjectsTestCase(String name)
+ {
+ super(name);
+ }
+
+
+ private ManagedComponent getServiceBindingManagerManagedComponent() throws Exception
+ {
+ ManagementView managementView = getManagementView();
+ ComponentType type = new ComponentType("MCBean", "ServiceBindingManager");
+ ManagedComponent component = managementView.getComponent("ServiceBindingManager", type);
+ assertNotNull(component);
+ return component;
+ }
+
+ private void serviceBindingTest(MetaValue element)
+ {
+ getLog().info(element);
+
+ assertTrue(element instanceof CompositeValue);
+
+ CompositeValue compValue = (CompositeValue) element;
+
+ MetaValue metaval = compValue.get("serviceName");
+ assertNotNull("has serviceName", metaval);
+ assertTrue(metaval instanceof SimpleValue);
+ assertTrue(((SimpleValue) metaval).getValue() instanceof String);
+
+ metaval = compValue.get("bindingName");
+ if (metaval != null)
+ {
+ assertTrue(metaval instanceof SimpleValue);
+ Object val = ((SimpleValue) metaval).getValue();
+ assertTrue(val instanceof String);
+ }
+
+ metaval = compValue.get("fullyQualifiedName");
+ assertNotNull("has fullyQualifiedName", metaval);
+ assertTrue(metaval instanceof SimpleValue);
+ assertTrue(((SimpleValue) metaval).getValue() instanceof String);
+
+ metaval = compValue.get("description");
+ if (metaval != null)
+ {
+ assertTrue(metaval instanceof SimpleValue);
+ Object val = ((SimpleValue) metaval).getValue();
+ assertTrue(val instanceof String);
+ }
+
+ metaval = compValue.get("hostName");
+ assertNotNull("has hostName", metaval);
+ assertTrue(metaval instanceof SimpleValue);
+ assertTrue(((SimpleValue) metaval).getValue() instanceof String);
+
+ metaval = compValue.get("bindAddress");
+ assertNotNull("has bindAddress", metaval);
+ assertTrue(metaval instanceof ArrayValue);
+ Object val = ((ArrayValue) metaval).getValue();
+ assertTrue(val instanceof byte[]);
+
+ metaval = compValue.get("port");
+ assertNotNull("has port", metaval);
+ assertTrue(metaval instanceof SimpleValue);
+ assertEquals("type of port value isn't int", int.class.getName(), metaval.getMetaType().getClassName());
+ }
+
+ private void serviceBindingSetTest(MetaValue metaValue, Map<String, Integer> offsets) throws Exception
+ {
+ assertTrue(metaValue instanceof CompositeValue);
+ CompositeValue bindingSet = (CompositeValue) metaValue;
+
+ MetaValue val = bindingSet.get("name");
+ assertNotNull("property name has no value", val);
+ assertTrue("property name value is SimpleValue", val instanceof SimpleValue);
+ Object simpleVal = ((SimpleValue) val).getValue();
+ assertTrue(simpleVal instanceof String);
+ String name = (String) simpleVal;
+
+ val = bindingSet.get("defaultHostName");
+ assertNotNull("property defaultHostName has no value", val);
+ assertEquals("type of defaultHostName value isn't String", String.class.getName(), val.getMetaType().getClassName());
+ assertTrue("property defaultHostName value is SimpleValue", val instanceof SimpleValue);
+ assertEquals(InetAddress.getByName(getServerHost()), InetAddress.getByName((String) ((SimpleValue) val).getValue()));
+
+ val = bindingSet.get("portOffset");
+ assertNotNull("property portOffset has no value", val);
+ assertTrue("property portOffset value is SimpleValue", val instanceof SimpleValue);
+ simpleVal = ((SimpleValue) val).getValue();
+ assertTrue(simpleVal instanceof Integer);
+ assertTrue(((Integer) simpleVal).intValue() > -1);
+ offsets.put(name, (Integer) simpleVal);
+
+ val = bindingSet.get("overrideBindings");
+ assertNotNull("property overrideBindings has no value", val);
+ assertTrue("property overrideBindings value is CollectionValue", val instanceof CollectionValue);
+ MetaValue[] elements = ((CollectionValue) val).getElements();
+ getLog().info(elements);
+ for (MetaValue element : elements)
+ {
+ serviceBindingMetadataTest(element);
+ }
+
+ }
+
+ private Checked serviceBindingMetadataTest(MetaValue metaValue)
+ {
+ assertTrue(metaValue instanceof CompositeValue);
+ CompositeValue bindingMetadata = (CompositeValue) metaValue;
+
+ Checked result = new Checked();
+
+ MetaValue val = bindingMetadata.get("fullyQualifiedName");
+ assertNotNull("property fullyQualifiedName has no value", val);
+ assertTrue("property fullyQualifiedName value is SimpleValue", val instanceof SimpleValue);
+ assertNotNull("property fullyQualifiedName value is not null", ((SimpleValue) val).getValue());
+
+ val = bindingMetadata.get("serviceName");
+ assertNotNull("property serviceName has no value", val);
+ assertTrue("property serviceName value is SimpleValue", val instanceof SimpleValue);
+ assertNotNull("property serviceName value is not null", ((SimpleValue) val).getValue());
+
+ val = bindingMetadata.get("bindingName");
+ if (val != null)
+ {
+ result.bindingName = true;
+ assertNotNull("property bindingName has no value", val);
+ assertTrue("property bindingName value is SimpleValue", val instanceof SimpleValue);
+ assertEquals("type of bindingName value isn't String", String.class.getName(), val.getMetaType().getClassName());
+ }
+
+ val = bindingMetadata.get("bindingSetName");
+ if (val != null)
+ {
+ assertNotNull("property bindingSetName has no value", val);
+ assertTrue("property bindingSetName value is SimpleValue", val instanceof SimpleValue);
+ assertEquals("type of bindingSetName value isn't String", String.class.getName(), val.getMetaType().getClassName());
+ }
+
+ val = bindingMetadata.get("hostName");
+ if (val != null)
+ {
+ result.hostname = true;
+ assertTrue("property hostName value is SimpleValue", val instanceof SimpleValue);
+ assertEquals("type of hostName value isn't String", String.class.getName(), val.getMetaType().getClassName());
+ }
+
+ val = bindingMetadata.get("port");
+ assertNotNull("property port has no value", val);
+ assertTrue("property port value is SimpleValue", val instanceof SimpleValue);
+ assertNotNull("property port value is not null", ((SimpleValue) val).getValue());
+ assertEquals("type of port value isn't int", int.class.getName(), val.getMetaType().getClassName());
+ assertNotNull("property port value is not null", ((SimpleValue) val).getValue());
+
+ val = bindingMetadata.get("description");
+ if (val != null)
+ {
+ result.hostname = true;
+ assertNotNull("property hostName has no value", val);
+ assertTrue("property description value is SimpleValue", val instanceof SimpleValue);
+ assertEquals("type of description value isn't String", String.class.getName(), val.getMetaType().getClassName());
+ }
+
+ val = bindingMetadata.get("fixedPort");
+ assertNotNull("property bindingName has no value", val);
+ assertTrue("property bindingName value is SimpleValue", val instanceof SimpleValue);
+ assertNotNull("property bindingName value is not null", ((SimpleValue) val).getValue());
+ assertEquals("type of bindingName value isn't boolean", boolean.class.getName(), val.getMetaType().getClassName());
+ assertNotNull("property bindingName value is not null", ((SimpleValue) val).getValue());
+
+ val = bindingMetadata.get("fixedHostName");
+ assertNotNull("property bindingName has no value", val);
+ assertTrue("property bindingName value is SimpleValue", val instanceof SimpleValue);
+ assertNotNull("property bindingName value is not null", ((SimpleValue) val).getValue());
+ assertEquals("type of bindingName value isn't boolean", boolean.class.getName(), val.getMetaType().getClassName());
+ assertNotNull("property bindingName value is not null", ((SimpleValue) val).getValue());
+
+ return result;
+ }
+
+ public void testUpdatedStandardBindings() throws Exception
+ {
+ ManagedComponent component = getServiceBindingManagerManagedComponent();
+
+ logHierarchy(component);
+
+ Map<String, ManagedProperty> properties = component.getProperties();
+ assertNotNull(properties);
+
+ ManagedProperty prop = properties.get("standardBindings");
+
+ // Before passing the updated component back, store some info about
+ // the binding sets so we can use it later
+ prop = properties.get("bindingSets");
+ assertNotNull("Missing property bindingSets", prop);
+ MetaValue val = prop.getValue();
+ assertNotNull("property bindingSets has no value", val);
+ assertTrue("property bindingSets value is CollectionValue", val instanceof CollectionValue);
+ MetaValue[] elements = ((CollectionValue) val).getElements();
+ assertNotNull(elements);
+
+ // C) Validate update from B)
+
+ component = getServiceBindingManagerManagedComponent();
+ properties = component.getProperties();
+
+ Map<String, Integer> offsets = new HashMap<String, Integer>();
+ Map<String, String> hosts = new HashMap<String, String>();
+ for (MetaValue mv : elements)
+ {
+ String name = getSimpleValue(mv, "name", String.class);
+ offsets.put(name, getSimpleValue(mv, "portOffset", Integer.class));
+ hosts.put(name, getSimpleValue(mv, "defaultHostName", String.class));
+ }
+ IndexedArray indexedArray = checkAddedBinding(properties, 25, 23456, offsets, hosts);
+
+ }
+
+ private IndexedArray checkAddedBinding(Map<String, ManagedProperty> properties, int bindingCount, int basePort, Map<String, Integer> offsets, Map<String, String> hosts)
+ {
+ // Return the array of standard bindings + the pos of the added binding
+ IndexedArray result = new IndexedArray();
+
+ // Scan for the standard binding
+
+ ManagedProperty prop = properties.get("standardBindings");
+ assertNotNull("Missing property standardBindings", prop);
+ MetaValue val = prop.getValue();
+ assertNotNull("property standardBindings has no value", val);
+ assertTrue("property standardBindings value is CollectionValue", val instanceof CollectionValue);
+ MetaValue[] refreshedElements = ((CollectionValue) val).getElements();
+ assertEquals(bindingCount, refreshedElements.length);
+ result.array = refreshedElements; // pass back to caller
+ boolean sawAdded = false;
+ for (int i = 0; i < refreshedElements.length; i++)
+ {
+ MetaValue mv = refreshedElements[i];
+ if ("AddedStandardBinding".equals(getSimpleValue(mv, "serviceName")))
+ {
+ sawAdded = true;
+ assertEquals("correct bindingName in standard binding", "bindingName", getSimpleValue(mv, "bindingName"));
+ assertEquals("correct description in standard binding", "description", getSimpleValue(mv, "description"));
+ assertNull("correct hostName in standardBinding", getSimpleValue(mv, "hostName"));
+ assertEquals("correct port in standard binding", basePort, getSimpleValue(mv, "port", Integer.class).intValue());
+ assertFalse("correct fixedPort in standard binding", getSimpleValue(mv, "fixedPort", Boolean.class).booleanValue());
+ assertFalse("correct fixedHostName in standard binding", getSimpleValue(mv, "fixedHostName", Boolean.class).booleanValue());
+
+ result.index = i; // tell caller which pos has the added binding
+ break;
+ }
+ }
+ assertTrue("saw standard binding", sawAdded);
+
+ // Check that our standard binding metadata generated the expected actual bindings
+
+ prop = properties.get("serviceBindings");
+ assertNotNull("Missing property serviceBindings", prop);
+ log.info("serviceBindings: " + prop);
+ val = prop.getValue();
+ assertNotNull("property serviceBindings has no value", val);
+ assertTrue("property serviceBindings value is CompositeValue", val instanceof CompositeValue);
+ CompositeValue compVal = (CompositeValue) val;
+ assertEquals("correct number of standard bindings", offsets.size(), compVal.values().size());
+ for (String bindingSetName : offsets.keySet())
+ {
+ MetaValue mv = compVal.get(bindingSetName);
+ assertTrue(mv instanceof CollectionValue);
+ CollectionValue colVal = (CollectionValue) mv;
+ sawAdded = false;
+ for (MetaValue element : colVal.getElements())
+ {
+ if ("AddedStandardBinding".equals(getSimpleValue(element, "serviceName")))
+ {
+ sawAdded = true;
+ assertEquals("correct bindingName in set " + bindingSetName,
+ "bindingName", getSimpleValue(element, "bindingName"));
+ assertEquals("correct description in set " + bindingSetName,
+ "description", getSimpleValue(element, "description"));
+ assertEquals("correct hostName in set " + bindingSetName,
+ hosts.get(bindingSetName), getSimpleValue(element, "hostName"));
+ assertEquals("correct port in set " + bindingSetName,
+ basePort + offsets.get(bindingSetName).intValue(),
+ getSimpleValue(element, "port", Integer.class).intValue());
+ break;
+ }
+ }
+ assertTrue("saw AddedStandardBinding in set " + bindingSetName, sawAdded);
+ }
+
+ return result;
+ }
+
+ public void testUpdatedServiceBindingSets() throws Exception
+ {
+ ManagedComponent component = getServiceBindingManagerManagedComponent();
+
+ logHierarchy(component);
+
+ Map<String, ManagedProperty> properties = component.getProperties();
+ assertNotNull(properties);
+
+
+ // Before updating get a ref to the standard bindings so we can use it
+ // in later validation
+ Map<String, MetaValue> standardBindings = new HashMap<String, MetaValue>();
+ ManagedProperty prop = properties.get("standardBindings");
+ assertNotNull("Missing property standardBindings", prop);
+ MetaValue val = prop.getValue();
+ assertNotNull("property standardBindings has no value", val);
+ assertTrue("property standardBindings value is CollectionValue", val instanceof CollectionValue);
+ MetaValue[] elements = ((CollectionValue) val).getElements();
+ assertNotNull("property standardBindings value has elements", elements);
+ for (MetaValue mv : elements)
+ {
+ standardBindings.put(getSimpleValue(mv, "fullyQualifiedName", String.class), mv);
+ }
+
+ // B) Validate the addition from A) took effect and then UPDATE the added binding set
+ IndexedArray indexedArray = checkAddedBindingSet(properties, 5, 400, 43210, standardBindings);
+ }
+
+ private IndexedArray checkAddedBindingSet(Map<String, ManagedProperty> properties, int numSets, int portOffset, int overrideBindingPort,
+ Map<String, MetaValue> standardBindings)
+ {
+ IndexedArray result = new IndexedArray();
+
+ // First confirm the expected binding set is there
+
+ ManagedProperty prop = properties.get("bindingSets");
+ assertNotNull("Missing property bindingSets", prop);
+ MetaValue val = prop.getValue();
+ assertNotNull("property bindingSets has no value", val);
+ assertTrue("property bindingSets value is CollectionValue", val instanceof CollectionValue);
+ MetaValue[] elements = ((CollectionValue) val).getElements();
+ assertNotNull(elements);
+ assertEquals(numSets, elements.length);
+ result.array = elements;
+ boolean sawAdded = false;
+ for (int i = 0; i < elements.length; i++)
+ {
+ MetaValue mv = elements[i];
+ if ("ports-test".equals(getSimpleValue(mv, "name")))
+ {
+ sawAdded = true;
+ assertEquals("added binding set has correct defaultHostName",
+ "localhost", getSimpleValue(mv, "defaultHostName"));
+ assertEquals("added binding set has correct portOffset",
+ portOffset, getSimpleValue(mv, "portOffset", Integer.class).intValue());
+ MetaValue overVal = ((CompositeValue) mv).get("overrideBindings");
+ assertTrue(overVal instanceof CollectionValue);
+ MetaValue[] overrides = ((CollectionValue) overVal).getElements();
+ assertNotNull("added binding set has overrides", overrides);
+ assertEquals("added binding set has correct # of overrides", 1, overrides.length);
+ mv = overrides[0];
+ assertEquals("added binding set has AddedOverrideBinding",
+ "AddedOverrideBinding", getSimpleValue(mv, "serviceName"));
+ assertNull("AddedOverrideBinding has null bindingName",
+ getSimpleValue(mv, "bindingName"));
+ assertEquals("AddedOverrideBinding has correct description",
+ "description", getSimpleValue(mv, "description"));
+ assertNull("AddedOverrideBinding has null hostName",
+ getSimpleValue(mv, "hostName"));
+ assertEquals("AddedOverrideBinding has correct port",
+ overrideBindingPort, getSimpleValue(mv, "port", Integer.class).intValue());
+ assertFalse("AddedOverrideBinding has correct fixedHostName",
+ getSimpleValue(mv, "fixedHostName", Boolean.class).booleanValue());
+ assertFalse("AddedOverrideBinding has correct fixedPort",
+ getSimpleValue(mv, "fixedPort", Boolean.class).booleanValue());
+ result.index = i;
+ break;
+ }
+ }
+ assertTrue(sawAdded);
+
+ // Next validate the expected actual bindings are there
+ prop = properties.get("serviceBindings");
+ assertNotNull("Missing property serviceBindings", prop);
+ val = prop.getValue();
+ assertNotNull("property serviceBindings has no value", val);
+ assertTrue("property serviceBindings value is Composite", val instanceof CompositeValue);
+ val = ((CompositeValue) val).get("ports-test");
+ assertNotNull(val);
+ assertTrue("property serviceBindings value is CollectionValue", val instanceof CollectionValue);
+ elements = ((CollectionValue) val).getElements();
+ assertNotNull("property serviceBindings value has elements", elements);
+ assertEquals("property serviceBindings value has correct # of elements",
+ standardBindings.size() + 1, elements.length);
+ for (MetaValue mv : elements)
+ {
+ String fqn = getSimpleValue(mv, "fullyQualifiedName", String.class);
+ if ("AddedOverrideBinding".equals(fqn))
+ {
+ assertEquals("actual AddedOverrideBinding has correct serviceName",
+ "AddedOverrideBinding", getSimpleValue(mv, "serviceName"));
+ assertNull("actual AddedOverrideBinding has null bindingName",
+ getSimpleValue(mv, "bindingName"));
+ assertEquals("actual AddedOverrideBinding has correct description",
+ "description", getSimpleValue(mv, "description"));
+ assertEquals("actual AddedOverrideBinding has correct port",
+ overrideBindingPort + portOffset, getSimpleValue(mv, "port", Integer.class).intValue());
+ assertEquals("actual AddedOverrideBinding has correct hostName",
+ "localhost", getSimpleValue(mv, "hostName"));
+ }
+ else
+ {
+ MetaValue standard = standardBindings.get(fqn);
+ assertNotNull(standard);
+ assertEquals("standardBinding " + fqn + " has correct serviceName",
+ getSimpleValue(standard, "serviceName"), getSimpleValue(mv, "serviceName"));
+ assertEquals("standardBinding " + fqn + " has correct bindingName",
+ getSimpleValue(standard, "bindingName"), getSimpleValue(mv, "bindingName"));
+ assertEquals("standardBinding " + fqn + " has correct description",
+ getSimpleValue(standard, "description"), getSimpleValue(mv, "description"));
+ int offset = getSimpleValue(standard, "fixedPort", Boolean.class).booleanValue() ? 0 : portOffset;
+ assertEquals("standardBinding " + fqn + " has correct port",
+ getSimpleValue(standard, "port", Integer.class).intValue() + offset,
+ getSimpleValue(mv, "port", Integer.class).intValue());
+ String host = getSimpleValue(standard, "fixedHostName", Boolean.class).booleanValue()
+ ? getSimpleValue(standard, "hostName", String.class)
+ : "localhost";
+ assertEquals("standardBinding " + fqn + " has correct hostName",
+ host, getSimpleValue(mv, "hostName"));
+ }
+ }
+
+ return result;
+ }
+
+ private void logHierarchy(ManagedComponent mc)
+ {
+ ManagedCommon child = mc;
+ ManagedCommon mcom = mc.getParent();
+ while (mcom != null)
+ {
+ log.debug("parent of " + child.getName() + " is " + mcom.getName());
+ child = mcom;
+ mcom = mcom.getParent();
+ }
+ }
+
+ private Object getSimpleValue(MetaValue val, String key)
+ {
+ return getSimpleValue(val, key, Object.class);
+ }
+
+ private <T> T getSimpleValue(MetaValue val, String key, Class<T> type)
+ {
+ T result = null;
+ assertTrue(val instanceof CompositeValue);
+ CompositeValue cval = (CompositeValue) val;
+ MetaValue mv = cval.get(key);
+ if (mv != null)
+ {
+ assertTrue(mv instanceof SimpleValue);
+ Object obj = ((SimpleValue) mv).getValue();
+ result = type.cast(obj);
+ }
+ return result;
+ }
+
+ private static MapCompositeValueSupport cloneCompositeValue(CompositeValue toClone)
+ {
+ if (toClone instanceof MapCompositeValueSupport)
+ {
+ return (MapCompositeValueSupport) toClone.clone();
+ }
+ else
+ {
+ CompositeMetaType type = toClone.getMetaType();
+ Map<String, MetaValue> map = new HashMap<String, MetaValue>();
+ for (String key : type.keySet())
+ {
+ map.put(key, toClone.get(key));
+ }
+ return new MapCompositeValueSupport(map, type);
+ }
+ }
+
+ private class Checked
+ {
+ private boolean hostname;
+ private boolean bindingName;
+ }
+
+ private class IndexedArray
+ {
+ int index;
+ MetaValue[] array;
+ }
+}
Added: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/override/test/ServiceBindingManagedObjectsTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/override/test/ServiceBindingManagedObjectsTestCase.java (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/override/test/ServiceBindingManagedObjectsTestCase.java 2009-05-19 20:18:52 UTC (rev 89131)
@@ -0,0 +1,607 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.profileservice.override.test;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.deployers.spi.management.ManagementView;
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.ManagedCommon;
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.types.CollectionMetaType;
+import org.jboss.metatype.api.types.CompositeMetaType;
+import org.jboss.metatype.api.types.ImmutableCompositeMetaType;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.CollectionValue;
+import org.jboss.metatype.api.values.CollectionValueSupport;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.MapCompositeValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.services.binding.ServiceBindingMetadata;
+import org.jboss.services.binding.impl.ServiceBindingSet;
+import org.jboss.services.binding.managed.ServiceBindingMetadataMapper;
+
+/**
+ * <p>
+ * Profile service ServiceBindingManager update tests.
+ * </p>
+ * @see org.jboss.test.profileservice.override.restart.test.ServiceBindingManagedObjectsTestCase
+ * for the tests of the persisted updates.
+ *
+ * @author Brian Stansberry
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 88921 $
+ */
+public class ServiceBindingManagedObjectsTestCase extends AbstractProfileServiceTest
+{
+ public static final CompositeMetaType SERVICE_BINDING_METADATA_TYPE;
+ public static final CompositeMetaType SERVICE_BINDING_SET_TYPE;
+
+ static
+ {
+ String[] itemNames = {
+ "bindingSetName",
+ "serviceName",
+ "bindingName",
+ "fullyQualifiedName",
+ "description",
+ "hostName",
+ "port",
+ "fixedHostName",
+ "fixedPort"//,
+// "serviceBindingValueSourceClassName",
+// "serviceBindingValueSourceConfig"
+ };
+ String[] itemDescriptions = {
+ "binding set to which this binding applies, or null for all sets",
+ "the name of the service to which this binding applies",
+ "a qualifier identifying which particular binding within the service this is",
+ "the fully qualified binding name",
+ "description of the binding",
+ "the host name or string notation IP address to use for the binding",
+ "the port to use for the binding",
+ "whether the host name should remain fixed in all binding sets",
+ "whether the port should remain fixed in all binding sets"//,
+// "fully qualified classname of specialized object used to process binding results",
+// ""
+ };
+ MetaType[] itemTypes = {
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.INTEGER_PRIMITIVE,
+ SimpleMetaType.BOOLEAN_PRIMITIVE,
+ SimpleMetaType.BOOLEAN_PRIMITIVE//,
+// SimpleMetaType.STRING,
+// new GenericMetaType(ManagedObject)
+ };
+ SERVICE_BINDING_METADATA_TYPE = new ImmutableCompositeMetaType(ServiceBindingMetadata.class.getName(),
+ "Service Binding Metadata",
+ itemNames, itemDescriptions, itemTypes);
+
+
+ String[] itemNames2 = {
+ "name",
+ "defaultHostName",
+ "portOffset",
+ "overrideBindings"
+ };
+ String[] itemDescriptions2 = {
+ "the name of the binding set",
+ "the host name that should be used for all bindings whose configuration " +
+ "does not specify fixedHostName=\"true\"",
+ "value to add to the port configuration for a standard binding to " +
+ "derive the port to use in this binding set",
+ "binding configurations that apply only to this binding set, either " +
+ "non-standard bindings or ones that override standard binding configurations",
+ };
+ MetaType[] itemTypes2 = {
+ SimpleMetaType.STRING,
+ SimpleMetaType.STRING,
+ SimpleMetaType.INTEGER_PRIMITIVE,
+ ServiceBindingMetadataMapper.TYPE
+ };
+ SERVICE_BINDING_SET_TYPE = new ImmutableCompositeMetaType(ServiceBindingSet.class.getName(),
+ "Service Binding Set", itemNames2, itemDescriptions2, itemTypes2);
+ }
+
+ /**
+ * <p>
+ * Creates an instance of {@code SecurityManagedObjectsTestCase} with the specified name.
+ * </p>
+ *
+ * @param name a {@code String} representing the name of this {@code TestCase}.
+ */
+ public ServiceBindingManagedObjectsTestCase(String name)
+ {
+ super(name);
+ }
+
+ private ManagedComponent getServiceBindingManagerManagedComponent() throws Exception
+ {
+ ManagementView managementView = getManagementView();
+ ComponentType type = new ComponentType("MCBean", "ServiceBindingManager");
+ ManagedComponent component = managementView.getComponent("ServiceBindingManager", type);
+ assertNotNull(component);
+ return component;
+ }
+
+ public void testUpdateServiceBindingSets() throws Exception
+ {
+ ManagedComponent component = getServiceBindingManagerManagedComponent();
+
+ logHierarchy(component);
+
+ Map<String, ManagedProperty> properties = component.getProperties();
+ assertNotNull(properties);
+
+ // A) ADD a new binding set
+
+ ManagedProperty prop = properties.get("bindingSets");
+ assertNotNull("Missing property bindingSets", prop);
+ MetaValue val = prop.getValue();
+ assertNotNull("property bindingSets has no value", val);
+ assertTrue("property bindingSets value is CollectionValue", val instanceof CollectionValue);
+ MetaValue[] origElements = ((CollectionValue) val).getElements();
+ assertNotNull(origElements);
+ MetaValue[] newElements = new MetaValue[origElements.length + 1];
+ System.arraycopy(origElements, 0, newElements, 0, origElements.length);
+
+
+ Map<String, MetaValue> map = new HashMap<String, MetaValue>();
+ map.put("name", SimpleValueSupport.wrap("ports-test"));
+ map.put("defaultHostName", SimpleValueSupport.wrap("localhost"));
+ map.put("portOffset", SimpleValueSupport.wrap(500));
+
+ Map<String, MetaValue> metadata = new HashMap<String, MetaValue>();
+ metadata.put("serviceName", SimpleValueSupport.wrap("AddedOverrideBinding"));
+ metadata.put("description", SimpleValueSupport.wrap("description"));
+ metadata.put("port", SimpleValueSupport.wrap(54321));
+ MapCompositeValueSupport newMetadata = new MapCompositeValueSupport(metadata, SERVICE_BINDING_METADATA_TYPE);
+ CollectionValue overrides = new CollectionValueSupport(new CollectionMetaType(Set.class.getName(), SERVICE_BINDING_METADATA_TYPE), new MetaValue[]{newMetadata});
+
+ map.put("overrideBindings", overrides);
+ MapCompositeValueSupport newElement = new MapCompositeValueSupport(map, SERVICE_BINDING_SET_TYPE);
+ newElements[newElements.length - 1] = newElement;
+ CollectionValue newVal = new CollectionValueSupport(new CollectionMetaType(Set.class.getName(), SERVICE_BINDING_SET_TYPE), newElements);
+ prop.setValue(newVal);
+
+ // Before updating get a ref to the standard bindings so we can use it
+ // in later validation
+ Map<String, MetaValue> standardBindings = new HashMap<String, MetaValue>();
+ prop = properties.get("standardBindings");
+ assertNotNull("Missing property standardBindings", prop);
+ val = prop.getValue();
+ assertNotNull("property standardBindings has no value", val);
+ assertTrue("property standardBindings value is CollectionValue", val instanceof CollectionValue);
+ MetaValue[] elements = ((CollectionValue) val).getElements();
+ assertNotNull("property standardBindings value has elements", elements);
+ for (MetaValue mv : elements)
+ {
+ standardBindings.put(getSimpleValue(mv, "fullyQualifiedName", String.class), mv);
+ }
+
+ try
+ {
+ getManagementView().updateComponent(component);
+ }
+ catch (Exception e)
+ {
+ log.error("Failed updating " + component, e);
+ throw e;
+ }
+
+ // B) Validate the addition from A) took effect and then UPDATE the added binding set
+
+ component = getServiceBindingManagerManagedComponent();
+ properties = component.getProperties();
+ assertNotNull(properties);
+
+ IndexedArray indexedArray = checkAddedBindingSet(properties, newElements.length, 500, 54321, standardBindings);
+
+ prop = properties.get("bindingSets");
+ assertNotNull("Missing property bindingSets", prop);
+ val = prop.getValue();
+ assertNotNull("property bindingSets has no value", val);
+ assertTrue("property bindingSets value is CollectionValue", val instanceof CollectionValue);
+ MetaValue[] updated = newElements.clone();
+ MapCompositeValueSupport updatedBindingSet = cloneCompositeValue((CompositeValue) updated[indexedArray.index]);
+ updatedBindingSet.put("portOffset", SimpleValueSupport.wrap(400));
+
+ MetaValue[] updatedOverrides = ((CollectionValue) updatedBindingSet.get("overrideBindings")).getElements();
+ assertEquals("single override binding", 1, updatedOverrides.length);
+ MapCompositeValueSupport updatedOverride = cloneCompositeValue((CompositeValue) updatedOverrides[0]);
+ updatedOverride.put("port", SimpleValueSupport.wrap(43210));
+ updatedBindingSet.put("overrideBindings", new CollectionValueSupport(new CollectionMetaType(Set.class.getName(), SERVICE_BINDING_METADATA_TYPE), new MetaValue[]{updatedOverride}));
+
+ updated[indexedArray.index] = updatedBindingSet;
+ newVal = new CollectionValueSupport(new CollectionMetaType(Set.class.getName(), SERVICE_BINDING_SET_TYPE), updated);
+ prop.setValue(newVal);
+
+ try
+ {
+ getManagementView().updateComponent(component);
+ }
+ catch (Exception e)
+ {
+ log.error("Failed updating " + component, e);
+ throw e;
+ }
+
+ // C) Validate the update from B) took effect
+
+ component = getServiceBindingManagerManagedComponent();
+ properties = component.getProperties();
+ assertNotNull(properties);
+
+ indexedArray = checkAddedBindingSet(properties, newElements.length, 400, 43210, standardBindings);
+ }
+
+
+ public void testUpdateStandardBindings() throws Exception
+ {
+ ManagedComponent component = getServiceBindingManagerManagedComponent();
+
+ logHierarchy(component);
+
+ Map<String, ManagedProperty> properties = component.getProperties();
+ assertNotNull(properties);
+
+ ManagedProperty prop = properties.get("standardBindings");
+ assertNotNull("Missing property standardBindings", prop);
+ MetaValue val = prop.getValue();
+ assertNotNull("property standardBindings has no value", val);
+ assertTrue("property standardBindings value is CollectionValue", val instanceof CollectionValue);
+
+ MetaValue[] origElements = ((CollectionValue) val).getElements();
+ assertNotNull(origElements);
+
+ // A) ADD a new element to "standardBindings"
+
+ MetaValue[] newElements = new MetaValue[origElements.length + 1];
+ System.arraycopy(origElements, 0, newElements, 0, origElements.length);
+
+ Map<String, MetaValue> map = new HashMap<String, MetaValue>();
+ map.put("serviceName", SimpleValueSupport.wrap("AddedStandardBinding"));
+ map.put("bindingName", SimpleValueSupport.wrap("bindingName"));
+ map.put("description", SimpleValueSupport.wrap("description"));
+ map.put("port", SimpleValueSupport.wrap(12345));
+ map.put("fixedHostName", SimpleValueSupport.wrap(false));
+ map.put("fixedPort", SimpleValueSupport.wrap(false));
+ MapCompositeValueSupport newElement = new MapCompositeValueSupport(map, SERVICE_BINDING_METADATA_TYPE);
+ newElements[newElements.length - 1] = newElement;
+
+ CollectionValue newVal = new CollectionValueSupport((CollectionMetaType) val.getMetaType(), newElements);
+ prop.setValue(newVal);
+
+ // Before passing the updated component back, store some info about
+ // the binding sets so we can use it later
+ prop = properties.get("bindingSets");
+ assertNotNull("Missing property bindingSets", prop);
+ val = prop.getValue();
+ assertNotNull("property bindingSets has no value", val);
+ assertTrue("property bindingSets value is CollectionValue", val instanceof CollectionValue);
+ MetaValue[] elements = ((CollectionValue) val).getElements();
+ assertNotNull(elements);
+
+ // Two maps we'll use
+ Map<String, Integer> offsets = new HashMap<String, Integer>();
+ Map<String, String> hosts = new HashMap<String, String>();
+ for (MetaValue mv : elements)
+ {
+ String name = getSimpleValue(mv, "name", String.class);
+ offsets.put(name, getSimpleValue(mv, "portOffset", Integer.class));
+ hosts.put(name, getSimpleValue(mv, "defaultHostName", String.class));
+ }
+
+ try
+ {
+ getManagementView().updateComponent(component);
+ }
+ catch (Exception e)
+ {
+ log.error("Failed updating " + component, e);
+ throw e;
+ }
+
+ // B) Validate the result of A) and MODIFY the element we added in A
+
+ component = getServiceBindingManagerManagedComponent();
+ properties = component.getProperties();
+
+ IndexedArray indexedArray = checkAddedBinding(properties, newElements.length, 12345, offsets, hosts);
+ // We'll update the component again using this MetaValue[]
+ newElements = new MetaValue[indexedArray.array.length];
+ System.arraycopy(indexedArray.array, 0, newElements, 0, newElements.length);
+
+ MapCompositeValueSupport update = cloneCompositeValue((CompositeValue) indexedArray.array[indexedArray.index]);
+ update.put("port", SimpleValueSupport.wrap(23456));
+ newElements[indexedArray.index] = update;
+
+ newVal = new CollectionValueSupport((CollectionMetaType) val.getMetaType(), newElements);
+ properties.get("standardBindings").setValue(newVal);
+
+ // OK, now update
+ try
+ {
+ getManagementView().updateComponent(component);
+ }
+ catch (Exception e)
+ {
+ log.error("Failed updating " + component, e);
+ throw e;
+ }
+
+ // C) Validate update from B) plus REMOVE the element we added
+
+ component = getServiceBindingManagerManagedComponent();
+ properties = component.getProperties();
+
+ indexedArray = checkAddedBinding(properties, newElements.length, 23456, offsets, hosts);
+ }
+
+ private IndexedArray checkAddedBindingSet(Map<String, ManagedProperty> properties, int numSets, int portOffset, int overrideBindingPort,
+ Map<String, MetaValue> standardBindings)
+ {
+ IndexedArray result = new IndexedArray();
+
+ // First confirm the expected binding set is there
+
+ ManagedProperty prop = properties.get("bindingSets");
+ assertNotNull("Missing property bindingSets", prop);
+ MetaValue val = prop.getValue();
+ assertNotNull("property bindingSets has no value", val);
+ assertTrue("property bindingSets value is CollectionValue", val instanceof CollectionValue);
+ MetaValue[] elements = ((CollectionValue) val).getElements();
+ assertNotNull(elements);
+ assertEquals(numSets, elements.length);
+ result.array = elements;
+ boolean sawAdded = false;
+ for (int i = 0; i < elements.length; i++)
+ {
+ MetaValue mv = elements[i];
+ if ("ports-test".equals(getSimpleValue(mv, "name")))
+ {
+ sawAdded = true;
+ assertEquals("added binding set has correct defaultHostName",
+ "localhost", getSimpleValue(mv, "defaultHostName"));
+ assertEquals("added binding set has correct portOffset",
+ portOffset, getSimpleValue(mv, "portOffset", Integer.class).intValue());
+ MetaValue overVal = ((CompositeValue) mv).get("overrideBindings");
+ assertTrue(overVal instanceof CollectionValue);
+ MetaValue[] overrides = ((CollectionValue) overVal).getElements();
+ assertNotNull("added binding set has overrides", overrides);
+ assertEquals("added binding set has correct # of overrides", 1, overrides.length);
+ mv = overrides[0];
+ assertEquals("added binding set has AddedOverrideBinding",
+ "AddedOverrideBinding", getSimpleValue(mv, "serviceName"));
+ assertNull("AddedOverrideBinding has null bindingName",
+ getSimpleValue(mv, "bindingName"));
+ assertEquals("AddedOverrideBinding has correct description",
+ "description", getSimpleValue(mv, "description"));
+ assertNull("AddedOverrideBinding has null hostName",
+ getSimpleValue(mv, "hostName"));
+ assertEquals("AddedOverrideBinding has correct port",
+ overrideBindingPort, getSimpleValue(mv, "port", Integer.class).intValue());
+ assertFalse("AddedOverrideBinding has correct fixedHostName",
+ getSimpleValue(mv, "fixedHostName", Boolean.class).booleanValue());
+ assertFalse("AddedOverrideBinding has correct fixedPort",
+ getSimpleValue(mv, "fixedPort", Boolean.class).booleanValue());
+ result.index = i;
+ break;
+ }
+ }
+ assertTrue(sawAdded);
+
+ // Next validate the expected actual bindings are there
+ prop = properties.get("serviceBindings");
+ assertNotNull("Missing property serviceBindings", prop);
+ val = prop.getValue();
+ assertNotNull("property serviceBindings has no value", val);
+ assertTrue("property serviceBindings value is Composite", val instanceof CompositeValue);
+ val = ((CompositeValue) val).get("ports-test");
+ assertNotNull(val);
+ assertTrue("property serviceBindings value is CollectionValue", val instanceof CollectionValue);
+ elements = ((CollectionValue) val).getElements();
+ assertNotNull("property serviceBindings value has elements", elements);
+ assertEquals("property serviceBindings value has correct # of elements",
+ standardBindings.size() + 1, elements.length);
+ for (MetaValue mv : elements)
+ {
+ String fqn = getSimpleValue(mv, "fullyQualifiedName", String.class);
+ if ("AddedOverrideBinding".equals(fqn))
+ {
+ assertEquals("actual AddedOverrideBinding has correct serviceName",
+ "AddedOverrideBinding", getSimpleValue(mv, "serviceName"));
+ assertNull("actual AddedOverrideBinding has null bindingName",
+ getSimpleValue(mv, "bindingName"));
+ assertEquals("actual AddedOverrideBinding has correct description",
+ "description", getSimpleValue(mv, "description"));
+ assertEquals("actual AddedOverrideBinding has correct port",
+ overrideBindingPort + portOffset, getSimpleValue(mv, "port", Integer.class).intValue());
+ assertEquals("actual AddedOverrideBinding has correct hostName",
+ "localhost", getSimpleValue(mv, "hostName"));
+ }
+ else
+ {
+ MetaValue standard = standardBindings.get(fqn);
+ assertNotNull(standard);
+ assertEquals("standardBinding " + fqn + " has correct serviceName",
+ getSimpleValue(standard, "serviceName"), getSimpleValue(mv, "serviceName"));
+ assertEquals("standardBinding " + fqn + " has correct bindingName",
+ getSimpleValue(standard, "bindingName"), getSimpleValue(mv, "bindingName"));
+ assertEquals("standardBinding " + fqn + " has correct description",
+ getSimpleValue(standard, "description"), getSimpleValue(mv, "description"));
+ int offset = getSimpleValue(standard, "fixedPort", Boolean.class).booleanValue() ? 0 : portOffset;
+ assertEquals("standardBinding " + fqn + " has correct port",
+ getSimpleValue(standard, "port", Integer.class).intValue() + offset,
+ getSimpleValue(mv, "port", Integer.class).intValue());
+ String host = getSimpleValue(standard, "fixedHostName", Boolean.class).booleanValue()
+ ? getSimpleValue(standard, "hostName", String.class)
+ : "localhost";
+ assertEquals("standardBinding " + fqn + " has correct hostName",
+ host, getSimpleValue(mv, "hostName"));
+ }
+ }
+
+ return result;
+ }
+
+ private IndexedArray checkAddedBinding(Map<String, ManagedProperty> properties, int bindingCount, int basePort, Map<String, Integer> offsets, Map<String, String> hosts)
+ {
+ // Return the array of standard bindings + the pos of the added binding
+ IndexedArray result = new IndexedArray();
+
+ // Scan for the standard binding
+
+ ManagedProperty prop = properties.get("standardBindings");
+ assertNotNull("Missing property standardBindings", prop);
+ MetaValue val = prop.getValue();
+ assertNotNull("property standardBindings has no value", val);
+ assertTrue("property standardBindings value is CollectionValue", val instanceof CollectionValue);
+ MetaValue[] refreshedElements = ((CollectionValue) val).getElements();
+ assertEquals(bindingCount, refreshedElements.length);
+ result.array = refreshedElements; // pass back to caller
+ boolean sawAdded = false;
+ for (int i = 0; i < refreshedElements.length; i++)
+ {
+ MetaValue mv = refreshedElements[i];
+ if ("AddedStandardBinding".equals(getSimpleValue(mv, "serviceName")))
+ {
+ sawAdded = true;
+ assertEquals("correct bindingName in standard binding", "bindingName", getSimpleValue(mv, "bindingName"));
+ assertEquals("correct description in standard binding", "description", getSimpleValue(mv, "description"));
+ assertNull("correct hostName in standardBinding", getSimpleValue(mv, "hostName"));
+ assertEquals("correct port in standard binding", basePort, getSimpleValue(mv, "port", Integer.class).intValue());
+ assertFalse("correct fixedPort in standard binding", getSimpleValue(mv, "fixedPort", Boolean.class).booleanValue());
+ assertFalse("correct fixedHostName in standard binding", getSimpleValue(mv, "fixedHostName", Boolean.class).booleanValue());
+
+ result.index = i; // tell caller which pos has the added binding
+ break;
+ }
+ }
+ assertTrue("saw standard binding", sawAdded);
+
+ // Check that our standard binding metadata generated the expected actual bindings
+
+ prop = properties.get("serviceBindings");
+ assertNotNull("Missing property serviceBindings", prop);
+ log.info("serviceBindings: " + prop);
+ val = prop.getValue();
+ assertNotNull("property serviceBindings has no value", val);
+ assertTrue("property serviceBindings value is CompositeValue", val instanceof CompositeValue);
+ CompositeValue compVal = (CompositeValue) val;
+ assertEquals("correct number of standard bindings", offsets.size(), compVal.values().size());
+ for (String bindingSetName : offsets.keySet())
+ {
+ MetaValue mv = compVal.get(bindingSetName);
+ assertTrue(mv instanceof CollectionValue);
+ CollectionValue colVal = (CollectionValue) mv;
+ sawAdded = false;
+ for (MetaValue element : colVal.getElements())
+ {
+ if ("AddedStandardBinding".equals(getSimpleValue(element, "serviceName")))
+ {
+ sawAdded = true;
+ assertEquals("correct bindingName in set " + bindingSetName,
+ "bindingName", getSimpleValue(element, "bindingName"));
+ assertEquals("correct description in set " + bindingSetName,
+ "description", getSimpleValue(element, "description"));
+ assertEquals("correct hostName in set " + bindingSetName,
+ hosts.get(bindingSetName), getSimpleValue(element, "hostName"));
+ assertEquals("correct port in set " + bindingSetName,
+ basePort + offsets.get(bindingSetName).intValue(),
+ getSimpleValue(element, "port", Integer.class).intValue());
+ break;
+ }
+ }
+ assertTrue("saw AddedStandardBinding in set " + bindingSetName, sawAdded);
+ }
+
+ return result;
+ }
+
+ private void logHierarchy(ManagedComponent mc)
+ {
+ ManagedCommon child = mc;
+ ManagedCommon mcom = mc.getParent();
+ while (mcom != null)
+ {
+ log.debug("parent of " + child.getName() + " is " + mcom.getName());
+ child = mcom;
+ mcom = mcom.getParent();
+ }
+ }
+
+ private Object getSimpleValue(MetaValue val, String key)
+ {
+ return getSimpleValue(val, key, Object.class);
+ }
+
+ private <T> T getSimpleValue(MetaValue val, String key, Class<T> type)
+ {
+ T result = null;
+ assertTrue(val instanceof CompositeValue);
+ CompositeValue cval = (CompositeValue) val;
+ MetaValue mv = cval.get(key);
+ if (mv != null)
+ {
+ assertTrue(mv instanceof SimpleValue);
+ Object obj = ((SimpleValue) mv).getValue();
+ result = type.cast(obj);
+ }
+ return result;
+ }
+
+ private static MapCompositeValueSupport cloneCompositeValue(CompositeValue toClone)
+ {
+ if (toClone instanceof MapCompositeValueSupport)
+ {
+ return (MapCompositeValueSupport) toClone.clone();
+ }
+ else
+ {
+ CompositeMetaType type = toClone.getMetaType();
+ Map<String, MetaValue> map = new HashMap<String, MetaValue>();
+ for (String key : type.keySet())
+ {
+ map.put(key, toClone.get(key));
+ }
+ return new MapCompositeValueSupport(map, type);
+ }
+ }
+
+ private class IndexedArray
+ {
+ int index;
+ MetaValue[] array;
+ }
+}
Modified: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ServiceBindingManagedObjectsTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ServiceBindingManagedObjectsTestCase.java 2009-05-19 18:35:20 UTC (rev 89130)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/test/ServiceBindingManagedObjectsTestCase.java 2009-05-19 20:18:52 UTC (rev 89131)
@@ -24,26 +24,22 @@
import java.net.InetAddress;
import java.util.HashMap;
import java.util.Map;
-import java.util.Set;
import org.jboss.deployers.spi.management.ManagementView;
import org.jboss.managed.api.ComponentType;
import org.jboss.managed.api.ManagedCommon;
import org.jboss.managed.api.ManagedComponent;
import org.jboss.managed.api.ManagedProperty;
-import org.jboss.metatype.api.types.CollectionMetaType;
import org.jboss.metatype.api.types.CompositeMetaType;
import org.jboss.metatype.api.types.ImmutableCompositeMetaType;
import org.jboss.metatype.api.types.MetaType;
import org.jboss.metatype.api.types.SimpleMetaType;
import org.jboss.metatype.api.values.ArrayValue;
import org.jboss.metatype.api.values.CollectionValue;
-import org.jboss.metatype.api.values.CollectionValueSupport;
import org.jboss.metatype.api.values.CompositeValue;
import org.jboss.metatype.api.values.MapCompositeValueSupport;
import org.jboss.metatype.api.values.MetaValue;
import org.jboss.metatype.api.values.SimpleValue;
-import org.jboss.metatype.api.values.SimpleValueSupport;
import org.jboss.services.binding.ServiceBindingMetadata;
import org.jboss.services.binding.impl.ServiceBindingSet;
import org.jboss.services.binding.managed.ServiceBindingMetadataMapper;
@@ -53,6 +49,9 @@
* Profile service ServiceBindingManager tests.
* </p>
*
+ * @see org.jboss.test.profileservice.override.test.ServiceBindingManagedObjectsTestCase
+ * for tests of updating the metadata
+ *
* @author Brian Stansberry
* @version $Revision$
*/
@@ -425,395 +424,7 @@
// assertEquals("ports-01", val.getValue());
// }
-
- public void testUpdateStandardBindings() throws Exception
- {
- ManagedComponent component = getServiceBindingManagerManagedComponent();
-
- logHierarchy(component);
-
- Map<String, ManagedProperty> properties = component.getProperties();
- assertNotNull(properties);
-
- ManagedProperty prop = properties.get("standardBindings");
- assertNotNull("Missing property standardBindings", prop);
- MetaValue val = prop.getValue();
- assertNotNull("property standardBindings has no value", val);
- assertTrue("property standardBindings value is CollectionValue", val instanceof CollectionValue);
-
- MetaValue[] origElements = ((CollectionValue) val).getElements();
- assertNotNull(origElements);
-
- // A) ADD a new element to "standardBindings"
-
- MetaValue[] newElements = new MetaValue[origElements.length + 1];
- System.arraycopy(origElements, 0, newElements, 0, origElements.length);
-
- Map<String, MetaValue> map = new HashMap<String, MetaValue>();
- map.put("serviceName", SimpleValueSupport.wrap("AddedStandardBinding"));
- map.put("bindingName", SimpleValueSupport.wrap("bindingName"));
- map.put("description", SimpleValueSupport.wrap("description"));
- map.put("port", SimpleValueSupport.wrap(12345));
- map.put("fixedHostName", SimpleValueSupport.wrap(false));
- map.put("fixedPort", SimpleValueSupport.wrap(false));
- MapCompositeValueSupport newElement = new MapCompositeValueSupport(map, SERVICE_BINDING_METADATA_TYPE);
- newElements[newElements.length - 1] = newElement;
-
- CollectionValue newVal = new CollectionValueSupport((CollectionMetaType) val.getMetaType(), newElements);
- prop.setValue(newVal);
-
- // Before passing the updated component back, store some info about
- // the binding sets so we can use it later
- prop = properties.get("bindingSets");
- assertNotNull("Missing property bindingSets", prop);
- val = prop.getValue();
- assertNotNull("property bindingSets has no value", val);
- assertTrue("property bindingSets value is CollectionValue", val instanceof CollectionValue);
- MetaValue[] elements = ((CollectionValue) val).getElements();
- assertNotNull(elements);
-
- // Two maps we'll use
- Map<String, Integer> offsets = new HashMap<String, Integer>();
- Map<String, String> hosts = new HashMap<String, String>();
- for (MetaValue mv : elements)
- {
- String name = getSimpleValue(mv, "name", String.class);
- offsets.put(name, getSimpleValue(mv, "portOffset", Integer.class));
- hosts.put(name, getSimpleValue(mv, "defaultHostName", String.class));
- }
-
- try
- {
- getManagementView().updateComponent(component);
- }
- catch (Exception e)
- {
- log.error("Failed updating " + component, e);
- throw e;
- }
-
- // B) Validate the result of A) and MODIFY the element we added in A
-
- component = getServiceBindingManagerManagedComponent();
- properties = component.getProperties();
-
- IndexedArray indexedArray = checkAddedBinding(properties, newElements.length, 12345, offsets, hosts);
- // We'll update the component again using this MetaValue[]
- newElements = new MetaValue[indexedArray.array.length];
- System.arraycopy(indexedArray.array, 0, newElements, 0, newElements.length);
-
- MapCompositeValueSupport update = cloneCompositeValue((CompositeValue) indexedArray.array[indexedArray.index]);
- update.put("port", SimpleValueSupport.wrap(23456));
- newElements[indexedArray.index] = update;
-
- newVal = new CollectionValueSupport((CollectionMetaType) val.getMetaType(), newElements);
- properties.get("standardBindings").setValue(newVal);
-
- // OK, now update
- try
- {
- getManagementView().updateComponent(component);
- }
- catch (Exception e)
- {
- log.error("Failed updating " + component, e);
- throw e;
- }
-
- // C) Validate update from B) plus REMOVE the element we added
-
- component = getServiceBindingManagerManagedComponent();
- properties = component.getProperties();
-
- indexedArray = checkAddedBinding(properties, newElements.length, 23456, offsets, hosts);
-
- // We'll update the component again using this MetaValue[]
- newElements = new MetaValue[indexedArray.array.length - 1];
- int j = 0;
- System.arraycopy(indexedArray.array, 0, newElements, 0, indexedArray.index);
- System.arraycopy(indexedArray.array, indexedArray.index + 1, newElements, indexedArray.index, indexedArray.array.length - indexedArray.index -1);
-
- newVal = new CollectionValueSupport((CollectionMetaType) val.getMetaType(), newElements);
- properties.get("standardBindings").setValue(newVal);
-
- // OK, now update
- try
- {
- getManagementView().updateComponent(component);
- }
- catch (Exception e)
- {
- log.error("Failed updating " + component, e);
- throw e;
- }
-
- // D) Removal from C) took effect
-
- component = getServiceBindingManagerManagedComponent();
- properties = component.getProperties();
-
- prop = properties.get("standardBindings");
- assertNotNull("Missing property standardBindings", prop);
- val = prop.getValue();
- assertNotNull("property standardBindings has no value", val);
- assertTrue("property standardBindings value is CollectionValue", val instanceof CollectionValue);
-
- MetaValue[] finalElements = ((CollectionValue) val).getElements();
- assertNotNull(finalElements);
- assertEquals(origElements.length, finalElements.length);
- for (MetaValue mv : finalElements)
- {
- assertFalse("AddedStandardBinding".equals(getSimpleValue(mv, "serviceName")));
- }
-
- prop = properties.get("serviceBindings");
- assertNotNull("Missing property serviceBindings", prop);
- log.info("serviceBindings: " + prop);
- val = prop.getValue();
- assertNotNull("property serviceBindings has no value", val);
- assertTrue("property serviceBindings value is CompositeValue", val instanceof CompositeValue);
- CompositeValue compVal = (CompositeValue) val;
- assertEquals(offsets.size(), compVal.values().size());
- for (String bindingSetName : offsets.keySet())
- {
- MetaValue mv = compVal.get(bindingSetName);
- assertTrue(mv instanceof CollectionValue);
- CollectionValue colVal = (CollectionValue) mv;
- for (MetaValue element : colVal.getElements())
- {
- assertFalse("AddedStandardBinding".equals(getSimpleValue(element, "serviceName")));
- }
- }
- }
-
- private IndexedArray checkAddedBinding(Map<String, ManagedProperty> properties, int bindingCount, int basePort, Map<String, Integer> offsets, Map<String, String> hosts)
- {
- // Return the array of standard bindings + the pos of the added binding
- IndexedArray result = new IndexedArray();
-
- // Scan for the standard binding
-
- ManagedProperty prop = properties.get("standardBindings");
- assertNotNull("Missing property standardBindings", prop);
- MetaValue val = prop.getValue();
- assertNotNull("property standardBindings has no value", val);
- assertTrue("property standardBindings value is CollectionValue", val instanceof CollectionValue);
- MetaValue[] refreshedElements = ((CollectionValue) val).getElements();
- assertEquals(bindingCount, refreshedElements.length);
- result.array = refreshedElements; // pass back to caller
- boolean sawAdded = false;
- for (int i = 0; i < refreshedElements.length; i++)
- {
- MetaValue mv = refreshedElements[i];
- if ("AddedStandardBinding".equals(getSimpleValue(mv, "serviceName")))
- {
- sawAdded = true;
- assertEquals("correct bindingName in standard binding", "bindingName", getSimpleValue(mv, "bindingName"));
- assertEquals("correct description in standard binding", "description", getSimpleValue(mv, "description"));
- assertNull("correct hostName in standardBinding", getSimpleValue(mv, "hostName"));
- assertEquals("correct port in standard binding", basePort, getSimpleValue(mv, "port", Integer.class).intValue());
- assertFalse("correct fixedPort in standard binding", getSimpleValue(mv, "fixedPort", Boolean.class).booleanValue());
- assertFalse("correct fixedHostName in standard binding", getSimpleValue(mv, "fixedHostName", Boolean.class).booleanValue());
-
- result.index = i; // tell caller which pos has the added binding
- break;
- }
- }
- assertTrue("saw standard binding", sawAdded);
-
- // Check that our standard binding metadata generated the expected actual bindings
-
- prop = properties.get("serviceBindings");
- assertNotNull("Missing property serviceBindings", prop);
- log.info("serviceBindings: " + prop);
- val = prop.getValue();
- assertNotNull("property serviceBindings has no value", val);
- assertTrue("property serviceBindings value is CompositeValue", val instanceof CompositeValue);
- CompositeValue compVal = (CompositeValue) val;
- assertEquals("correct number of standard bindings", offsets.size(), compVal.values().size());
- for (String bindingSetName : offsets.keySet())
- {
- MetaValue mv = compVal.get(bindingSetName);
- assertTrue(mv instanceof CollectionValue);
- CollectionValue colVal = (CollectionValue) mv;
- sawAdded = false;
- for (MetaValue element : colVal.getElements())
- {
- if ("AddedStandardBinding".equals(getSimpleValue(element, "serviceName")))
- {
- sawAdded = true;
- assertEquals("correct bindingName in set " + bindingSetName,
- "bindingName", getSimpleValue(element, "bindingName"));
- assertEquals("correct description in set " + bindingSetName,
- "description", getSimpleValue(element, "description"));
- assertEquals("correct hostName in set " + bindingSetName,
- hosts.get(bindingSetName), getSimpleValue(element, "hostName"));
- assertEquals("correct port in set " + bindingSetName,
- basePort + offsets.get(bindingSetName).intValue(),
- getSimpleValue(element, "port", Integer.class).intValue());
- break;
- }
- }
- assertTrue("saw AddedStandardBinding in set " + bindingSetName, sawAdded);
- }
-
- return result;
- }
-
- public void testUpdateServiceBindingSets() throws Exception
- {
- ManagedComponent component = getServiceBindingManagerManagedComponent();
-
- logHierarchy(component);
-
- Map<String, ManagedProperty> properties = component.getProperties();
- assertNotNull(properties);
-
- // A) ADD a new binding set
-
- ManagedProperty prop = properties.get("bindingSets");
- assertNotNull("Missing property bindingSets", prop);
- MetaValue val = prop.getValue();
- assertNotNull("property bindingSets has no value", val);
- assertTrue("property bindingSets value is CollectionValue", val instanceof CollectionValue);
- MetaValue[] origElements = ((CollectionValue) val).getElements();
- assertNotNull(origElements);
- MetaValue[] newElements = new MetaValue[origElements.length + 1];
- System.arraycopy(origElements, 0, newElements, 0, origElements.length);
-
- Map<String, MetaValue> map = new HashMap<String, MetaValue>();
- map.put("name", SimpleValueSupport.wrap("ports-test"));
- map.put("defaultHostName", SimpleValueSupport.wrap("localhost"));
- map.put("portOffset", SimpleValueSupport.wrap(500));
-
- Map<String, MetaValue> metadata = new HashMap<String, MetaValue>();
- metadata.put("serviceName", SimpleValueSupport.wrap("AddedOverrideBinding"));
- metadata.put("description", SimpleValueSupport.wrap("description"));
- metadata.put("port", SimpleValueSupport.wrap(54321));
- MapCompositeValueSupport newMetadata = new MapCompositeValueSupport(metadata, SERVICE_BINDING_METADATA_TYPE);
- CollectionValue overrides = new CollectionValueSupport(new CollectionMetaType(Set.class.getName(), SERVICE_BINDING_METADATA_TYPE), new MetaValue[]{newMetadata});
-
- map.put("overrideBindings", overrides);
- MapCompositeValueSupport newElement = new MapCompositeValueSupport(map, SERVICE_BINDING_SET_TYPE);
- newElements[newElements.length - 1] = newElement;
- CollectionValue newVal = new CollectionValueSupport(new CollectionMetaType(Set.class.getName(), SERVICE_BINDING_SET_TYPE), newElements);
- prop.setValue(newVal);
-
- // Before updating get a ref to the standard bindings so we can use it
- // in later validation
- Map<String, MetaValue> standardBindings = new HashMap<String, MetaValue>();
- prop = properties.get("standardBindings");
- assertNotNull("Missing property standardBindings", prop);
- val = prop.getValue();
- assertNotNull("property standardBindings has no value", val);
- assertTrue("property standardBindings value is CollectionValue", val instanceof CollectionValue);
- MetaValue[] elements = ((CollectionValue) val).getElements();
- assertNotNull("property standardBindings value has elements", elements);
- for (MetaValue mv : elements)
- {
- standardBindings.put(getSimpleValue(mv, "fullyQualifiedName", String.class), mv);
- }
-
- try
- {
- getManagementView().updateComponent(component);
- }
- catch (Exception e)
- {
- log.error("Failed updating " + component, e);
- throw e;
- }
-
- // B) Validate the addition from A) took effect and then UPDATE the added binding set
-
- component = getServiceBindingManagerManagedComponent();
- properties = component.getProperties();
- assertNotNull(properties);
-
- IndexedArray indexedArray = checkAddedBindingSet(properties, newElements.length, 500, 54321, standardBindings);
-
- prop = properties.get("bindingSets");
- assertNotNull("Missing property bindingSets", prop);
- val = prop.getValue();
- assertNotNull("property bindingSets has no value", val);
- assertTrue("property bindingSets value is CollectionValue", val instanceof CollectionValue);
- MetaValue[] updated = newElements.clone();
- MapCompositeValueSupport updatedBindingSet = cloneCompositeValue((CompositeValue) updated[indexedArray.index]);
- updatedBindingSet.put("portOffset", SimpleValueSupport.wrap(400));
-
- MetaValue[] updatedOverrides = ((CollectionValue) updatedBindingSet.get("overrideBindings")).getElements();
- assertEquals("single override binding", 1, updatedOverrides.length);
- MapCompositeValueSupport updatedOverride = cloneCompositeValue((CompositeValue) updatedOverrides[0]);
- updatedOverride.put("port", SimpleValueSupport.wrap(43210));
- updatedBindingSet.put("overrideBindings", new CollectionValueSupport(new CollectionMetaType(Set.class.getName(), SERVICE_BINDING_METADATA_TYPE), new MetaValue[]{updatedOverride}));
-
- updated[indexedArray.index] = updatedBindingSet;
- newVal = new CollectionValueSupport(new CollectionMetaType(Set.class.getName(), SERVICE_BINDING_SET_TYPE), updated);
- prop.setValue(newVal);
-
- try
- {
- getManagementView().updateComponent(component);
- }
- catch (Exception e)
- {
- log.error("Failed updating " + component, e);
- throw e;
- }
-
- // C) Validate the update from B) took effect and then REMOVE the added binding set
-
- component = getServiceBindingManagerManagedComponent();
- properties = component.getProperties();
- assertNotNull(properties);
-
- indexedArray = checkAddedBindingSet(properties, newElements.length, 400, 43210, standardBindings);
-
- // We'll update the component again using this MetaValue[]
- newElements = new MetaValue[indexedArray.array.length - 1];
- System.arraycopy(indexedArray.array, 0, newElements, 0, indexedArray.index);
- System.arraycopy(indexedArray.array, indexedArray.index + 1, newElements, indexedArray.index, indexedArray.array.length - indexedArray.index -1);
-
- newVal = new CollectionValueSupport((CollectionMetaType) val.getMetaType(), newElements);
- properties.get("bindingSets").setValue(newVal);
-
- try
- {
- getManagementView().updateComponent(component);
- }
- catch (Exception e)
- {
- log.error("Failed updating " + component, e);
- throw e;
- }
-
- // D) Confirm the added binding set is now gone
-
- component = getServiceBindingManagerManagedComponent();
- properties = component.getProperties();
- assertNotNull(properties);
-
- prop = properties.get("bindingSets");
- assertNotNull("Missing property bindingSets", prop);
- val = prop.getValue();
- assertNotNull("property bindingSets has no value", val);
- assertTrue("property bindingSets value is CollectionValue", val instanceof CollectionValue);
- MetaValue[] finalElements = ((CollectionValue) val).getElements();
- assertNotNull("property bindingSets value has elements", finalElements);
- assertEquals("correct number of binding sets after removal",
- origElements.length, finalElements.length);
- for (MetaValue mv : finalElements)
- {
- assertFalse("ports-test".equals(getSimpleValue(mv, "name")));
- }
- prop = properties.get("serviceBindings");
- assertNotNull("Missing property serviceBindings", prop);
- val = prop.getValue();
- assertTrue(val instanceof CompositeValue);
- assertNull("no actual bindings for ports-test", ((CompositeValue) val).get("ports-test"));
- }
-
private IndexedArray checkAddedBindingSet(Map<String, ManagedProperty> properties, int numSets, int portOffset, int overrideBindingPort,
Map<String, MetaValue> standardBindings)
{
More information about the jboss-cvs-commits
mailing list