[jboss-cvs] JBossAS SVN: r81830 - in trunk/testsuite/src: main/org/jboss/test/profileservice/persistenceformat and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sun Nov 30 09:43:20 EST 2008


Author: emuckenhuber
Date: 2008-11-30 09:43:20 -0500 (Sun, 30 Nov 2008)
New Revision: 81830

Added:
   trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/
   trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/NestedTestMetaData.java
   trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/PrimitiveMetaData.java
   trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/Serializer.java
   trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/TestMetaData.java
   trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/SimplePersistenceFormatUnitTestCase.java
   trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/TestNestedPeristenceFormatUnitTestCase.java
Modified:
   trunk/testsuite/src/main/org/jboss/test/profileservice/override/test/ProfileServiceOverrideTestCase.java
   trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/AbstractPersistenceFormatTest.java
   trunk/testsuite/src/resources/profileservice/override/testTopic-service.xml
Log:
[JBAS-3768] some basic persistence format tests.
[JBAS-6248] finally fix the jmsDestination topicService test.

Modified: trunk/testsuite/src/main/org/jboss/test/profileservice/override/test/ProfileServiceOverrideTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/profileservice/override/test/ProfileServiceOverrideTestCase.java	2008-11-30 14:39:40 UTC (rev 81829)
+++ trunk/testsuite/src/main/org/jboss/test/profileservice/override/test/ProfileServiceOverrideTestCase.java	2008-11-30 14:43:20 UTC (rev 81830)
@@ -26,6 +26,8 @@
 import org.jboss.managed.api.ManagedDeployment;
 import org.jboss.managed.api.ManagedProperty;
 import org.jboss.managed.api.ManagedDeployment.DeploymentPhase;
+import org.jboss.metatype.api.values.CollectionValue;
+import org.jboss.metatype.api.values.CompositeValue;
 import org.jboss.metatype.api.values.SimpleValueSupport;
 
 /**
@@ -79,6 +81,13 @@
          // change value
          property.setValue(SimpleValueSupport.wrap(34));
          
+         
+         ManagedProperty configProps = mc.getProperty("connection-properties");
+         assertNotNull(configProps);
+         CompositeValue collection = (CompositeValue) configProps.getValue();
+         configProps.setValue(collection);
+         
+         
          // update component
          mgtView.updateComponent(mc);
          mgtView.process();

Added: trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/NestedTestMetaData.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/NestedTestMetaData.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/NestedTestMetaData.java	2008-11-30 14:43:20 UTC (rev 81830)
@@ -0,0 +1,53 @@
+/*
+ * 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 java.io.Serializable;
+import java.util.List;
+
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+ at ManagementObject
+public class NestedTestMetaData implements Serializable
+{
+
+   List<TestMetaData> deployments;
+
+   @ManagementProperty(managed = true)
+   public List<TestMetaData> getDeployments()
+   {
+      return deployments;
+   }
+   
+   public void setDeployments(List<TestMetaData> deployments)
+   {
+      this.deployments = deployments;
+   }
+   
+   
+}
+

Added: trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/PrimitiveMetaData.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/PrimitiveMetaData.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/PrimitiveMetaData.java	2008-11-30 14:43:20 UTC (rev 81830)
@@ -0,0 +1,78 @@
+/*
+ * 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 java.io.Serializable;
+
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+ at ManagementObject
+public class PrimitiveMetaData implements Serializable
+{
+   /** The name */
+   String name;
+   
+   /** The optional name */
+   String optionalName;
+   
+   /** The integer */
+   int integer;
+
+   @ManagementProperty
+   public String getName()
+   {
+      return name;
+   }
+
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+
+   @ManagementProperty
+   public int getInteger()
+   {
+      return integer;
+   }
+
+   public void setInteger(int integer)
+   {
+      this.integer = integer;
+   }
+
+   @ManagementProperty
+   public String getOptionalName()
+   {
+      return optionalName;
+   }
+   
+   public void setOptionalName(String optionalName)
+   {
+      this.optionalName = optionalName;
+   }
+   
+}

