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.artifact.persistence;
16
17 import org.figure8.join.util.SpringTestCase;
18 import org.figure8.join.businessobjects.artifact.Build;
19 import org.figure8.join.businessobjects.commons.Release;
20 import org.figure8.join.businessobjects.artifact.persistence.BuildDao;
21 import org.figure8.join.businessobjects.commons.persistence.ReleaseDao;
22
23 import java.util.Date;
24 import java.util.List;
25 /**
26 * JUnit test case for testing BuildDao implementation.
27 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
28 * @version $Revision: 1.2 $
29 */
30 public class BuildDaoTest extends SpringTestCase{
31
32
33
34 /** Spring configuration files */
35 private String[] configLocations = new String[]{"classpath:/org/figure8/join/businessobjects/artifact/persistence/spring.xml"};
36
37
38
39
40 /** A ReleaseDao implementation that we need */
41 protected ReleaseDao releDao = null;
42 /** The BuildDao implementation to test */
43 protected BuildDao dao = null;
44
45
46
47
48 /** Retrieve assembly daos after having initialized the context */
49 public void setUp(){
50 super.setUp();
51
52 releDao = (ReleaseDao)context.getBean("releaseDao");
53 dao = (BuildDao)context.getBean("buildDao");
54 }
55
56
57
58
59 /** Test the finder methods on assembly */
60 public void testFindBy(){
61
62 Release release = new Release("40.1", 40, 1, new Date());
63 Build build1 = new Build("1.0", "comments1", "fooId", release);
64 Build build2 = new Build("2.0", "comments2", "barId", release);
65 int size = getBuildListSize();
66 releDao.save(release);
67 dao.save(build1);
68 dao.save(build2);
69
70 assertEquals("Builds have been successfuylly created", size + 2, dao.findAll().size());
71
72 Build foundBuild = dao.getBuild("build-r40.1-v1.0");
73 assertNotNull("Found a Build", foundBuild);
74 assertEquals("Found the correct Build", "build-r40.1-v1.0", foundBuild.getKey());
75 assertEquals("Found the correct Build", "1.0", foundBuild.getVersionInfo());
76 assertEquals("Found the correct Build", "comments1", foundBuild.getComments());
77 assertEquals("Found the correct Build", "fooId", foundBuild.getComposerId());
78
79 List foundBuilds = dao.getBuildsComposedByUser("barId");
80 assertNotNull("Found a list of Assemblies", foundBuilds);
81 assertEquals("Found a list with 1 Assembly", 1, foundBuilds.size());
82 foundBuild = (Build)foundBuilds.get(0);
83 assertEquals("Found the correct Build", "build-r40.1-v2.0", foundBuild.getKey());
84 assertEquals("Found the correct Build", "2.0", foundBuild.getVersionInfo());
85 assertEquals("Found the correct Build", "comments2", foundBuild.getComments());
86 assertEquals("Found the correct Build", "barId", foundBuild.getComposerId());
87
88 foundBuilds = dao.getBuildsByRelease(release);
89 assertNotNull("Found a list of Assemblies", foundBuilds);
90 assertEquals("Found a list with 2 Assemblies", 2, foundBuilds.size());
91
92 }
93
94
95
96
97 /** Test the findAll on builds */
98 protected int getBuildListSize(){
99 return dao.findAll().size();
100 }
101
102
103
104
105 /** @return An array of locations from Spring configuration files. */
106 public String[] getConfigLocations(){
107 return configLocations;
108 }
109 }