1 /**
2 * Copyright 2005-2006 the original author or authors.
3 *
4 * Licensed under the Gnu General Pubic License, Version 2.0 (the
5 * "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/gpl-license.php
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the Gnu General Public License for more details.
14 */
15 package org.figure8.join.core.persistence;
16
17 import org.figure8.join.util.SpringTestCase;
18 import org.figure8.join.businessobjects.commons.Release;
19 import org.figure8.join.businessobjects.commons.persistence.ReleaseDao;
20 import org.figure8.join.businessobjects.artifact.Assembly;
21 import org.figure8.join.businessobjects.artifact.Deliverable;
22 import org.figure8.join.businessobjects.artifact.DeliverableType;
23 import org.figure8.join.businessobjects.artifact.persistence.AssemblyDao;
24 import org.figure8.join.businessobjects.artifact.persistence.DeliverableDao;
25 import org.figure8.join.businessobjects.artifact.persistence.DeliverableTypeDao;
26
27 import java.util.Date;
28 import java.util.List;
29 /**
30 * JUnit test case for testing Generic object dao.
31 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
32 * @version $Revision: 1.1 $
33 */
34 public class GenericHibernateObjectDaoTest extends SpringTestCase{
35
36
37
38 /** Spring configuration files */
39 private String[] configLocations = new String[]{"classpath:/org/figure8/join/core/persistence/spring.xml"};
40
41
42
43
44 /** A ReleaseDao implementation that we need */
45 protected ReleaseDao releDao = null;
46 /** The DeliverableDao implementation to test */
47 protected DeliverableDao delDao = null;
48 /** A DeliverableTypeDao implementation that we need */
49 protected DeliverableTypeDao typeDao = null;
50 /** The AssemblyDao implementation that we need */
51 protected AssemblyDao assemblyDao = null;
52 /** The GenericHibernateObjectDao to test */
53 protected GenericHibernateObjectDao dao = null;
54
55
56
57
58 /** Retrieve daos after having initialized context */
59 public void setUp(){
60 super.setUp();
61
62 releDao = (ReleaseDao)context.getBean("releaseDao");
63 delDao = (DeliverableDao)context.getBean("deliverableDao");
64 typeDao = (DeliverableTypeDao)context.getBean("deliverableTypeDao");
65 assemblyDao = (AssemblyDao)context.getBean("assemblyDao");
66 dao = (GenericHibernateObjectDao)context.getBean("genericObjectDao");
67 }
68
69
70
71
72 /** Test the find all method */
73 public void testFindAll(){
74
75 Release release = new Release("100.0", 100, 0, new Date());
76 DeliverableType foo = new DeliverableType("foo1Type", "Foo 1 Label", "foo1-{0}.{1}", true, true);
77 DeliverableType bar = new DeliverableType("bar1Type", "Bar 1 Label", "bar1-{0}.{1}", true, false);
78 Deliverable foo1 = new Deliverable("01", "comments", "supplier", release, foo);
79 Deliverable bar1 = new Deliverable("01", "comments", "supplier", release, bar);
80 Assembly assembly1 = new Assembly("1.0", "comments1", "fooId", release);
81 Assembly assembly2 = new Assembly("2.0", "comments2", "barId", release);
82 releDao.save(release);
83 typeDao.save(foo);
84 typeDao.save(bar);
85 delDao.save(foo1);
86 delDao.save(bar1);
87 assembly1.addDeliverable(foo1);
88 assembly2.addDeliverable(foo1);
89 assembly2.addDeliverable(bar1);
90 assemblyDao.save(assembly1);
91 assemblyDao.save(assembly2);
92
93 List objects = dao.findAll();
94 assertEquals("All persistent objects are found", 7, objects.size());
95 assertTrue(objects.contains(release));
96 assertTrue(objects.contains(foo));
97 assertTrue(objects.contains(bar));
98 assertTrue(objects.contains(foo1));
99 assertTrue(objects.contains(bar1));
100 assertTrue(objects.contains(assembly1));
101 assertTrue(objects.contains(assembly2));
102 }
103
104
105
106
107 /** @return configLocations inner field */
108 public String[] getConfigLocations(){
109 return configLocations;
110 }
111 }