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.Target;
19 /**
20 * JUnit test case for testing TargetDao implementation.
21 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
22 * @version $Revision: 1.1 $
23 */
24 public class TargetDaoTest extends SpringTestCase{
25
26
27
28 /** Spring configuration files */
29 private String[] configLocations = new String[]{"classpath:/org/figure8/join/businessobjects/commons/persistence/spring.xml"};
30
31
32
33
34 /** The target dao implementation to test */
35 protected TargetDao dao = null;
36
37
38
39
40 /** Retrieve target dao after having initialized context */
41 public void setUp(){
42 super.setUp();
43
44 dao = (TargetDao)context.getBean("targetDao");
45 }
46
47
48
49
50 /** Test the target creation */
51 public void testTargetCreation(){
52
53 Target target = new Target("creationTarget", "creationDescription");
54 int size = getTargetListSize();
55 dao.save(target);
56
57 assertEquals("Target is successfully created", size + 1, dao.findAll().size());
58 }
59
60 /** Test the getByName() method */
61 public void testFindByName(){
62
63 Target target = new Target("findByNameTarget", "findByNameDescription");
64 int size = getTargetListSize();
65 dao.save(target);
66
67 assertEquals("Target is successfully created", size + 1, dao.findAll().size());
68
69 Target foundTarget = dao.getTarget("findByNameTarget");
70 assertNotNull("Found a target", foundTarget);
71 assertEquals("Found a target with correct name", "findByNameTarget", foundTarget.getName());
72 assertEquals("Found a target with correct decription", "findByNameDescription", foundTarget.getDescription());
73 }
74
75 /** Test the removal of a target */
76 public void testTargetRemoval(){
77
78 Target target = new Target("removalTarget", "removalDescription");
79 int size = getTargetListSize();
80 dao.save(target);
81
82 assertEquals("Target is successfully created", size + 1, dao.findAll().size());
83
84 dao.remove(target);
85 assertEquals("Target is successfully removed", size, dao.findAll().size());
86 }
87
88
89
90 /** Test the findAll on target */
91 protected int getTargetListSize(){
92 return dao.findAll().size();
93 }
94
95
96
97
98 /** @return configLocations inner field */
99 public String[] getConfigLocations(){
100 return configLocations;
101 }
102 }