[jboss-svn-commits] JBL Code SVN: r29524 - in labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/stm/xml: model and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Oct 1 12:59:14 EDT 2009


Author: whitingjr
Date: 2009-10-01 12:59:14 -0400 (Thu, 01 Oct 2009)
New Revision: 29524

Added:
   labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/
   labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/TestModelMapDataAdapter.java
Log:
Added xml JAXB classes for marshalling data.

Added: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/TestModelMapDataAdapter.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/TestModelMapDataAdapter.java	                        (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/TestModelMapDataAdapter.java	2009-10-01 16:59:14 UTC (rev 29524)
@@ -0,0 +1,120 @@
+ /*
+  * JBoss, Home of Professional Open Source
+  * Copyright 2005, JBoss Inc., and individual contributors as indicated
+  * by the @authors tag. See the copyright.txt 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 uk.ac.ncl.sdia.a8905943.stm.xml.model;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Assert;
+
+import org.apache.log4j.Logger;
+import org.junit.Test;
+
+import uk.ac.ncl.sdia.a8905943.model.Bike;
+import uk.ac.ncl.sdia.a8905943.model.Car;
+import uk.ac.ncl.sdia.a8905943.model.LeccyCar;
+
+public class TestModelMapDataAdapter
+{
+   private static final Logger logger = Logger.getLogger(TestModelMapDataAdapter.class);
+   @Test
+   public void testCheckMarshallWorks()
+   {
+      try
+      {
+         Map<String, List<Object>> modelMap = new HashMap<String, List<Object>>();
+         List<Object> entityListA = new ArrayList<Object>();
+         modelMap.put(LeccyCar.class.getName(), entityListA);
+         entityListA.add(new LeccyCar(1l));
+         entityListA.add(new LeccyCar(2l));
+         List<Object> entityListB = new ArrayList<Object>();
+         modelMap.put(Bike.class.getName(), entityListB);
+         entityListB.add(new Bike(3l));
+         entityListB.add(new Bike(4l));
+         ModelMapDataAdapter adapter = new ModelMapDataAdapter();
+         ModelList modelList = adapter.marshal(modelMap);
+         Assert.assertNotNull(modelList);
+         Assert.assertEquals(entityListA.size()+entityListB.size(), modelList.getSize());// check to make sure nothing has been lost
+         for (ModelEntry entry : modelList.getItem())
+         {
+            Assert.assertTrue(modelMap.containsKey(entry.modelClass));
+         }
+      }
+      catch (Exception e)
+      {
+         Assert.fail(e.getMessage());
+      }
+   }
+   @Test
+   public void testCheckUnMarshallWorks()
+   {
+      try
+      {
+         ModelList list = new ModelList();
+         list.addItem(new ModelEntry(1l, LeccyCar.class.getName()));
+         list.addItem(new ModelEntry(2l, LeccyCar.class.getName()));
+         list.addItem(new ModelEntry(3l, LeccyCar.class.getName()));
+         list.addItem(new ModelEntry(5l, Car.class.getName()));
+         list.addItem(new ModelEntry(6l, Car.class.getName()));
+         list.addItem(new ModelEntry(7l, Car.class.getName()));
+         list.addItem(new ModelEntry(8l, Car.class.getName()));
+         ModelMapDataAdapter adapter = new ModelMapDataAdapter();
+         Map<String, List<Object>> modelMap = adapter.unmarshal(list);
+         Assert.assertNotNull(modelMap);
+         Assert.assertEquals(2, modelMap.size());
+         Assert.assertEquals(3, modelMap.get(LeccyCar.class.getName()).size());
+         Assert.assertEquals(4, modelMap.get(Car.class.getName()).size());
+      }
+      catch (Exception e)
+      {
+         Assert.fail(e.getMessage());
+      }
+   }
+   /**
+    * This test detects if duplicated entries have been created. The model
+    * data structure should not have duplicated entities. The adapter is expected
+    * to detect these and not add them.
+    */
+   @Test
+   public void testCheckDuplicatesAreFiltered()
+   {
+      try
+      {
+         ModelList list = new ModelList();
+         list.addItem(new ModelEntry(1l, LeccyCar.class.getName()));
+         list.addItem(new ModelEntry(1l, LeccyCar.class.getName()));
+         ModelMapDataAdapter adapter = new ModelMapDataAdapter();
+         Map<String, List<Object>> modelMap = adapter.unmarshal(list);
+         Assert.assertNotNull(modelMap);
+         Assert.assertEquals(1, modelMap.size());
+         Assert.assertEquals(1, modelMap.get(LeccyCar.class.getName()).size());
+      }
+      catch (Exception e)
+      {
+         Assert.fail(e.getMessage());
+      }      
+   }
+}
+



More information about the jboss-svn-commits mailing list