2 * Copyright (C) 2007-2012 Mathieu Baudier
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.argeo
.slc
.hibernate
.process
;
18 import java
.sql
.SQLException
;
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
;
33 public class CastorSlcExecutionHibernateTest
extends HibernateTestCase
{
35 public void testSaveWithRealizedFlowsXml() throws Exception
{
36 SlcExecutionDao dao
= getBean(SlcExecutionDao
.class);
38 SlcExecution slcExec
= SlcExecutionTestUtils
39 .createSlcExecutionWithRealizedFlows();
41 ObjectList ol
= new ObjectList(slcExec
.getRealizedFlows());
42 StringResult result
= new StringResult();
43 getBean(Marshaller
.class).marshal(ol
, result
);
44 slcExec
.setRealizedFlowsXml(result
.toString());
48 SlcExecution slcExecPersisted
= dao
.getSlcExecution(slcExec
.getUuid());
49 assertSlcExecution(slcExec
, slcExecPersisted
);
51 StringSource source
= new StringSource(slcExecPersisted
52 .getRealizedFlowsXml());
53 ObjectList ol2
= (ObjectList
) getBean(Unmarshaller
.class).unmarshal(
55 ol2
.fill(slcExec
.getRealizedFlows());
59 public void assertSlcExecution(final SlcExecution expected
,
60 final SlcExecution persisted
) {
61 getHibernateTemplate().execute(new HibernateCallback() {
63 public Object
doInHibernate(Session session
)
64 throws HibernateException
, SQLException
{
65 session
.refresh(persisted
);
66 SlcExecutionTestUtils
.assertSlcExecution(expected
, persisted
);
73 protected String
getApplicationContextLocation() {
74 return "org/argeo/slc/hibernate/withCastor.xml";