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.commons.Step;
19  import org.figure8.join.businessobjects.commons.Release;
20  import org.figure8.join.businessobjects.commons.persistence.StepDao;
21  import org.figure8.join.businessobjects.commons.persistence.ReleaseDao;
22  import org.figure8.join.businessobjects.environment.LogicalEnvironment;
23  import org.figure8.join.businessobjects.environment.PhysicalEnvironment;
24  import org.figure8.join.businessobjects.environment.EnvironmentMapping;
25  
26  import java.util.Date;
27  /**
28   * JUnit test case for testing EnvironmentMappingDao implementation.
29   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
30   * @version $Revision: 1.2 $
31   */
32  public class EnvironmentMappingDaoTest extends SpringTestCase{
33  
34     // Static -------------------------------------------------------------------
35  
36     /** Spring configuration files */
37     private String[] configLocations = new String[]{
38        "classpath:/org/figure8/join/businessobjects/environment/persistence/spring.xml"};
39  
40  
41     // Attributes ---------------------------------------------------------------
42  
43     /** The needed StepDao impl */
44     protected StepDao stepDao = null;
45     /** The needed ReleaseDao impl */
46     protected ReleaseDao releaseDao = null;
47     /** The needed logical environment dao impl. */
48     protected LogicalEnvironmentDao logicalEnvDao = null;
49     /** The needed physical environment dao impl. */
50     protected PhysicalEnvironmentDao physicalEnvDao = null;
51  
52     /** The EnvironmentMappingDao implementation instance to test. */
53     protected EnvironmentMappingDao dao = null;
54  
55  
56     // Override of SpringTestCase -----------------------------------------------
57  
58     /** Retrieve required daos after having initialized context */
59     public void setUp(){
60        super.setUp();
61        // Get required daos.
62        stepDao = (StepDao)context.getBean("stepDao");
63        releaseDao = (ReleaseDao)context.getBean("releaseDao");
64        logicalEnvDao = (LogicalEnvironmentDao)context.getBean("logicalEnvironmentDao");
65        physicalEnvDao = (PhysicalEnvironmentDao)context.getBean("physicalEnvironmentDao");
66        dao = (EnvironmentMappingDao)context.getBean("environmentMappingDao");
67     }
68  
69  
70     // Public -------------------------------------------------------------------
71  
72     /** Test the creation of environment mapping */
73     public void testEnvironmentMappingCreation(){
74        // Save an EnvironmentMapping and required items.
75        Step step = new Step("envMappingCreation", 1);
76        Release release = new Release("20.0", 20, 0, new Date());
77        LogicalEnvironment logical = new LogicalEnvironment("mapCreation", "label", "description", "managerId", step, release);
78        PhysicalEnvironment physical = new PhysicalEnvironment("mapCreation", "name");
79        EnvironmentMapping mapping = new EnvironmentMapping(logical, physical);
80        int size = getEnvironmentMappingListSize();
81        stepDao.save(step);
82        releaseDao.save(release);
83        logicalEnvDao.save(logical);
84        physicalEnvDao.save(physical);
85        dao.save(mapping);
86        // Assert there's one environment mapping.
87        assertEquals("EnvironmentMapping is successfully created", size + 1, dao.findAll().size());
88     }
89  
90  
91     // Protected ----------------------------------------------------------------
92  
93     /** Test the findAll on EnvironmentMapping */
94     protected int getEnvironmentMappingListSize(){
95        return dao.findAll().size();
96     }
97  
98  
99     // Implementation of SpringTestCase -----------------------------------------
100 
101    /** @return An array of Spring configuration files locations */
102    public String[] getConfigLocations(){
103       return configLocations;
104    }
105 }