]> 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
Introduce H
[gpl/argeo-slc.git] / runtime / org.argeo.slc.support.hibernate / src / test / java / org / argeo / slc / hibernate / process / CastorSlcExecutionHibernateTest.java
1 /*
2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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
17 package org.argeo.slc.hibernate.process;
18
19 import java.sql.SQLException;
20
21 import org.argeo.slc.dao.process.SlcExecutionDao;
22 import org.argeo.slc.hibernate.unit.HibernateTestCase;
23 import org.argeo.slc.msg.ObjectList;
24 import org.argeo.slc.process.SlcExecution;
25 import org.argeo.slc.unit.process.SlcExecutionTestUtils;
26 import org.hibernate.HibernateException;
27 import org.hibernate.Session;
28 import org.springframework.orm.hibernate3.HibernateCallback;
29 import org.springframework.oxm.Marshaller;
30 import org.springframework.oxm.Unmarshaller;
31 import org.springframework.xml.transform.StringResult;
32 import org.springframework.xml.transform.StringSource;
33
34 public class CastorSlcExecutionHibernateTest extends HibernateTestCase {
35
36 public void testSaveWithRealizedFlowsXml() throws Exception {
37 SlcExecutionDao dao = getBean(SlcExecutionDao.class);
38
39 SlcExecution slcExec = SlcExecutionTestUtils
40 .createSlcExecutionWithRealizedFlows();
41
42 ObjectList ol = new ObjectList(slcExec.getRealizedFlows());
43 StringResult result = new StringResult();
44 getBean(Marshaller.class).marshal(ol, result);
45 slcExec.setRealizedFlowsXml(result.toString());
46
47 dao.create(slcExec);
48
49 SlcExecution slcExecPersisted = dao.getSlcExecution(slcExec.getUuid());
50 assertSlcExecution(slcExec, slcExecPersisted);
51
52 StringSource source = new StringSource(slcExecPersisted
53 .getRealizedFlowsXml());
54 ObjectList ol2 = (ObjectList) getBean(Unmarshaller.class).unmarshal(
55 source);
56 ol2.fill(slcExec.getRealizedFlows());
57
58 }
59
60 public void assertSlcExecution(final SlcExecution expected,
61 final SlcExecution persisted) {
62 getHibernateTemplate().execute(new HibernateCallback() {
63
64 public Object doInHibernate(Session session)
65 throws HibernateException, SQLException {
66 session.refresh(persisted);
67 SlcExecutionTestUtils.assertSlcExecution(expected, persisted);
68 return null;
69 }
70 });
71 }
72
73 @Override
74 protected String getApplicationContextLocation() {
75 return "org/argeo/slc/hibernate/withCastor.xml";
76 }
77 }