+package org.argeo.slc.hibernate.process;\r
+\r
+import java.sql.SQLException;\r
+\r
+import org.argeo.slc.dao.process.SlcExecutionDao;\r
+import org.argeo.slc.hibernate.unit.HibernateTestCase;\r
+import org.argeo.slc.msg.ObjectList;\r
+import org.argeo.slc.process.SlcExecution;\r
+import org.argeo.slc.unit.process.SlcExecutionTestUtils;\r
+import org.hibernate.HibernateException;\r
+import org.hibernate.Session;\r
+import org.springframework.orm.hibernate3.HibernateCallback;\r
+import org.springframework.oxm.Marshaller;\r
+import org.springframework.oxm.Unmarshaller;\r
+import org.springframework.xml.transform.StringResult;\r
+import org.springframework.xml.transform.StringSource;\r
+\r
+public class CastorSlcExecutionHibernateTest extends HibernateTestCase {\r
+\r
+ public void testSaveWithRealizedFlowsXml() throws Exception {\r
+ SlcExecutionDao dao = getBean(SlcExecutionDao.class);\r
+\r
+ SlcExecution slcExec = SlcExecutionTestUtils\r
+ .createSlcExecutionWithRealizedFlows();\r
+\r
+ ObjectList ol = new ObjectList(slcExec.getRealizedFlows());\r
+ StringResult result = new StringResult();\r
+ getBean(Marshaller.class).marshal(ol, result);\r
+ slcExec.setRealizedFlowsXml(result.toString());\r
+\r
+ dao.create(slcExec);\r
+\r
+ SlcExecution slcExecPersisted = dao.getSlcExecution(slcExec.getUuid());\r
+ assertSlcExecution(slcExec, slcExecPersisted);\r
+\r
+ StringSource source = new StringSource(slcExecPersisted\r
+ .getRealizedFlowsXml());\r
+ ObjectList ol2 = (ObjectList) getBean(Unmarshaller.class).unmarshal(\r
+ source);\r
+ ol2.fill(slcExec.getRealizedFlows());\r
+\r
+ }\r
+\r
+ public void assertSlcExecution(final SlcExecution expected,\r
+ final SlcExecution persisted) {\r
+ getHibernateTemplate().execute(new HibernateCallback() {\r
+\r
+ public Object doInHibernate(Session session)\r
+ throws HibernateException, SQLException {\r
+ session.refresh(persisted);\r
+ SlcExecutionTestUtils.assertSlcExecution(expected, persisted);\r
+ return null;\r
+ }\r
+ });\r
+ }\r
+\r
+ @Override\r
+ protected String getApplicationContextLocation() {\r
+ return "org/argeo/slc/hibernate/withCastor.xml";\r
+ }\r
+}\r