[jboss-svn-commits] JBL Code SVN: r29537 - in labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM: src/main/java/uk/ac/ncl/sdia/a8905943/entitymanager and 8 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Oct 5 12:43:55 EDT 2009
Author: whitingjr
Date: 2009-10-05 12:43:54 -0400 (Mon, 05 Oct 2009)
New Revision: 29537
Modified:
labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/pom.xml
labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/entitymanager/STMEntityManagerImpl.java
labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/model/LeccyCar.java
labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/STM.java
labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/object/TransactedObjectReference.java
labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/STMQueryImpl.java
labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/ModelMapDataAdapter.java
labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/entitymanager/TestSTMEntityManagerImpl.java
labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/stm/xml/TestToXml.java
labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/TestModelMapDataAdapter.java
Log:
Added test cases, xml mapping.
Modified: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/pom.xml
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/pom.xml 2009-10-05 14:09:25 UTC (rev 29536)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/pom.xml 2009-10-05 16:43:54 UTC (rev 29537)
@@ -35,6 +35,12 @@
<version>4.5</version>
<scope>compile</scope>
</dependency>
+ <dependency>
+ <groupId>xmlunit</groupId>
+ <artifactId>xmlunit</artifactId>
+ <version>1.2</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
<plugins>
Modified: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/entitymanager/STMEntityManagerImpl.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/entitymanager/STMEntityManagerImpl.java 2009-10-05 14:09:25 UTC (rev 29536)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/entitymanager/STMEntityManagerImpl.java 2009-10-05 16:43:54 UTC (rev 29537)
@@ -190,7 +190,7 @@
Query returnValue = null;
if (null != qlString)
{
- returnValue = new STMQueryImpl(this.xpathContext, qlString, getSTMConnection().getSTM().getDeletedEntityFilter(qlString));
+ returnValue = new STMQueryImpl(this.xpathContext, qlString);
}
else
{
@@ -199,33 +199,8 @@
}
return returnValue;
}
+
/**
- *
- * @param qlString
- * @param filter
- * @deprecated
- * @throws IllegalArgumentException
- */
- private Query createQuery( String qlString, Filter filter)
- throws IllegalArgumentException
- {
- detectectClosedConnection();
- Query returnValue = null;
- if (null != qlString && null != filter)
- {
- returnValue = new STMQueryImpl(this.xpathContext, qlString, filter);
- }
- else
- {
- throw new IllegalArgumentException(
- "The query string or filter provided is null.");
- }
- return returnValue;
- }
-
- @SuppressWarnings("unchecked")
- @Override
- /**
* To call this method the entity object is expected to follow this contract.
* Entity has one constructor that is public, contains only one field and is of
* type {@link java.lang.Long}.
@@ -234,6 +209,8 @@
* an instance of the entity.
* Returns the entity or null if not found.
*/
+ @SuppressWarnings("unchecked")
+ @Override
@STMDisabled
public <T> T find(Class<T> entityClass, Object primaryKey)
{
@@ -249,18 +226,7 @@
{
Field idField = fieldUtils.findIdField(entityClass);
StringBuffer queryStatement = new StringBuffer();
- /* Use custom function to filter the returned entities. The function is
- * used here because the EntityManager is manually building the query
- * expression. */
- /*
queryStatement.append("model/").append(entityClass.getName()).append(
- "[").append(idField.getName());
- queryStatement.append("=$identityValue and stmf:notin(").append(idField.getName()).append(")]");
- Query query = this.createQuery(queryStatement.toString(), new NoOpFilter());
- query.setParameter("identityValue", primaryKey);
- query.setParameter("exclusionList", getSTMConnection().getSTM().getDeletedEntities(entityClass));
- */
- queryStatement.append("model/").append(entityClass.getName()).append(
"[").append(idField.getName()).append("=$identityValue]");
Query query = this.createQuery(queryStatement.toString());
query.setParameter("identityValue", primaryKey);
Modified: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/model/LeccyCar.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/model/LeccyCar.java 2009-10-05 14:09:25 UTC (rev 29536)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/model/LeccyCar.java 2009-10-05 16:43:54 UTC (rev 29537)
@@ -6,6 +6,8 @@
*/
package uk.ac.ncl.sdia.a8905943.model;
+import org.apache.commons.lang.builder.HashCodeBuilder;
+
import uk.ac.ncl.sdia.a8905943.aspects.annotation.STMReadable;
import uk.ac.ncl.sdia.a8905943.aspects.annotation.STMWriteable;
import uk.ac.ncl.sdia.a8905943.aspects.annotation.collections.set.STMCollectionAdd;
@@ -70,6 +72,11 @@
}
return returnValue;
}
+ @Override
+ public int hashCode()
+ {
+ return new HashCodeBuilder().append(this.getClass().getName()).append(this.getId()).toHashCode();
+ }
}
Modified: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/STM.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/STM.java 2009-10-05 14:09:25 UTC (rev 29536)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/STM.java 2009-10-05 16:43:54 UTC (rev 29537)
@@ -2,18 +2,14 @@
import java.util.HashMap;
import java.util.HashSet;
-import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.transaction.Status;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
-import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapters;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.builder.EqualsBuilder;
@@ -35,6 +31,7 @@
import uk.ac.ncl.sdia.a8905943.stm.transaction.PrepareParameter;
import uk.ac.ncl.sdia.a8905943.stm.transaction.STMTransaction;
import uk.ac.ncl.sdia.a8905943.stm.transaction.TransactionManager;
+import uk.ac.ncl.sdia.a8905943.stm.xml.field.FieldMapDataAdapter;
import uk.ac.ncl.sdia.a8905943.stm.xml.model.ModelMapDataAdapter;
/**
@@ -52,10 +49,10 @@
{
@XmlTransient private final String databaseName;
@XmlTransient private static final Logger logger = Logger.getLogger(STM.class);
+ @XmlJavaTypeAdapter (FieldMapDataAdapter.class)
+ private final Map<Long, TransactedObjectReference> transactedFieldMemory ;
@XmlJavaTypeAdapter (ModelMapDataAdapter.class)
- private final Map<Long, TransactedObjectReference> transactedFieldMemory ;
-
- @XmlTransient private final Map<String, Set<Object>> transactedModelMemory;
+ private final Map<String, Set<Object>> transactedModelMemory;
@XmlTransient private final TransactionManager transactionManager = new TransactionManager();
@XmlTransient private ThreadLocal<Integer> isolationLevel = new ThreadLocal<Integer>();
@XmlTransient private ThreadLocal<Integer> timeoutPeriod = new ThreadLocal<Integer>();
@@ -236,8 +233,9 @@
}
/**
- * This method filters the model object to remove all the
- * deleted entities for this transaction.
+ * This method returns a clone model object to remove all the
+ * deleted entities for this transaction. Changes to this
+ * collection are not passed onto the underlying representation.
* This implementation is not going to have fantastic performance.
*
* @return filter collection of current Entities
@@ -277,6 +275,16 @@
return returnValue;
}
+ /**
+ * This method returns the actual underlying model object.
+ *
+ * @return
+ */
+ public Map<String, Set<Object>> getBaseModel()
+ {
+ return this.transactedModelMemory;
+ }
+
public void setTimeout(int timeout)
{
if (0 >= timeout)
Modified: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/object/TransactedObjectReference.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/object/TransactedObjectReference.java 2009-10-05 14:09:25 UTC (rev 29536)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/object/TransactedObjectReference.java 2009-10-05 16:43:54 UTC (rev 29537)
@@ -11,16 +11,26 @@
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.locks.ReentrantReadWriteLock;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlTransient;
+import javax.xml.bind.annotation.XmlValue;
+
import org.apache.commons.lang.builder.EqualsBuilder;
public class TransactedObjectReference implements Serializable
{
/** The serialVersionUID */
+ @XmlTransient
private static final long serialVersionUID = 2497531722707627406L;
+ @XmlAttribute
final Long lookupIdentity;
+ @XmlValue
protected AtomicReference<Object> value = new AtomicReference<Object>();
+ @XmlAttribute
protected AtomicLong version = new AtomicLong();
+ @XmlTransient
transient final ReentrantReadWriteLock prepared = new ReentrantReadWriteLock(true);
+ @XmlTransient
protected transient Long preparedVersion ;
public TransactedObjectReference(Long identity, Object value, long version)
@@ -87,4 +97,8 @@
{
this.preparedVersion = preparedVersion;
}
+ public TransactedObjectReference()
+ {
+
+ }
}
Modified: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/STMQueryImpl.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/STMQueryImpl.java 2009-10-05 14:09:25 UTC (rev 29536)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/STMQueryImpl.java 2009-10-05 16:43:54 UTC (rev 29537)
@@ -36,13 +36,11 @@
import org.apache.commons.jxpath.JXPathContext;
import uk.ac.ncl.sdia.a8905943.stm.activation.STMDisabled;
-import uk.ac.ncl.sdia.a8905943.stm.query.filter.Filter;
public class STMQueryImpl implements Query {
private final String query;
private final JXPathContext xpathContext;
- private final Filter filter;
@Override
public int executeUpdate() {
@@ -54,9 +52,7 @@
@Override
@STMDisabled
public List getResultList() {
- List returnValue = IteratorUtils.toList(this.xpathContext.iterate(this.query));
- this.filter.filter (returnValue);
- return returnValue;
+ return IteratorUtils.toList(this.xpathContext.iterate(this.query));
}
/**
@@ -147,11 +143,9 @@
// FIXME setParameter
return null;
}
-
- public STMQueryImpl(JXPathContext context, String expression, Filter resultFilter)
- {
- this.xpathContext= context;
- this.query = expression;
- this.filter = resultFilter;
- }
+ public STMQueryImpl(JXPathContext context, String expression)
+ {
+ this.xpathContext= context;
+ this.query = expression;
+ }
}
Modified: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/ModelMapDataAdapter.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/ModelMapDataAdapter.java 2009-10-05 14:09:25 UTC (rev 29536)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/ModelMapDataAdapter.java 2009-10-05 16:43:54 UTC (rev 29537)
@@ -23,9 +23,9 @@
package uk.ac.ncl.sdia.a8905943.stm.xml.model;
import java.lang.reflect.Constructor;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import javax.xml.bind.annotation.adapters.XmlAdapter;
@@ -34,10 +34,10 @@
import uk.ac.ncl.sdia.a8905943.handle.FieldUtils;
-public class ModelMapDataAdapter extends XmlAdapter<ModelList, Map<String, List<Object>>>
+public class ModelMapDataAdapter extends XmlAdapter<ModelList, Map<String, Set<Object>>>
{
@Override
- public ModelList marshal(Map<String, List<Object>> modelMap) throws Exception
+ public ModelList marshal(Map<String, Set<Object>> modelMap) throws Exception
{
ModelList returnValue = new ModelList();
FieldUtils fieldUtils = new FieldUtils();
@@ -51,9 +51,9 @@
return returnValue;
}
@Override
- public Map<String, List<Object>> unmarshal(ModelList serialisedModel) throws Exception
+ public Map<String, Set<Object>> unmarshal(ModelList serialisedModel) throws Exception
{
- Map<String, List<Object>> returnValue = new ConcurrentHashMap<String, List<Object>>();
+ Map<String, Set<Object>> returnValue = new ConcurrentHashMap<String, Set<Object>>();
for (ModelEntry entry : serialisedModel.getItem())
{
Class entityClass = ClassUtils.getClass(entry.modelClass);
@@ -62,7 +62,7 @@
if (!returnValue.containsKey(entry.modelClass))
{// place a list object in the map for the entity type
- returnValue.put(entry.modelClass, new ArrayList<Object>());
+ returnValue.put(entry.modelClass, new HashSet<Object>());
}
if (!returnValue.get(entry.modelClass).contains(instance))
{// place the entity instance in the map if not present already
@@ -71,5 +71,4 @@
}
return returnValue;
}
-
}
Modified: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/entitymanager/TestSTMEntityManagerImpl.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/entitymanager/TestSTMEntityManagerImpl.java 2009-10-05 14:09:25 UTC (rev 29536)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/entitymanager/TestSTMEntityManagerImpl.java 2009-10-05 16:43:54 UTC (rev 29537)
@@ -1,6 +1,5 @@
package uk.ac.ncl.sdia.a8905943.entitymanager;
-import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -33,14 +32,13 @@
*/
@Test
public void testCheckContainsMethodWorks() {
- Map<String, Set<Object>> modelStore = this.stm.getModel();
Long carId = new Long(1);
LeccyCar car = new LeccyCar(carId);
Set<Object> carList = new HashSet<Object>();
carList.add(car);
String carFQCN = "uk.ac.ncl.sdia.a8905943.model.LeccyCar";
Assert.assertEquals(carFQCN, car.getClass().getName());
- modelStore.put(car.getClass().getName(), carList);
+ this.modelStore.put(car.getClass().getName(), carList);
Assert.assertNotNull(this.entityManager);
Assert.assertTrue(this.entityManager.contains(car));
@@ -59,17 +57,17 @@
* This test checks a single result query works.
*/
@Test
- public void testCheckSingleResultQueryWorks() {
+ public void testCheckSingleResultQueryWorks()
+ {
try
{
- Map<String, Set<Object>> modelStore = this.stm.getModel();
Long carId = new Long(1);
LeccyCar car = new LeccyCar(carId);
Set<Object> carList = new HashSet<Object>();
carList.add(car);
String carFQCN = "uk.ac.ncl.sdia.a8905943.model.LeccyCar";
Assert.assertEquals(carFQCN, car.getClass().getName());
- modelStore.put(car.getClass().getName(), carList);
+ this.modelStore.put(car.getClass().getName(), carList);
Assert.assertNotNull(this.entityManager);
Query query = this.entityManager.createQuery("model/"+carFQCN);
@@ -103,7 +101,6 @@
{
try
{
- Map<String, Set<Object>> modelStore = this.stm.getModel();
Long carId = new Long(1);
LeccyCar car = new LeccyCar(carId);
Set<Object> carList = new HashSet<Object>();
@@ -111,7 +108,7 @@
carList.add(new LeccyCar(new Long(2)));
String carFQCN = "uk.ac.ncl.sdia.a8905943.model.LeccyCar";
Assert.assertEquals(carFQCN, car.getClass().getName());
- modelStore.put(car.getClass().getName(), carList);
+ this.modelStore.put(car.getClass().getName(), carList);
Assert.assertNotNull(this.entityManager);
Query query = this.entityManager.createQuery("model/"+carFQCN);
@@ -126,7 +123,6 @@
@Test
public void testCheckFindEntity()
{
- Map<String, Set<Object>> modelStore = this.stm.getModel();
Long carId = new Long(1);
LeccyCar car = new LeccyCar(carId);
Set<Object> carList = new HashSet<Object>();
@@ -134,7 +130,7 @@
carList.add(new LeccyCar(new Long(2)));
String carFQCN = "uk.ac.ncl.sdia.a8905943.model.LeccyCar";
Assert.assertEquals(carFQCN, car.getClass().getName());
- modelStore.put(car.getClass().getName(), carList);
+ this.modelStore.put(car.getClass().getName(), carList);
Assert.assertNotNull(this.entityManager);
LeccyCar foundEntity = this.entityManager.find(LeccyCar.class, carId);
@@ -157,14 +153,13 @@
@Test (expected=EntityExistsException.class)
public void testCheckPersistThrowsEntityExistsExceptino()
{
- Map<String, Set<Object>> modelStore = this.stm.getModel();
Long carId = new Long(1);
LeccyCar car = new LeccyCar(carId);
Set<Object> carList = new HashSet<Object>();
carList.add(car);
String carFQCN = "uk.ac.ncl.sdia.a8905943.model.LeccyCar";
Assert.assertEquals(carFQCN, car.getClass().getName());
- modelStore.put(car.getClass().getName(), carList);
+ this.modelStore.put(car.getClass().getName(), carList);
LeccyCar duplicate = new LeccyCar(new Long(1));
Assert.assertEquals(car.getId(), duplicate.getId());
@@ -175,13 +170,12 @@
@Test
public void testCheckQueryDoesNotReturnRemovedEntity()
{
- Map<String, Set<Object>> modelStore = this.stm.getModel();
Long carId = new Long(1);
LeccyCar car = new LeccyCar(carId);
Set<Object> carList = new HashSet<Object>();
carList.add(car);
carList.add(new LeccyCar(new Long(5)));
- modelStore.put(car.getClass().getName(), carList);
+ this.modelStore.put(car.getClass().getName(), carList);
this.entityManager.remove(car);
Query query = this.entityManager.createQuery("model/"+car.getClass().getName());
@@ -217,7 +211,6 @@
@Test
public void testCheckFindingDeletedAfterAdding()
{
- Map<String, Set<Object>> modelStore = this.stm.getModel();
Long carId = new Long(1);
LeccyCar car = new LeccyCar(carId);
Set<Object> carList = new HashSet<Object>();
@@ -225,7 +218,7 @@
carList.add(new LeccyCar(new Long(2)));
String carFQCN = "uk.ac.ncl.sdia.a8905943.model.LeccyCar";
Assert.assertEquals(carFQCN, car.getClass().getName());
- modelStore.put(car.getClass().getName(), carList);
+ this.modelStore.put(car.getClass().getName(), carList);
Assert.assertNotNull(this.entityManager);
LeccyCar foundEntity = this.entityManager.find(LeccyCar.class, carId);
Modified: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/stm/xml/TestToXml.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/stm/xml/TestToXml.java 2009-10-05 14:09:25 UTC (rev 29536)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/stm/xml/TestToXml.java 2009-10-05 16:43:54 UTC (rev 29537)
@@ -22,10 +22,32 @@
package uk.ac.ncl.sdia.a8905943.stm.xml;
+import java.io.BufferedOutputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Marshaller;
+import javax.xml.xpath.XPathExpressionException;
+
+import junit.framework.Assert;
+
+import org.apache.commons.io.IOUtils;
import org.apache.log4j.Logger;
+import org.custommonkey.xmlunit.XMLAssert;
+import org.custommonkey.xmlunit.XMLTestCase;
+import org.custommonkey.xmlunit.exceptions.XpathException;
import org.junit.Test;
+import org.xml.sax.SAXException;
+import uk.ac.ncl.sdia.a8905943.model.LeccyCar;
import uk.ac.ncl.sdia.a8905943.stm.AbstractUnitT;
+import uk.ac.ncl.sdia.a8905943.stm.STM;
public class TestToXml extends AbstractUnitT
{
@@ -37,28 +59,50 @@
*/
@Test
- public void testCheckTORIsSerialized()
+ public void testCheckModelIsSerialized()
{
- /*Long id = 3l;
- String make = "Ford";
- Long version = 1l;
- Car car = new Car(id);
- Long handle = new HandleUtils().getHandle(Car.class, id, "make") ;
- TransactedObjectReference reference = new TransactedObjectReference(handle, make, version);
- this.fieldStore.put(handle, reference);
- Writer writer = new StringWriter();
+ Long carId = new Long(1);
+ LeccyCar car = new LeccyCar(carId);
+ Set<Object> carList = new HashSet<Object>();
+ carList.add(car);
+ this.modelStore.put(car.getClass().getName(), carList);
+
+ BufferedOutputStream outStream = null;
+ Writer sWriter = new StringWriter();
try
{
+ //outStream= new BufferedOutputStream( new FileOutputStream("testCheckTORIsSerialized.xml"));
JAXBContext context = JAXBContext.newInstance(STM.class);
Marshaller marshaller = context.createMarshaller();
- marshaller.setProperty(marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
- marshaller.marshal(this.stm, writer);
- logger.info(writer.toString());
+ //marshaller.marshal(this.stm, outStream);
+ marshaller.marshal(this.stm, sWriter);
+ logger.info("XML generated ["+sWriter.toString()+"]");
+ XMLAssert.assertXpathExists("/stm/transactedModelMemory/item", sWriter.toString());
+ XMLAssert.assertXpathEvaluatesTo(carId.toString(), "/stm/transactedModelMemory/item", sWriter.toString());
+ XMLAssert.assertXpathExists("/stm/transactedModelMemory/item/@modelClass", sWriter.toString());
+ XMLAssert.assertXpathEvaluatesTo(LeccyCar.class.getName(), "/stm/transactedModelMemory/item/@modelClass", sWriter.toString());
}
catch (JAXBException jaxbe)
{
Assert.fail(jaxbe.getMessage());
}
- */
+ catch (IOException ioe)
+ {
+ Assert.fail(ioe.getMessage());
+ }
+ catch (XpathException xpee)
+ {
+ Assert.fail(xpee.getMessage());
+ }
+ catch (SAXException saxe)
+ {
+ Assert.fail(saxe.getMessage());
+ }
+ finally
+ {
+ IOUtils.closeQuietly( outStream);
+ IOUtils.closeQuietly(sWriter);
+ }
}
+
}
Modified: 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 2009-10-05 14:09:25 UTC (rev 29536)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/test/java/uk/ac/ncl/sdia/a8905943/stm/xml/model/TestModelMapDataAdapter.java 2009-10-05 16:43:54 UTC (rev 29537)
@@ -24,8 +24,10 @@
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import java.util.Set;
import junit.framework.Assert;
@@ -44,12 +46,12 @@
{
try
{
- Map<String, List<Object>> modelMap = new HashMap<String, List<Object>>();
- List<Object> entityListA = new ArrayList<Object>();
+ Map<String, Set<Object>> modelMap = new HashMap<String, Set<Object>>();
+ Set<Object> entityListA = new HashSet<Object>();
modelMap.put(LeccyCar.class.getName(), entityListA);
entityListA.add(new LeccyCar(1l));
entityListA.add(new LeccyCar(2l));
- List<Object> entityListB = new ArrayList<Object>();
+ Set<Object> entityListB = new HashSet<Object>();
modelMap.put(Bike.class.getName(), entityListB);
entityListB.add(new Bike(3l));
entityListB.add(new Bike(4l));
@@ -81,7 +83,7 @@
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);
+ Map<String, Set<Object>> modelMap = adapter.unmarshal(list);
Assert.assertNotNull(modelMap);
Assert.assertEquals(2, modelMap.size());
Assert.assertEquals(3, modelMap.get(LeccyCar.class.getName()).size());
@@ -106,7 +108,7 @@
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);
+ Map<String, Set<Object>> modelMap = adapter.unmarshal(list);
Assert.assertNotNull(modelMap);
Assert.assertEquals(1, modelMap.size());
Assert.assertEquals(1, modelMap.get(LeccyCar.class.getName()).size());
More information about the jboss-svn-commits
mailing list