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);