// First disable datasource (allow service restart)
OperationDefinition disableOperation = getOperationDefinition("disable");
Configuration disableOperationParams = disableOperation.getParametersConfigurationDefinition()
.getDefaultTemplate().createConfiguration();
disableOperationParams.setSimpleValue("allow-resource-service-restart", TRUE.toString());
OperationFacet operationFacet = getOperationFacet(datasourceTestResource);
OperationResult operationResult = operationFacet.invokeOperation(disableOperation.getName(),
disableOperationParams);
assertNull(operationResult.getErrorMessage(),
"Disable operation failed with error: " + operationResult.getErrorMessage());
// Then update properties which can only be changed when datasource is in disabled state
Configuration configuration = pluginContainer.getConfigurationManager().loadResourceConfiguration(
datasourceTestResource.getId());
assertFalse(Boolean.parseBoolean(configuration.getSimpleValue("enabled")), "");
// Make a working copy
configuration = configuration.deepCopy(false);
// Change values
PropertySimple propertySimple = configuration.getSimple("prepared-statements-cache-size");
Long currentCacheSize = propertySimple.getLongValue();
long newCacheSize = currentCacheSize == null ? 40 : currentCacheSize + 1;
propertySimple.setStringValue(String.valueOf(newCacheSize));
PropertyList connectionPropertiesListWrapper = configuration.getList("*1");
assertNotNull(connectionPropertiesListWrapper, "Connection properties list wrapper is null");
List<Property> connectionPropertiesList = connectionPropertiesListWrapper.getList();
connectionPropertiesList.add(new PropertyMap("*:pname", new PropertySimple("pname", "pipo"),
new PropertySimple("value", "molo")));
ConfigurationUpdateRequest configurationUpdateRequest = new ConfigurationUpdateRequest(-1, configuration,
datasourceTestResource.getId());
ConfigurationUpdateResponse configurationUpdateResponse = pluginContainer.getConfigurationManager()
.executeUpdateResourceConfigurationImmediately(configurationUpdateRequest);
assertSame(configurationUpdateResponse.getStatus(), ConfigurationUpdateStatus.SUCCESS);
configuration = pluginContainer.getConfigurationManager().loadResourceConfiguration(
datasourceTestResource.getId());
assertFalse(Boolean.parseBoolean(configuration.getSimpleValue("enabled")), "");
assertEquals(configuration.getSimple("prepared-statements-cache-size").getLongValue(),
Long.valueOf(newCacheSize));
connectionPropertiesListWrapper = configuration.getList("*1");
assertNotNull(connectionPropertiesListWrapper, "Connection properties list wrapper is null");
connectionPropertiesList = connectionPropertiesListWrapper.getList();
String connectionPropertyValue = null;
for (Property property : connectionPropertiesList) {
assertTrue(property instanceof PropertyMap, "Connection properties should be a list of maps");
PropertyMap propertyMap = (PropertyMap) property;
String pname = propertyMap.getSimpleValue("pname", null);
assertNotNull(pname, "Connection property key is null");
String value = propertyMap.getSimpleValue("value", null);
assertNotNull(value, "Connection property value is null");
if ("pipo".equals(pname)) {
connectionPropertyValue = value;
break;
}
}
assertEquals(connectionPropertyValue, "molo");
assertFalse(
configuration.getNames().contains("__OOB"),
"The configuration object should not contain out of band messages: "
+ configuration.getSimpleValue("__OOB"));
// Now re-enable datasource
OperationDefinition enableOperation = getOperationDefinition("enable");
Configuration enableOperationParams = enableOperation.getParametersConfigurationDefinition()
.getDefaultTemplate().createConfiguration();
operationResult = operationFacet.invokeOperation(enableOperation.getName(), enableOperationParams);
assertNull(operationResult.getErrorMessage(),
"Enable operation failed with error: " + operationResult.getErrorMessage());
// Check server state
configuration = pluginContainer.getConfigurationManager().loadResourceConfiguration(