[jboss-cvs] JBossAS SVN: r86330 - in branches/Branch_5_x: testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Mar 25 09:41:08 EDT 2009


Author: emuckenhuber
Date: 2009-03-25 09:41:08 -0400 (Wed, 25 Mar 2009)
New Revision: 86330

Added:
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/SimpleAnnotatedBean.java
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/JBossBeansPersistenceFormatTestCase.java
Modified:
   branches/Branch_5_x/system/src/main/org/jboss/deployers/plugins/managed/BeanMetaDataICF.java
Log:
[JBAS-6227] initial BeanMetaData persistence testcase

Modified: branches/Branch_5_x/system/src/main/org/jboss/deployers/plugins/managed/BeanMetaDataICF.java
===================================================================
--- branches/Branch_5_x/system/src/main/org/jboss/deployers/plugins/managed/BeanMetaDataICF.java	2009-03-25 13:38:03 UTC (rev 86329)
+++ branches/Branch_5_x/system/src/main/org/jboss/deployers/plugins/managed/BeanMetaDataICF.java	2009-03-25 13:41:08 UTC (rev 86330)
@@ -28,6 +28,7 @@
 import org.jboss.beans.info.spi.PropertyInfo;
 import org.jboss.beans.metadata.spi.AnnotationMetaData;
 import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
 import org.jboss.dependency.spi.ControllerContext;
 import org.jboss.kernel.spi.dependency.KernelController;
 import org.jboss.logging.Logger;
@@ -125,6 +126,23 @@
             }
          }
       }
+      // Find <annotation/> in the beans.xml 
+//      if(annotations != null)
+//      {
+//         for(AnnotationMetaData amd : annotations)
+//         {
+//            Annotation ann = amd.getAnnotationInstance();
+//            if(ann instanceof ManagementObject)
+//            {
+//               String beanClassName = attachment.getBean();
+//               ClassLoader loader = getClassLoader(attachment);
+//               mocClass = loader.loadClass(beanClassName); 
+//               log.debug("Saw ManagementObject, "+mocClass+" for bean: "+attachment);
+//               break;               
+//            }
+//         }
+//      }
+      
       // Use the bean from the metadata
       if(mocClass == null)
       {
@@ -177,6 +195,7 @@
             mvalue = delegateICF.getValue(beanInfo, property, metaData, attachment);
          else
             mvalue = delegateICF.getValue(beanInfo, property, metaData, bean);
+            
       }
       catch(Throwable e)
       {
@@ -218,7 +237,14 @@
          }
          Object plainValue = metaValueFactory.unwrap(value, propertyInfo.getType());
          Object bean = locateBean(beanName);
