]> git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.hibernate/src/test/java/org/argeo/slc/hibernate/process/CastorSlcExecutionHibernateTest.java
Update headers
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.hibernate / src / test / java / org / argeo / slc / hibernate / process / CastorSlcExecutionHibernateTest.java
1 /*
2 * Copyright (C) 2007-2012 Mathieu Baudier
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.argeo.slc.hibernate.process;
17
18 import java.sql.SQLException;
19
20 import org.argeo.slc.dao.process.SlcExecutionDao;
21 import org.argeo.slc.hibernate.unit.HibernateTestCase;
22 import org.argeo.slc.msg.ObjectList;
23 import org.argeo.slc.process.SlcExecution;
24 import org.argeo.slc.unit.process.SlcExecutionTestUtils;
25 import org.hibernate.HibernateException;
26 import org.hibernate.Session;
27 import org.springframework.orm.hibernate3.HibernateCallback;
28 import org.springframework.oxm.Marshaller;
29 import org.springframework.oxm.Unmarshaller;
30 import org.springframework.xml.transform.StringResult;
31 import org.springframework.xml.transform.StringSource;
32
33 public class CastorSlcExecutionHibernateTest extends HibernateTestCase {
34
35 public void testSaveWithRealizedFlowsXml() throws Exception {
36 SlcExecutionDao dao = getBean(SlcExecutionDao.class);
37
38 SlcExecution slcExec = SlcExecutionTestUtils
39 .createSlcExecutionWithRealizedFlows();
40
41 ObjectList ol = new ObjectList(slcExec.getRealizedFlows());
42 StringResult result = new StringResult();
43 getBean(Marshaller.class).marshal(ol, result);
44 slcExec.setRealizedFlowsXml(result.toString());
45
46 dao.create(slcExec);
47
48 SlcExecution slcExecPersisted = dao.getSlcExecution(slcExec.getUuid());
49 assertSlcExecution(slcExec, slcExecPersisted);
50
51 StringSource source = new StringSource(slcExecPersisted
52 .getRealizedFlowsXml());
53 ObjectList ol2 = (ObjectList) getBean(Unmarshaller.class).unmarshal(
54 source);
55 ol2.fill(slcExec.getRealizedFlows());
56
57 }
58
59 public void assertSlcExecution(final SlcExecution expected,
60 final SlcExecution persisted) {
61 getHibernateTemplate().execute(new HibernateCallback() {
62
63 public Object doInHibernate(Session session)
64 throws HibernateException, SQLException {
65 session.refresh(persisted);
66 SlcExecutionTestUtils.assertSlcExecution(expected, persisted);
67 return null;
68 }
69 });
70 }
71
72 @Override
73 protected String getApplicationContextLocation() {
74 return "org/argeo/slc/hibernate/withCastor.xml";
75 }
76 }