[jboss-cvs] JBossAS SVN: r86650 - in branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice: template and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Apr 2 05:41:58 EDT 2009
Author: emuckenhuber
Date: 2009-04-02 05:41:58 -0400 (Thu, 02 Apr 2009)
New Revision: 86650
Added:
branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/template/
branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/template/test/
branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/template/test/AbstractTemplateTest.java
branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/template/test/DSDeploymentTemplateUnitTestCase.java
branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/template/test/JMSDestinationTemplateUnitTestCase.java
Log:
template test cases
Added: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/template/test/AbstractTemplateTest.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/template/test/AbstractTemplateTest.java (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/template/test/AbstractTemplateTest.java 2009-04-02 09:41:58 UTC (rev 86650)
@@ -0,0 +1,190 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.template.test;
+
+import java.io.Serializable;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.managed.api.DeploymentTemplateInfo;
+import org.jboss.managed.api.Fields;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.managed.api.annotation.ManagementProperty;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.managed.plugins.factory.DeploymentTemplateInfoFactory;
+import org.jboss.managed.plugins.factory.ManagedObjectFactoryBuilder;
+import org.jboss.metatype.api.types.MetaType;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.MetaValueFactory;
+import org.jboss.metatype.plugins.values.MetaValueFactoryBuilder;
+import org.jboss.test.BaseTestCase;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public abstract class AbstractTemplateTest extends BaseTestCase
+{
+
+ /** The deployment factory. */
+ DeploymentTemplateInfoFactory factory = new DeploymentTemplateInfoFactory();
+
+ /** The managed object factory. */
+ ManagedObjectFactory mof = ManagedObjectFactoryBuilder.create();
+
+ /** The meta value factory. */
+ MetaValueFactory mvf = MetaValueFactoryBuilder.create();
+
+ protected boolean debug = false;
+
+ public AbstractTemplateTest(String name)
+ {
+ super(name);
+ }
+
+ public ManagedObjectFactory getMof()
+ {
+ return mof;
+ }
+
+ public MetaValueFactory getMvf()
+ {
+ return mvf;
+ }
+
+ public DeploymentTemplateInfoFactory getFactory()
+ {
+ return factory;
+ }
+
+ public boolean isDebug()
+ {
+ return debug;
+ }
+
+ public void setDebug(boolean debug)
+ {
+ this.debug = debug;
+ }
+
+ abstract DeploymentTemplateInfo createDeploymentInfo(String name, Class<?> clazz) throws Exception;
+
+ protected DeploymentTemplateInfo assertTemplate(String name, Class<?> clazz) throws Exception
+ {
+ DeploymentTemplateInfo info = createDeploymentInfo(name, clazz);
+ assertNotNull(info);
+
+ ManagedObject mo = mof.createManagedObject(clazz);
+ assertNotNull(mo);
+
+ log.debug(">> " + info.getName());
+ assertTemplateInfo(info, mo);
+
+ return info;
+ }
+
+ protected void assertTemplateInfo(DeploymentTemplateInfo info, ManagedObject mo)
+ {
+ List<String> processed = new ArrayList<String>();
+ for(ManagedProperty property : info.getProperties().values())
+ {
+ //
+ String propertyName = property.getName();
+ //
+ ManagedProperty other = mo.getProperty(propertyName);
+ assertProperty(propertyName , property, other);
+ //
+ processed.add(propertyName);
+
+ log.debug("property: " + propertyName);
+
+ }
+
+ for(ManagedProperty other : info.getProperties().values())
+ {
+ String otherName = other.getName();
+ if(processed.contains(otherName))
+ continue;
+
+ ManagedProperty reference = mo.getProperty(otherName);
+ if(isDebug() && reference == null)
+ {
+ log.debug("Does not exist in runtime MO: " + otherName);
+ continue;
+ }
+
+ assertNotNull(otherName + " is included in the MO", reference);
+
+ ManagementProperty annotation = null;
+ if(reference.getAnnotations() != null)
+ {
+ annotation = (ManagementProperty) reference.getAnnotations().get(ManagementProperty.class.getName());
+ }
+ else
+ {
+ PropertyInfo propertyInfo = reference.getField(Fields.PROPERTY_INFO, PropertyInfo.class);
+ annotation = (ManagementProperty) propertyInfo.getAnnotation(ManagementProperty.class.getName());
+ }
+ if(isDebug() && annotation == null)
+ {
+ log.debug("@ManagedProperty not present: " + otherName);
+ continue;
+ }
+ assertNotNull(otherName + " annotation present", annotation);
+
+ if(isDebug() && annotation.includeInTemplate() == false)
+ {
+ log.error("includeInTemplate == true " + otherName);
+ continue;
+ }
+
+
+ assertTrue(otherName + " includeInTemplate", annotation.includeInTemplate());
+ assertProperty(otherName, other, reference);
+ }
+ }
+
+ protected void assertProperty(String name, ManagedProperty property, ManagedProperty other)
+ {
+ assertNotNull(name, property);
+ assertNotNull(name, other);
+
+ assertEquals(name, property.getMetaType(), other.getMetaType());
+ assertEquals(name, property.isMandatory(), other.isMandatory());
+ }
+
+ protected void assertProperty(ManagedProperty property, MetaType metaType, Serializable value)
+ {
+ assertProperty(property, metaType, mvf.create(value));
+ }
+
+ protected void assertProperty(ManagedProperty property, MetaType metaType, MetaValue metaValue)
+ {
+ assertNotNull(property);
+ assertEquals(property.getMetaType(), metaType);
+ assertEquals(property.getValue(), metaValue);
+ }
+
+}
+
Added: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/template/test/DSDeploymentTemplateUnitTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/template/test/DSDeploymentTemplateUnitTestCase.java (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/template/test/DSDeploymentTemplateUnitTestCase.java 2009-04-02 09:41:58 UTC (rev 86650)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.template.test;
+
+import org.jboss.managed.api.DeploymentTemplateInfo;
+import org.jboss.resource.deployers.management.DsDataSourceTemplateInfo;
+import org.jboss.resource.metadata.mcf.LocalDataSourceDeploymentMetaData;
+import org.jboss.resource.metadata.mcf.NoTxConnectionFactoryDeploymentMetaData;
+import org.jboss.resource.metadata.mcf.NoTxDataSourceDeploymentMetaData;
+import org.jboss.resource.metadata.mcf.TxConnectionFactoryDeploymentMetaData;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class DSDeploymentTemplateUnitTestCase extends AbstractTemplateTest
+{
+
+ public DSDeploymentTemplateUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public boolean isDebug()
+ {
+ return debug;
+ }
+
+ public void testLocalTxDataSourceTemplateInfo() throws Exception
+ {
+ assertTemplate("LocalTxDataSourceTemplateInfo",
+ LocalDataSourceDeploymentMetaData.class);
+ }
+
+ public void testNoTxDataSourceTemplateInfo() throws Exception
+ {
+ assertTemplate("NoTxDataSourceTemplateInfo",
+ NoTxDataSourceDeploymentMetaData.class);
+ }
+
+ public void testTxConnectionFactoryTemplateInfo() throws Exception
+ {
+ assertTemplate("TxConnectionFactoryTemplateInfo",
+ TxConnectionFactoryDeploymentMetaData.class);
+ }
+
+ public void testNoTxConnectionFactoryTemplateInfo() throws Exception
+ {
+ assertTemplate("NoTxConnectionFactoryTemplateInfo",
+ NoTxConnectionFactoryDeploymentMetaData.class);
+ }
+
+ protected DeploymentTemplateInfo createDeploymentInfo(String name, Class<?> attachment) throws Exception
+ {
+ DeploymentTemplateInfo info = getFactory().createTemplateInfo(DsDataSourceTemplateInfo.class, attachment, name, null);
+ // populate the values
+ ((DsDataSourceTemplateInfo) info).start();
+ return info;
+ }
+
+}
Added: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/template/test/JMSDestinationTemplateUnitTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/template/test/JMSDestinationTemplateUnitTestCase.java (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/template/test/JMSDestinationTemplateUnitTestCase.java 2009-04-02 09:41:58 UTC (rev 86650)
@@ -0,0 +1,131 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.template.test;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.jboss.jms.server.destination.SecurityConfigMapper;
+import org.jboss.managed.api.DeploymentTemplateInfo;
+import org.jboss.metatype.api.types.CompositeMetaType;
+import org.jboss.metatype.api.types.MapCompositeMetaType;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.CompositeValueSupport;
+import org.jboss.metatype.api.values.MapCompositeValueSupport;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.profileservice.management.templates.JmsDestinationTemplateInfo;
+
+/**
+ * JMSDestination Queue and Topic template testcase.
+ *
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class JMSDestinationTemplateUnitTestCase extends AbstractTemplateTest
+{
+
+ /** The security mapper meta types. */
+ private static MapCompositeMetaType mapMetaType;
+ private static CompositeMetaType compositeMetaType;
+
+ static
+ {
+ SecurityConfigMapper mapper = new SecurityConfigMapper();
+ mapMetaType = (MapCompositeMetaType) mapper.getMetaType();
+ compositeMetaType = SecurityConfigMapper.composite;
+ }
+
+ public JMSDestinationTemplateUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testQueueTemplateInfo() throws Exception
+ {
+// DeploymentTemplateInfo info = assertTemplate("QueueTemplate",
+// QueueServiceMO.class);
+//
+// info.getProperties().get("JNDIName").setValue(new SimpleValueSupport(SimpleMetaType.STRING, "Test"));
+//
+// info.getProperties().get("serverPeer").setValue(getMvf().create(new ObjectName("jboss.messaging.destination:service=Queue")));
+// info.getProperties().get("DLQ").setValue(getMvf().create(new ObjectName("jboss.messaging.destination:service=Queue,name=PrivateDLQ")));
+// info.getProperties().get("expiryQueue").setValue(getMvf().create(new ObjectName("jboss.messaging.destination:service=Queue,name=PrivateExpiryQueue")));
+// info.getProperties().get("securityConfig").setValue(createComposityType());
+//
+//
+// DeploymentTemplate t = new JmsDestinationTemplate();
+// // Try to apply the template and delete the file afterwards
+// t.applyTemplate(info);
+ }
+
+ public void testTopicTemplateInfo() throws Exception
+ {
+// DeploymentTemplateInfo info = assertTemplate("TopicTemplate",
+// TopicServiceMO.class);
+//
+// info.getProperties().get("JNDIName").setValue(new SimpleValueSupport(SimpleMetaType.STRING, "Test"));
+//
+// info.getProperties().get("serverPeer").setValue(getMvf().create(new ObjectName("jboss.messaging.destination:service=Queue")));
+// info.getProperties().get("DLQ").setValue(getMvf().create(new ObjectName("jboss.messaging.destination:service=Queue,name=PrivateDLQ")));
+// info.getProperties().get("expiryQueue").setValue(getMvf().create(new ObjectName("jboss.messaging.destination:service=Queue,name=PrivateExpiryQueue")));
+// info.getProperties().get("securityConfig").setValue(createComposityType());
+//
+// DeploymentTemplate t = new JmsDestinationTemplate();
+// // Try to apply the template and delete the file afterwards
+// t.applyTemplate(info);
+ }
+
+ @Override
+ DeploymentTemplateInfo createDeploymentInfo(String name, Class<?> attachment) throws Exception
+ {
+ DeploymentTemplateInfo info = getFactory().createTemplateInfo(JmsDestinationTemplateInfo.class, attachment, name, null);
+ ((JmsDestinationTemplateInfo)info).start();
+ ((JmsDestinationTemplateInfo)info).setDestinationType(name);
+ return info;
+ }
+
+ protected MapCompositeValueSupport createComposityType()
+ {
+ Map<String, MetaValue> values = new HashMap<String, MetaValue>();
+
+ values.put("admin", createCompositeValue(true, true, true));
+ values.put("publisher", createCompositeValue(true, true, false));
+ values.put("user", createCompositeValue(true, null, null));
+
+ return new MapCompositeValueSupport(values, mapMetaType);
+ }
+
+ protected CompositeValue createCompositeValue(Boolean read, Boolean write, Boolean create)
+ {
+ Map<String, MetaValue> map = new HashMap<String, MetaValue>();
+
+ map.put("read", new SimpleValueSupport(SimpleMetaType.BOOLEAN, read));
+ map.put("write", new SimpleValueSupport(SimpleMetaType.BOOLEAN, write));
+ map.put("create", new SimpleValueSupport(SimpleMetaType.BOOLEAN, create));
+
+ return new CompositeValueSupport(compositeMetaType, map);
+ }
+
+}
+
More information about the jboss-cvs-commits
mailing list