2 * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
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.
17 package org
.argeo
.slc
.hibernate
.test
.tree
;
19 import java
.sql
.SQLException
;
20 import java
.util
.Date
;
22 import org
.argeo
.slc
.core
.test
.tree
.TreeTestResult
;
23 import org
.argeo
.slc
.core
.test
.tree
.TreeTestResultCollection
;
24 import org
.argeo
.slc
.dao
.test
.tree
.TreeTestResultCollectionDao
;
25 import org
.argeo
.slc
.dao
.test
.tree
.TreeTestResultDao
;
26 import org
.argeo
.slc
.hibernate
.unit
.HibernateTestCase
;
27 import org
.argeo
.slc
.unit
.test
.tree
.TreeTestResultTestUtils
;
28 import org
.argeo
.slc
.unit
.test
.tree
.UnitTestTreeUtil
;
29 import org
.hibernate
.HibernateException
;
30 import org
.hibernate
.Session
;
31 import org
.springframework
.orm
.hibernate3
.HibernateCallback
;
33 public class TreeTestResultCollectionDaoHibernateTest
extends HibernateTestCase
{
35 public void testScenario() {
36 TreeTestResultDao ttrDao
= getBean(TreeTestResultDao
.class);
37 TreeTestResultCollectionDao ttrcDao
= getBean(TreeTestResultCollectionDao
.class);
39 String ttrcName
= "testCollection";
41 TreeTestResult ttr1
= TreeTestResultTestUtils
42 .createCompleteTreeTestResult();
45 TreeTestResultCollection ttrc
= new TreeTestResultCollection(ttrcName
);
48 ttrc
.getResults().add(ttr1
);
51 final TreeTestResult ttr2
= TreeTestResultTestUtils
52 .createCompleteTreeTestResult();
55 ttrc
.getResults().add(ttr2
);
58 ttrc
.getResults().remove(ttr1
);
61 final TreeTestResultCollection ttrcPersist
= ttrcDao
62 .getTestResultCollection(ttrcName
);
64 // Because of lazy initialization
65 getHibernateTemplate().execute(new HibernateCallback() {
67 public Object
doInHibernate(Session session
)
68 throws HibernateException
, SQLException
{
69 session
.refresh(ttrcPersist
);
70 assertEquals(1, ttrcPersist
.getResults().size());
71 UnitTestTreeUtil
.assertTreeTestResult(ttr2
, ttrcPersist
72 .getResults().iterator().next());
78 public void testResultsWithSameCloseDate() {
79 TreeTestResultDao ttrDao
= getBean(TreeTestResultDao
.class);
80 TreeTestResultCollectionDao ttrcDao
= getBean(TreeTestResultCollectionDao
.class);
82 String ttrcName
= "testCollection";
84 Date closeDate
= new Date();
87 TreeTestResult ttr1
= TreeTestResultTestUtils
88 .createCompleteTreeTestResult();
89 ttr1
.setCloseDate(closeDate
);
93 TreeTestResult ttr2
= TreeTestResultTestUtils
94 .createCompleteTreeTestResult();
95 ttr2
.setCloseDate(closeDate
);
99 TreeTestResultCollection ttrc
= new TreeTestResultCollection(ttrcName
);
100 ttrc
.getResults().add(ttr1
);
101 ttrc
.getResults().add(ttr2
);
102 ttrcDao
.create(ttrc
);
104 final TreeTestResultCollection ttrcPersist
= ttrcDao
105 .getTestResultCollection(ttrcName
);
106 // Because of lazy initialization
107 getHibernateTemplate().execute(new HibernateCallback() {
109 public Object
doInHibernate(Session session
)
110 throws HibernateException
, SQLException
{
111 session
.refresh(ttrcPersist
);
112 assertEquals(2, ttrcPersist
.getResults().size());
119 protected String
getApplicationContextLocation() {
120 return "org/argeo/slc/hibernate/applicationContext.xml";