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.services.scripting.persistence;
16
17 import org.figure8.join.util.SpringTestCase;
18 import org.figure8.join.services.scripting.ScriptLogInfo;
19 import org.figure8.join.businessobjects.commons.Step;
20 import org.figure8.join.businessobjects.commons.Release;
21
22 import java.util.Date;
23 import java.util.List;
24 /**
25 * JUnit test case for testing ScriptLogInfoDao implementation
26 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
27 * @version Revision$
28 */
29 public class ScriptLogInfoDaoTest extends SpringTestCase{
30
31
32
33 /** Spring configuration files */
34 private String[] configLocations = new String[]{"classpath:/org/figure8/join/services/scripting/persistence/spring.xml"};
35
36
37
38
39 /** The ScriptLogInfoDao implemnetation instance to test */
40 protected ScriptLogInfoDao dao = null;
41
42
43
44
45 /** Retrieve needed dao after having initialized context */
46 public void setUp(){
47 super.setUp();
48
49 dao = (ScriptLogInfoDao)context.getBean("scriptLogInfoDao");
50 }
51
52
53
54
55 /** Test the creation of a ScriptLogInfo object */
56 public void testScriptLogInfoCreation(){
57
58 Release release = new Release("1.0", 1, 0, new Date());
59 ScriptLogInfo log = new ScriptLogInfo(release, "logFile", "scriptName", "scriptCat", "scriptFile");
60 int size = getScriptLogListSize();
61 dao.save(log);
62
63 assertEquals("ScriptLogInfo is successfully created", size + 1, dao.findAll().size());
64 }
65
66 /** Test the retrieval of script logs using different criteria. */
67 public void testScriptLogInfoRetrieval(){
68
69 Step step = new Step("assembly", 1);
70 ScriptLogInfo log1 = new ScriptLogInfo(step, "logFile1", "scriptName1", "scriptCat", "scriptFile");
71 ScriptLogInfo log2 = new ScriptLogInfo(step, "logFile2", "scriptName2", "scriptCat", "scriptFile");
72 ScriptLogInfo log3 = new ScriptLogInfo(step, "logFile3", "scriptName1", "scriptCat", "scriptFile");
73 int size = getScriptLogListSize();
74 dao.save(log1);
75 dao.save(log2);
76 dao.save(log3);
77
78 assertEquals("ScriptLogInfos are successfully created", size + 3, dao.findAll().size());
79
80 List infos = dao.getScriptLogInfosForEntity(step);
81 assertNotNull("Found a list of ScriptLogInfos", infos);
82 assertFalse("Found a non empty list", infos.isEmpty());
83 assertEquals("Found a list of three elements", 3, infos.size());
84
85 infos = dao.getScriptLogInfos("scriptName1");
86 assertNotNull("Found a list of ScriptLogInfos", infos);
87 assertFalse("Found a non empty list", infos.isEmpty());
88 assertEquals("Found a list of two elements", 2, infos.size());
89
90 }
91
92
93
94 /** Test the findAll on script log info */
95 protected int getScriptLogListSize(){
96 return dao.findAll().size();
97 }
98
99
100
101
102 /** @return configLocations inner field */
103 public String[] getConfigLocations(){
104 return configLocations;
105 }
106 }