-         propertyInfo.set(bean, plainValue);
+         
+         // Only update if the bean is not null
+         if(bean != null)
+            propertyInfo.set(bean, plainValue);
+         
+         BeanMetaDataBuilder builder = BeanMetaDataBuilder.createBuilder(attachment);
+         builder.addPropertyMetaData(name, plainValue);
+         
       }
       catch(Throwable e)
       {

Added: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/SimpleAnnotatedBean.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/SimpleAnnotatedBean.java	                        (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/SimpleAnnotatedBean.java	2009-03-25 13:41:08 UTC (rev 86330)
@@ -0,0 +1,62 @@
+/*
+ * 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.persistenceformat.support;
+
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+//@ManagementObject(name = "SimpleBean")
+public class SimpleAnnotatedBean
+{
+   
+   /** The string property. */
+   private String stringProperty;
+   
+   /** The injection propeprty. */
+   private Object injectProperty;
+ 
+   @ManagementProperty
+   public String getStringProperty()
+   {
+      return stringProperty;
+   }
+   
+   public void setStringProperty(String stringProperty)
+   {
+      this.stringProperty = stringProperty;
+   }
+   
+   @ManagementProperty
+   public Object getInjectProperty()
+   {
+      return injectProperty;
+   }
+   
+   public void setInjectProperty(Object injectProperty)
+   {
+      this.injectProperty = injectProperty;
+   }
+   
+}

Added: branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/JBossBeansPersistenceFormatTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/JBossBeansPersistenceFormatTestCase.java	                        (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/JBossBeansPersistenceFormatTestCase.java	2009-03-25 13:41:08 UTC (rev 86330)
@@ -0,0 +1,134 @@
+/*
+ * 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.persistenceformat.test;
+
+import java.util.Set;
+
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.PropertyMetaData;
+import org.jboss.beans.metadata.spi.builder.BeanMetaDataBuilder;
+import org.jboss.deployers.plugins.managed.BeanMetaDataICF;
+import org.jboss.kernel.Kernel;
+import org.jboss.kernel.plugins.bootstrap.basic.BasicBootstrap;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.plugins.factory.AbstractManagedObjectFactory;
+import org.jboss.metadata.spi.MetaData;
+import org.jboss.system.server.profileservice.persistence.ManagedGenericOverrideHandler;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+import org.jboss.test.profileservice.persistenceformat.support.SimpleAnnotatedBean;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class JBossBeansPersistenceFormatTestCase extends AbstractPersistenceFormatTest
+{
+   
+   /** The bootstrap. */
+   private BasicBootstrap bootstrap;
+   
+   /** The kernel. */
+   private Kernel kernel;
+   
+   /** The controller. */
+   private KernelController controller;
+
+   public JBossBeansPersistenceFormatTestCase(String name)
+   {
+      super(name);
+   }
+
+   
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+      // Bootstrap
+      bootstrap = new BasicBootstrap();
+      bootstrap.run();
+      //
+      kernel = bootstrap.getKernel();
+      //
+      controller = kernel.getController();
+   }
+   
+   protected BeanMetaData installBean() throws Throwable
+   {
+      BeanMetaDataBuilder builder = getSimpleBeanMetaDataBuilder();
+      // Add a value
+      builder.addPropertyMetaData("stringProperty", "testValue");
+      // Install
+      controller.install(builder.getBeanMetaData());
+      
+      return builder.getBeanMetaData();
+   }
+   
+   public void test() throws Throwable
+   {
+      // InstallBean
+      BeanMetaData md = installBean();
+      
+      // setUp beanICF
+      BeanMetaDataICF beanICF = new BeanMetaDataICF();
+      beanICF.setController(controller);
+      beanICF.setDelegateICF(((AbstractManagedObjectFactory)getMOF()).getDefaultInstanceFactory());
+      
+      getMOF().addInstanceClassFactory(beanICF);
+      
+      KernelControllerContext ctx = (KernelControllerContext) controller.getInstalledContext("SimpleAnnotatedBean");
+      assertNotNull(ctx);
+      
+      MetaData metaData = kernel.getMetaDataRepository().getMetaData(ctx);
+      assertNotNull(metaData);
+      
+      ManagedObject mo = getMOF().initManagedObject(md, null, metaData, "SimpleAnnotatedBean", null);
+      assertNotNull(mo);
+
+      PersistedManagedObject moElement = restore(mo);
+      assertNotNull(moElement);
+
+      // Uninstall for offline attachment persistence
+      controller.uninstall("SimpleAnnotatedBean");
+      
+      ManagedGenericOverrideHandler override = new ManagedGenericOverrideHandler();
+      // Try to restore the information without the installed bean      
+      mo = getMOF().initManagedObject(getSimpleBeanMetaDataBuilder().getBeanMetaData(), null);
+      assertNotNull(mo);
+      
+      override.updateManagedObject(mo, moElement, mo.getAttachment());
+      Set<PropertyMetaData> properties = ((BeanMetaData)mo.getAttachment()).getProperties();
+      assertNotNull(properties);
+      // TODO
+      assertEquals(1, properties.size());
+   }
+   
+   protected BeanMetaDataBuilder getSimpleBeanMetaDataBuilder()
+   {
+      BeanMetaDataBuilder b = BeanMetaDataBuilder.createBuilder("SimpleAnnotatedBean", SimpleAnnotatedBean.class.getName());
+      b.addAnnotation("@org.jboss.managed.api.annotation.ManagementObject(name=\"simpleBean\")");
+      return b;
+   }
+   
+   
+}
+




More information about the jboss-cvs-commits mailing list