Added: trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/Serializer.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/Serializer.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/Serializer.java	2008-11-30 14:43:20 UTC (rev 81830)
@@ -0,0 +1,97 @@
+/*
+ * 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 java.io.File;
+import java.io.Serializable;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedProperty;
+import org.jboss.system.server.profileservice.repository.AbstractFileAttachmentsSerializer;
+
+/**
+ * A test attachment serializer
+ * 
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class Serializer extends AbstractFileAttachmentsSerializer implements Serializable
+{
+   /** log */
+   boolean logToSystemOut = false;
+   
+   public void setLogToSystemOut(boolean logToSystemOut)
+   {
+      this.logToSystemOut = logToSystemOut;
+   }
+   
+   public void saveAttachment(File attachmentsStore, Object attachment) throws Exception
+   {
+      JAXBContext ctx = JAXBContext.newInstance(attachment.getClass());
+      Marshaller marshaller = ctx.createMarshaller();
+      marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE);
+      marshaller.marshal(attachment, attachmentsStore);
+      if(logToSystemOut)
+         marshaller.marshal(attachment, System.out);
+   }
+   
+   protected <T> T loadAttachment(File attachmentsStore, Class<T> expected) throws Exception
+   {
+      JAXBContext ctx = JAXBContext.newInstance(expected);
+      Unmarshaller unmarshaller = ctx.createUnmarshaller();
+      // Hack JAXB
+      if(PersistedManagedObject.class.getName().equals(expected.getName()))
+      {
+         hack(unmarshaller);
+      }
+      return (T) unmarshaller.unmarshal(attachmentsStore);
+   }
+
+   private void hack(Unmarshaller unmarshaller)
+   {
+      unmarshaller.setListener(new HackHandler());
+   }
+   
+   /**
+    * make JAXB do something useful at last.
+    */
+   private static class HackHandler extends Unmarshaller.Listener
+   {
+      @Override
+      public void afterUnmarshal(Object target, Object parent)
+      {
+         if(parent instanceof PersistedManagedObject)
+         {
+            if(target instanceof PersistedProperty)
+            {
+               PersistedProperty p = (PersistedProperty) target;
+               ((PersistedManagedObject) parent).put(p.getName(), p);
+            }
+         }
+      }
+   }   
+}
+

Added: trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/TestMetaData.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/TestMetaData.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/support/TestMetaData.java	2008-11-30 14:43:20 UTC (rev 81830)
@@ -0,0 +1,108 @@
+/*
+ * 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 java.io.Serializable;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.managed.api.annotation.ManagementObject;
+import org.jboss.managed.api.annotation.ManagementObjectID;
+import org.jboss.managed.api.annotation.ManagementProperty;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+ at ManagementObject
+public class TestMetaData implements Serializable
+{
+
+   String name;
+   
+   /** The primitive */
+   PrimitiveMetaData primitive;
+   
+   /** A primitive List */
+   List<String> list;
+   
+   Map<String, String> testMap;
+   
+   Character[] charArray;
+   
+   @ManagementProperty
+   @ManagementObjectID
+   public String getName()
+   {
+      return name;
+   }
+   
+   public void setName(String name)
+   {
+      this.name = name;
+   }
+
+   @ManagementProperty
+   public PrimitiveMetaData getPrimitive()
+   {
+      return primitive;
+   }
+   
+   public void setPrimitive(PrimitiveMetaData primitive)
+   {
+      this.primitive = primitive;
+   }
+   
+   @ManagementProperty
+   public List<String> getList()
+   {
+      return list;
+   }
+   
+   public void setList(List<String> list)
+   {
+      this.list = list;
+   }
+
+   @ManagementProperty
+   public Map<String, String> getTestMap()
+   {
+      return testMap;
+   }
+   
+   public void setTestMap(Map<String, String> testMap)
+   {
+      this.testMap = testMap;
+   }
+
+   @ManagementProperty
+   public Character[] getCharArray()
+   {
+      return charArray;
+   }
+   
+   public void setCharArray(Character[] charArray)
+   {
+      this.charArray = charArray;
+   }
+   
+}

Modified: trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/AbstractPersistenceFormatTest.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/AbstractPersistenceFormatTest.java	2008-11-30 14:39:40 UTC (rev 81829)
+++ trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/AbstractPersistenceFormatTest.java	2008-11-30 14:43:20 UTC (rev 81830)
@@ -23,6 +23,12 @@
 
 import java.io.File;
 
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.Marshaller;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.factory.ManagedObjectFactory;
+import org.jboss.metatype.api.values.MetaValueFactory;
 import org.jboss.profileservice.spi.AttachmentsSerializer;
 import org.jboss.system.server.profileservice.repository.JAXBAttachmentSerializer;
 import org.jboss.test.JBossTestCase;
