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.businessobjects.commons.persistence;
16
17 import org.figure8.join.util.SpringTestCase;
18 import org.figure8.join.businessobjects.commons.Release;
19
20 import java.util.Date;
21 /**
22 * JUnit test case for testing ReleaseDao implementation.
23 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
24 * @version $Revision: 1.2 $
25 */
26 public class ReleaseDaoTest extends SpringTestCase{
27
28
29
30 /** Spring configuration files */
31 private String[] configLocations = new String[]{"classpath:/org/figure8/join/businessobjects/commons/persistence/spring.xml"};
32
33
34
35
36 /** The ReleaseDao implementation to test */
37 protected ReleaseDao dao = null;
38
39
40
41
42 /** Retrieve ReleaseDao implementation after having initialized context */
43 public void setUp(){
44 super.setUp();
45
46 dao = (ReleaseDao)context.getBean("releaseDao");
47 }
48
49
50
51
52 /** Test Release creation */
53 public void testReleaseCreation(){
54
55 Release release = new Release("1.0", 1, 0, new Date());
56 int size = getReleaseListSize();
57 dao.save(release);
58
59 assertEquals("Release is successfully created", size + 1, dao.findAll().size());
60 }
61
62 /** Test the getByNumbers() method */
63 public void testFindByNumbers(){
64
65 Release release = new Release("2.0", 2, 0, new Date());
66 int size = getReleaseListSize();
67 dao.save(release);
68
69 assertEquals("Release is successfully created", size + 1, dao.findAll().size());
70
71 Release foundRelease = dao.getReleaseByNumbers(2, 0);
72 assertNotNull("Found a release", foundRelease);
73 assertEquals("Found a release with correct major", 2, foundRelease.getMajor());
74 assertEquals("Found a release with correct minor", 0, foundRelease.getMinor());
75 assertEquals("Found a release with correct name", "2.0", foundRelease.getName());
76 }
77
78 /** Test Release removal */
79 public void testReleaseRemoval(){
80
81 Release release = new Release("3.0", 3, 0, new Date());
82 int size = getReleaseListSize();
83 dao.save(release);
84
85 assertEquals("Release is successfully created", size + 1, dao.findAll().size());
86
87 dao.remove(release);
88 assertEquals("Release is successfully removed", size, dao.findAll().size());
89 }
90
91
92
93
94 /** Test the findAll on release */
95 protected int getReleaseListSize(){
96 return dao.findAll().size();
97 }
98
99
100
101
102 /** @return An array of locations from Spring configuration files. */
103 public String[] getConfigLocations(){
104 return configLocations;
105 }
106 }