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.environment.persistence;
16  
17  import org.figure8.join.util.SpringTestCase;
18  import org.figure8.join.businessobjects.environment.Parameter;
19  /**
20   * JUnit test case for testing ParameterDao implementation.
21   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
22   * @version $Revision: 1.2 $
23   */
24  public class ParameterDaoTest extends SpringTestCase{
25  
26     // Static -------------------------------------------------------------------
27  
28     /** Spring configuration files */
29     private String[] configLocations = new String[]{
30        "classpath:/org/figure8/join/businessobjects/environment/persistence/spring.xml"};
31  
32  
33     // Attributes ---------------------------------------------------------------
34  
35     /** The ParameterDao implementation to test. */
36     protected ParameterDao dao = null;
37  
38  
39     // Override of SpringTestCase -----------------------------------------------
40  
41     /** Retrieve ParameterDao implementation after having initialized context */
42     public void setUp(){
43        super.setUp();
44        // Get Parameter dao.
45        dao = (ParameterDao)context.getBean("parameterDao");
46     }
47  
48  
49     // Public -------------------------------------------------------------------
50  
51     /** Test the creation of a parameter */
52     public void testParameterCreation(){
53        // Save a new parameter.
54        Parameter param = new Parameter("creation", "description");
55        int size = getParameterListSize();
56        dao.save(param);
57        // Assert there's one parameter.
58        assertEquals("Parameter is successfully created", size + 1, dao.findAll().size());
59     }
60  
61     /** Test the findByName() method. */
62     public void testFindByName(){
63        // Save a new parameter.
64        Parameter param = new Parameter("findByName", "nameDescription");
65        int size = getParameterListSize();
66        dao.save(param);
67        // Assert there's one more parameter.
68        assertEquals("Parameter is successfully created", size + 1, dao.findAll().size());
69        // Retrieve parameter using name.
70        Parameter foundParam = dao.getParameter("findByName");
71        assertNotNull("Found a parameter", foundParam);
72        assertEquals("Found a parameter with correct name", "findByName", foundParam.getName());
73        assertEquals("Found a parameter with correct description", "nameDescription", foundParam.getDescription());
74     }
75  
76     /** Test parameter removal. */
77     public void testParameterRemoval(){
78        // Save a new parameter.
79        Parameter param = new Parameter("removal", "description");
80        int size = getParameterListSize();
81        dao.save(param);
82        // Assert there's one more parameter.
83        assertEquals("Parameter is successfully created", size + 1, dao.findAll().size());
84        // Remove and assert.
85        dao.remove(param);
86        assertEquals("Parameter is successfully removed", size, dao.findAll().size());
87     }
88  
89  
90     // Protected ----------------------------------------------------------------
91  
92     /** Test the findAll on Parameter */
93     protected int getParameterListSize(){
94        return dao.findAll().size();
95     }
96  
97  
98     // Implementation of SpringTestCase -----------------------------------------
99  
100    /** @return An array of locations from Spring configuration files. */
101    public String[] getConfigLocations(){
102       return configLocations;
103    }
104 }