@@ -34,30 +40,83 @@
 public abstract class AbstractPersistenceFormatTest extends JBossTestCase
 {
 
+   /** The managed object factory */
+   private ManagedObjectFactory managedObjectFactory = ManagedObjectFactory.getInstance();
+   
+   /** The meta value factory */
+   private MetaValueFactory metaValueFactory = MetaValueFactory.getInstance();
+   
    public AbstractPersistenceFormatTest(String name)
    {
       super(name);
    }
+
+   protected ManagedObjectFactory getMOF()
+   {
+      return this.managedObjectFactory;
+   }
    
+   protected MetaValueFactory getMVF()
+   {
+      return this.metaValueFactory;
+   }
+   
+   protected ManagedObject initManagedObject(Object o)
+   {
+      return getMOF().initManagedObject(o, null);
+   }
+   
    protected AttachmentsSerializer getAttachmentSerializer() throws Exception
    {
+      return getAttachmentSerializer(false);
+   }
+   
+   protected AttachmentsSerializer getAttachmentSerializer(boolean logToSystemOut) throws Exception
+   {
       File tempFile = File.createTempFile(getName(), null);
-      return createSerializer(tempFile);
+      return createSerializer(tempFile, logToSystemOut);
    }
 
    /**
-    * Create the attachment serializer.
-    * Use a tempfile for storing the xml.
+    * Create the attachment Serializer.
+    * Use a tempFile for storing the Xml.
     * 
-    * @param tempFile the temp file
+    * @param tempFile the temp File
     * @return a AttachmentSerializer.
     * @throws Exception
     */
    protected AttachmentsSerializer createSerializer(File tempFile) throws Exception
    {
+      return createSerializer(tempFile, false);
+   }
+   
+   protected AttachmentsSerializer createSerializer(final File tempFile, final boolean logToSystemOut) throws Exception
+   {
       JAXBAttachmentSerializer serializer = new JAXBAttachmentSerializer()
       {
+//         @Override
+//         protected <T> T loadAttachment(File attachmentsStore, Class<T> expected) throws Exception
+//         {
+//            Unmarshaller u = UnmarshallerFactory.newInstance().newUnmarshaller();
+//            JBossXBBuilder builder = new JBossXBBuilder();
+//            SchemaBinding binding = builder.build(expected);
+//            return (T) u.unmarshal(attachmentsStore.getAbsolutePath(), binding); 
+//         }
+         
          @Override
+         protected void saveAttachment(File attachmentsStore, Object attachment) throws Exception
+         {
+            log.trace("saveAttachments, attachmentsStore="+attachmentsStore+ ", attachment="+attachment);
+            JAXBContext ctx = JAXBContext.newInstance(attachment.getClass());
+            Marshaller marshaller = ctx.createMarshaller();
+            marshaller.setProperty("jaxb.formatted.output", Boolean.TRUE);
+            marshaller.marshal(attachment, attachmentsStore);
+            // log to system out ?
+            if(logToSystemOut)
+               marshaller.marshal(attachment, System.out);
+         }
+         
+         @Override
          protected File getAttachmentPath(String baseName)
          {
             // Return the temp file

Added: trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/SimplePersistenceFormatUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/SimplePersistenceFormatUnitTestCase.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/SimplePersistenceFormatUnitTestCase.java	2008-11-30 14:43:20 UTC (rev 81830)
@@ -0,0 +1,318 @@
+/*
+ * 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.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.ArrayValue;
+import org.jboss.metatype.api.values.CollectionValue;
+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.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.profileservice.spi.AttachmentsSerializer;
+import org.jboss.system.server.profileservice.persistence.ManagedObjectPeristenceHandler;
+import org.jboss.system.server.profileservice.persistence.ManagedObjectUpdateHandler;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedCompositeValue;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedProperty;
+import org.jboss.test.profileservice.persistenceformat.support.PrimitiveMetaData;
+import org.jboss.test.profileservice.persistenceformat.support.TestMetaData;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class SimplePersistenceFormatUnitTestCase extends AbstractPersistenceFormatTest
+{
+
+   public SimplePersistenceFormatUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testPrimitive() throws Exception
+   {
+      // Create initial model
+      ManagedObject mo = createPrimitiveMO();
+      assertNotNull(mo);
+      
+      ManagedProperty p = mo.getProperty("name");
+      assertNotNull(p);
+      p.setValue(SimpleValueSupport.wrap("newName"));
+      
+      p = mo.getProperty("integer");
+      p.setValue(SimpleValueSupport.wrap(111));
+      
+      mo.getProperty("optionalName").setValue(SimpleValueSupport.wrap("optional"));
+      
+      // Assert the restored information
+      PersistedManagedObject restored = process(mo);
+      assertNotNull(restored);
+      assertFalse(restored.values().isEmpty());
+      assertEquals(3, restored.values().size());
+      PersistedProperty pp0 = restored.get("name");
+      assertNotNull(pp0);
+      assertNotNull(pp0.getValue());
+      
+      
+      ManagedObjectUpdateHandler merger = new ManagedObjectUpdateHandler();
+      // init again;
+      mo = createPrimitiveMO();
+      
+      assertEquals("testName", getMVF().unwrap(mo.getProperty("name").getValue()));
+      
+      merger.processManagedObject(restored, mo);
+      
+      assertEquals("newName", getMVF().unwrap(mo.getProperty("name").getValue()));
+      assertEquals(111, getMVF().unwrap(mo.getProperty("integer").getValue()));
+      assertEquals("optional", ((SimpleValue) mo.getProperty("optionalName").getValue()).getValue());
+      
+   }
+   
+   public void testMetaDataPrimitive() throws Exception
+   {
+      ManagedObject mo = createTestMetaDataMO();
+      assertNotNull(mo);
+      ManagedProperty p = mo.getProperty("primitive");
+      assertNotNull(p);
+      
+      CompositeValue nested = (CompositeValue) p.getValue();
+      MetaValue name = nested.get("name");
+      assertNotNull(name);
+      MetaValue integer = nested.get("integer");
+      assertNotNull(integer);
+
+      // Change values
+      Map<String, MetaValue> changedMap = new HashMap<String, MetaValue>();
+      changedMap.put("name", new SimpleValueSupport(
+            (SimpleMetaType) name.getMetaType(), "newName"));
+      changedMap.put("integer", new SimpleValueSupport(
+            (SimpleMetaType) integer.getMetaType(), 111));
+      
+      // Set new values
+      p.setValue(
+            new CompositeValueSupport(nested.getMetaType(), changedMap)
+            );
+
+      // Save and restore
+      PersistedManagedObject restored = process(mo);
+      assertNotNull(restored);
+      assertFalse(restored.values().isEmpty());
+      PersistedProperty pp0 = restored.get("primitive");
+      assertNotNull(pp0);
+      PersistedCompositeValue pp1 = (PersistedCompositeValue) pp0.getValue();
+      assertNotNull(pp1);
+      assertFalse(pp1.values().isEmpty());
+      
+      // Create again
+      mo = createTestMetaDataMO();
+      
+      
+      // Merge
+      ManagedObjectUpdateHandler merger = new ManagedObjectUpdateHandler();
+      merger.processManagedObject(restored, mo);
+      
+      p = mo.getProperty("primitive");
+      nested = (CompositeValue) p.getValue();
+      name = nested.get("name");
+      assertNotNull(name);
+      integer = nested.get("integer");
+      assertNotNull(integer);
+      
+      //
+      assertEquals(111, ((SimpleValue) integer).getValue());
+      assertEquals("newName", ((SimpleValue) name).getValue());
+   }
+   
+//   public void testMetaDataList() throws Exception
+//   {
+//      
+//      ManagedObject mo = createTestMetaDataMO();
+//      assertNotNull(mo);
+//      
+//      ManagedProperty p = mo.getProperty("list");
+//      assertNotNull(p);
+//      
+//      CollectionValue cv = (CollectionValue) p.getValue(); 
+//      assertNotNull(cv);
+//      
+//      // TODO merge list
+//      fail("TODO merge list");
+//   }
+   
+   
+   public void testMetaDataMap() throws Exception
+   {
+      ManagedObject mo = createTestMetaDataMO();
+      assertNotNull(mo);
+      
+      ManagedProperty p = mo.getProperty("testMap");
+      assertNotNull(p);
+      
+      MapCompositeValueSupport composite = (MapCompositeValueSupport) p.getValue();
+      assertNotNull(composite);
+      
+      SimpleValue v = (SimpleValue) composite.get("testString2");
+      assertNotNull(v);
+      
+      composite.put("testString2", SimpleValueSupport.wrap("changedString"));
+      
+      PersistedManagedObject restored = process(mo);
+      assertNotNull(restored);
+      
+      mo = createTestMetaDataMO();
+      
+      ManagedObjectUpdateHandler handler = new ManagedObjectUpdateHandler();
+      handler.processManagedObject(restored, mo);
+      
+      p = mo.getProperty("testMap");
+      assertNotNull(p);
+      
+      CompositeValue changedComposite = (CompositeValue) p.getValue();
+      assertNotNull(changedComposite);
+      
+      v = (SimpleValue) changedComposite.get("testString2");
+      assertEquals("changedString", v.getValue());
+   }
+   
+   // TODO
+//   public void testPrimitiveArray() throws Exception
+//   {
+//      ManagedObject mo = createTestMetaDataMO();
+//      assertNotNull(mo);
+//      
+//      ManagedProperty p = mo.getProperty("charArray");
+//      assertNotNull(p);
+//      
+//      ArrayValue a = (ArrayValue) p.getValue();
+//      assertNotNull(a);
+//      
+//      SimpleValueSupport svs = (SimpleValueSupport) a.getValue(1);
+//      assertNotNull(svs);
+//      svs.setValue('H');
+//      
+//      PersistedManagedObject restored = process(mo);
+//      assertNotNull(restored);
+//      
+//      //
+//      mo = createTestMetaDataMO();
+//      
+//      ManagedObjectUpdateHandler handler = new ManagedObjectUpdateHandler();
+//      handler.processManagedObject(restored, mo);
+//      
+//      p = mo.getProperty("charArray");
+//      assertNotNull(p);
+//      
+//      a = (ArrayValue) p.getValue();
+//      assertNotNull(a);
+//      
+//      assertEquals('H', ((SimpleValue) a.getValue(1)).getValue());
+//   }
+   
+   protected PersistedManagedObject process(ManagedObject mo) throws Exception
+   {
+      // Create root;
+      PersistedManagedObject persisted = new PersistedManagedObject();
+      // Create xml elements
+      ManagedObjectPeristenceHandler handler = new ManagedObjectPeristenceHandler();
+      handler.processManagedObject(persisted, mo);
+
+      // Save
+      AttachmentsSerializer serializer = getAttachmentSerializer(true);
+      serializer.saveAttachment("test", persisted);
+      // Restore
+      return serializer.loadAttachment("test", PersistedManagedObject.class);
+   }
+   
+   protected ManagedObject createMO(Object o)
+   {
+      return getMOF().initManagedObject(o, null);
+   }
+   
+   protected ManagedObject createPrimitiveMO()
+   {
+      PrimitiveMetaData md = createPrimitive();
+      assertNotNull(md);
+      return createMO(md);
+   }
+   
+   protected ManagedObject createTestMetaDataMO()
+   {
+      return createMO(createTestMetaData());
+   }
+   
+   protected TestMetaData createTestMetaData()
+   {
+      TestMetaData test = new TestMetaData();
+      test.setPrimitive(createPrimitive());
+      
+      // Create list
+      List<String> list = new ArrayList<String>();
+      
+      list.add("String1");
+      list.add("String2");
+      list.add("String3");
+      
+      test.setList(list);
+      
+      // Create map
+      Map<String, String> map = new HashMap<String, String>();
+      
+      map.put("testString1", "string1");
+      map.put("testString2", "string2");
+      map.put("testString3", "string3");
+      
+      test.setTestMap(map);
+      
+      
+      // Create primitive array
+      
+      Character[] array = new Character[3];
+      
+      array[0] = 'A';
+      array[1] = 'B';
+      array[2] = 'C';
+      
+      test.setCharArray(array);
+      
+      return test;
+   }
+   
+   protected PrimitiveMetaData createPrimitive()
+   {
+      PrimitiveMetaData primitive = new PrimitiveMetaData();
+      primitive.setInteger(12);
+      primitive.setName("testName");
+      return primitive;
+   }
+
+}
+

Added: trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/TestNestedPeristenceFormatUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/TestNestedPeristenceFormatUnitTestCase.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/profileservice/persistenceformat/test/TestNestedPeristenceFormatUnitTestCase.java	2008-11-30 14:43:20 UTC (rev 81830)
@@ -0,0 +1,254 @@
+/*
+ * 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.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.managed.api.ManagedObject;
+import org.jboss.managed.api.ManagedProperty;
+import org.jboss.metatype.api.types.SimpleMetaType;
+import org.jboss.metatype.api.values.CollectionValue;
+import org.jboss.metatype.api.values.CompositeValue;
+import org.jboss.metatype.api.values.CompositeValueSupport;
+import org.jboss.metatype.api.values.GenericValue;
+import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.metatype.api.values.SimpleValueSupport;
+import org.jboss.profileservice.spi.AttachmentsSerializer;
+import org.jboss.system.server.profileservice.persistence.ManagedObjectPeristenceHandler;
+import org.jboss.system.server.profileservice.persistence.ManagedObjectUpdateHandler;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedCollectionValue;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedGenericValue;
+import org.jboss.system.server.profileservice.persistence.xml.PersistedManagedObject;
+import org.jboss.test.profileservice.persistenceformat.support.NestedTestMetaData;
+import org.jboss.test.profileservice.persistenceformat.support.PrimitiveMetaData;
+import org.jboss.test.profileservice.persistenceformat.support.TestMetaData;
+
+/**
+ * @author <a href="mailto:emuckenh at redhat.com">Emanuel Muckenhuber</a>
+ * @version $Revision$
+ */
+public class TestNestedPeristenceFormatUnitTestCase extends AbstractPersistenceFormatTest
+{
+
+   public TestNestedPeristenceFormatUnitTestCase(String name)
+   {
+      super(name);
+   }
+
+   public void test() throws Exception
+   {
+      ManagedObject mo = createNestedMO();
+      
+      // deployment1
+      ManagedObject deployment = getDeployment("testDeployment1", mo);
+      assertNotNull(deployment);
+      deployment.getProperty("");
+      
+      ManagedProperty p = deployment.getProperty("primitive");
+      assertNotNull(p);
+      
+      CompositeValue composite = (CompositeValue) p.getValue();
+      
+      Map<String, MetaValue> valueMap = new HashMap<String, MetaValue>();
+      valueMap.put("optionalName",
+            new SimpleValueSupport(SimpleMetaType.STRING, "changed"));
+      valueMap.put("integer", new SimpleValueSupport(
+            SimpleMetaType.INTEGER, 111));
+
+      //
+      p.setValue(new CompositeValueSupport(composite.getMetaType(), valueMap));
+
+      ManagedProperty property = deployment.getProperty("name");
+      assertNotNull(property);
+      property.setValue(SimpleValueSupport.wrap("ChangedName"));
+      
+      // deployment3
+      deployment = getDeployment("testDeployment3", mo);
+      assertNotNull(deployment);
+      
+      property = deployment.getProperty("name");
+      assertNotNull(property);
+      property.setValue(SimpleValueSupport.wrap("ChangedName3"));
+
+      PersistedManagedObject restored = process(mo);
+      assertNotNull(restored);
+      PersistedCollectionValue collection = (PersistedCollectionValue) restored.getProperties().get(0).getValue(); 
+      assertNotNull(collection);
+      PersistedManagedObject o = ((PersistedGenericValue) collection.getValues().get(0)).getManagedObject();
+      assertNotNull(o);
+      
+      // Recreate
+      mo = createNestedMO();
+      
+      ManagedObjectUpdateHandler handler = new ManagedObjectUpdateHandler();
+      handler.processManagedObject(restored, mo);
+      
+      deployment = getDeployment("ChangedName", mo); 
+      assertNotNull("changed name deployment null", deployment);
+      
+      p = deployment.getProperty("primitive");
+      assertNotNull(p);
+      
+      composite = (CompositeValue) p.getValue();
+      assertNotNull(composite);
+      
+      assertEquals("changed", ((SimpleValue)composite.get("optionalName")).getValue());
+      
+      
+      deployment = getDeployment("testDeployment2", mo);
+      assertNotNull(deployment);
+      
+      deployment = getDeployment("ChangedName3", mo);
+      assertNotNull(deployment);
+
+      // Null
+      deployment = getDeployment("testDeployment1", mo);
+      assertNull(deployment);
+      // Null
+      deployment = getDeployment("testDeployment3", mo);
+      assertNull(deployment);
+
+      NestedTestMetaData md = (NestedTestMetaData) mo.getAttachment();
+      assertNotNull(md);
+      
+      for(TestMetaData tmd : md.getDeployments())
+         log.debug(tmd);
+   }
+   
+   protected ManagedObject getDeployment(String name, ManagedObject mo)
+   {
+    
+      ManagedProperty p = mo.getProperty("deployments");
+      CollectionValue collection = (CollectionValue) p.getValue();
+      
+      assertTrue(p.getMetaType().isCollection());
+      assertNotNull("null collection", collection);
+      assertEquals(3, collection.getSize());;
+      
+      for(MetaValue value : collection)
+      {         
+         ManagedObject deployment = (ManagedObject) ((GenericValue) value).getValue();
+         
+         ManagedProperty nameProp = deployment.getProperty("name");
+         assertNotNull(nameProp);
+         
+         String deploymentName = (String) ((SimpleValue) deployment.getProperty("name").getValue()).getValue();
+         
+         if(name.equals(deploymentName))
+            return deployment; 
+      }
+      return null;
+   }
+   
+   protected PersistedManagedObject process(ManagedObject mo) throws Exception
+   {
+      // Create root;
+      PersistedManagedObject persisted = new PersistedManagedObject();
+      // Create xml elements
+      ManagedObjectPeristenceHandler handler = new ManagedObjectPeristenceHandler();
+      handler.processManagedObject(persisted, mo);
+
+      // Save
+      AttachmentsSerializer serializer = getAttachmentSerializer(true);
+      serializer.saveAttachment("test", persisted);
+      // Restore
+      return serializer.loadAttachment("test", PersistedManagedObject.class);
+   }
+   
+   protected ManagedObject createNestedMO()
+   {
+      return createMO(createNestedTestMetaData());
+   }
+   
+   protected ManagedObject createMO(Object o)
+   {
+      return getMOF().initManagedObject(o, null);
+   }
+   
+   protected NestedTestMetaData createNestedTestMetaData()
+   {
+      NestedTestMetaData test = new NestedTestMetaData();
+      
+      List<TestMetaData> deployments = new ArrayList<TestMetaData>();
+      
+      deployments.add(createTestMetaData("testDeployment1"));
+      deployments.add(createTestMetaData("testDeployment2"));
+      deployments.add(createTestMetaData("testDeployment3"));
+      
+      test.setDeployments(deployments);
+      return test;
+   }
+   
+   protected TestMetaData createTestMetaData(String name)
+   {
+      TestMetaData test = new TestMetaData();
+      
+      //
+      test.setName(name);
+      
+      // primitive
+      test.setPrimitive(createPrimitive());
+      
+      // Create list
+      List<String> list = new ArrayList<String>();
+      
+      list.add("String1");
+      list.add("String2");
+      list.add("String3");
+      
+      test.setList(list);
+      
+      // Create map
+      Map<String, String> map = new HashMap<String, String>();
+      
+      map.put("testString1", "string1");
+      map.put("testString2", "string2");
+      map.put("testString3", "string3");
+      
+      test.setTestMap(map);
+      
+      // Create primitive array
+      
+      Character[] array = new Character[3];
+      
+      array[0] = 'A';
+      array[1] = 'B';
+      array[2] = 'C';
+      
+      test.setCharArray(array);
+      
+      return test;
+   }
+   
+   protected PrimitiveMetaData createPrimitive()
+   {
+      PrimitiveMetaData primitive = new PrimitiveMetaData();
+      primitive.setInteger(12);
+      primitive.setName("testName");
+      return primitive;
+   }
+}
+

Modified: trunk/testsuite/src/resources/profileservice/override/testTopic-service.xml
===================================================================
--- trunk/testsuite/src/resources/profileservice/override/testTopic-service.xml	2008-11-30 14:39:40 UTC (rev 81829)
+++ trunk/testsuite/src/resources/profileservice/override/testTopic-service.xml	2008-11-30 14:43:20 UTC (rev 81830)
@@ -5,7 +5,6 @@
     		code="org.jboss.jms.server.destination.TopicService">
         <annotation>@org.jboss.system.deployers.managed.ManagementObjectClass(code=org.jboss.jms.server.destination.TopicServiceMO)</annotation>
         <attribute name="JNDIName">testTopic</attribute>
-        <attribute name="MessageCounterHistoryDayLimit">1</attribute>
         <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
         <depends>jboss.messaging:service=PostOffice</depends>
     </mbean>




More information about the jboss-cvs-commits mailing list