public void testDSMetaDataManagedObjectFactoryInit()
{
ManagedObjectFactory mof = ManagedObjectFactory.getInstance();
DSMetaData dsmd = new DSMetaData();
LocalDataSourceMetaData ds = new LocalDataSourceMetaData();
XADataSourceMetaData xads = new XADataSourceMetaData();
ArrayList<ConnMetaData> deployments = new ArrayList<ConnMetaData>();
deployments.add(ds);
deployments.add(xads);
dsmd.setDeployments(deployments);
ManagedObject mo = mof.initManagedObject(dsmd, null, null);
// Validate the expected properties
Map<String, ManagedProperty> propsMap = mo.getProperties();
assertEquals(2, propsMap.size());
log.info("DSMetaData properties: "+propsMap);
// display-name
ManagedProperty displayName = propsMap.get("display-name");
assertNotNull(displayName);
assertEquals("display name of DS deployment", displayName.getDescription());
assertEquals(SimpleMetaType.STRING, displayName.getMetaType());
// deployments
ManagedProperty dsDeployments = propsMap.get("deployments");
assertNotNull(deployments);
assertEquals("The DS connection factories", dsDeployments.getDescription());
MetaType deploymentsType = new CollectionMetaType(List.class.getName(), AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE);
assertEquals(deploymentsType, dsDeployments.getMetaType());
CollectionValue value = CollectionValue.class.cast(dsDeployments.getValue());
CollectionMetaType valueType = value.getMetaType();
assertEquals(AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE, valueType.getElementType());
assertEquals(2, value.getSize());
ManagedObject localConnMO = null;
ManagedObject xaConnMO = null;
for(Object md : value)
{
GenericValue tmpGV = GenericValue.class.cast(md);
ManagedObject tmpMO = ManagedObject.class.cast(tmpGV.getValue());
if (tmpMO.getName().equals(LocalDataSourceMetaData.class.getName()))
localConnMO = tmpMO;
if (tmpMO.getName().equals(XADataSourceMetaData.class.getName()))
xaConnMO = tmpMO;
}
assertNotNull(localConnMO);
assertNotNull(xaConnMO);
// Validate the LocalDataSourceMetaData ManagedObject
propsMap = localConnMO.getProperties();
assertEquals(10, propsMap.size());
log.info("LocalDataSourceMetaData properties: "+propsMap);
ManagedProperty dsType = propsMap.get("datasource-type");
assertNotNull(dsType);
Set<MetaValue> dsTypeValues = dsType.getLegalValues();
assertTrue(dsTypeValues.containsAll(AllowedDsTypes.values));
// Validate the XADataSourceMetaData ManagedObject
propsMap = xaConnMO.getProperties();
assertEquals(12, propsMap.size());
log.info("XADataSourceMetaData properties: "+propsMap);
ManagedProperty xaDataSourceClass = propsMap.get("xaDataSourceClass");
assertNotNull(xaDataSourceClass);
ManagedProperty xaResourceTimeout = propsMap.get("xaResourceTimeout");
assertNotNull(xaResourceTimeout);
ManagedProperty secDomain = propsMap.get("security-domain");
assertNotNull(secDomain);
MetaType secDomainType = secDomain.getMetaType();
assertEquals(AbstractManagedObjectFactory.MANAGED_OBJECT_META_TYPE, secDomainType);
ManagedProperty jndiName = propsMap.get("jndi-name");
assertNotNull(jndiName);
ManagedProperty password = propsMap.get("password");
assertNotNull(password);
ManagedProperty connProperties = propsMap.get("connection-properties");
assertNotNull(connProperties);
ManagedProperty username = propsMap.get("username");
assertNotNull(username);
ManagedProperty maxSize = propsMap.get("max-size");
assertNotNull(maxSize);
ManagedProperty minSize = propsMap.get("min-size");
assertNotNull(minSize);
// Validate setting the properties
displayName.setValue(getMetaValueFactory().create("testDSMetaDataManagedObjectFactoryInit"));
jndiName.setValue(getMetaValueFactory().create("java:TestDS"));
password.setValue(getMetaValueFactory().create("password".toCharArray()));
username.setValue(getMetaValueFactory().create("username"));
minSize.setValue(getMetaValueFactory().create(10));
maxSize.setValue(getMetaValueFactory().create(100));
Object attachment = xaConnMO.getAttachment();
assertTrue("attachment is a XADataSourceMetaData("+attachment+")", attachment instanceof XADataSourceMetaData);
XADataSourceMetaData xaDS = XADataSourceMetaData.class.cast(attachment);
assertEquals("jndiName", "java:TestDS", xaDS.getJndiName());
assertEquals("password", "password", new String(xaDS.getPassword()));
assertEquals("username", "username", xaDS.getUsername());
assertEquals("minSize", 10, xaDS.getMinSize());
assertEquals("maxSize", 100, xaDS.getMaxSize());
}