Clover Coverage Report - Liquibase Maven Plugin 2.0.2
Coverage timestamp: Wed Aug 3 2011 19:38:24 EDT
57   114   6   9.5
0   78   0.11   6
6     1  
1    
 
  LiquibaseUpdateMojoTest       Line # 10 57 0% 6 0 100% 1.0
 
  (4)
 
1    package org.liquibase.maven.plugins;
2   
3    import java.util.*;
4    import org.codehaus.plexus.configuration.PlexusConfiguration;
5   
6    /**
7    * Some basic tests that validate the setting of properties for the LiquibaseUpdate mojo.
8    * @author Peter Murray
9    */
 
10    public class LiquibaseUpdateMojoTest extends AbstractLiquibaseMojoTest {
11   
12    private static final String CONFIG_FILE = "update/plugin_config.xml";
13   
14    private static final Map<String, Object> DEFAULT_PROPERTIES;
15   
 
16  1 toggle static {
17  1 DEFAULT_PROPERTIES = new HashMap<String, Object>();
18  1 DEFAULT_PROPERTIES.put("changeLogFile", "org/liquibase/changelog.xml");
19  1 DEFAULT_PROPERTIES.put("driver", "com.mysql.jdbc.Driver");
20  1 DEFAULT_PROPERTIES.put("url", "jdbc:mysql://localhost/eformat");
21  1 DEFAULT_PROPERTIES.put("username", "root");
22  1 DEFAULT_PROPERTIES.put("password", null);
23  1 DEFAULT_PROPERTIES.put("verbose", true);
24    }
25   
 
26  1 toggle public void testNoPropertiesFile() throws Exception {
27  1 LiquibaseUpdate mojo = createUpdateMojo();
28    // Clear out any settings for the property file that may be set
29  1 setVariableValueToObject(mojo, "propertyFile", null);
30  1 setVariableValueToObject(mojo, "propertyFileWillOverride", false);
31   
32  1 loadPropertiesFileIfPresent(mojo);
33   
34  1 Map values = getVariablesAndValuesFromObject(mojo);
35  1 checkValues(DEFAULT_PROPERTIES, values);
36    }
37   
 
38  1 toggle public void testOverideAllWithPropertiesFile() throws Exception {
39    // Create the properties file for this test
40  1 Properties props = new Properties();
41  1 props.setProperty("driver", "properties_driver_value");
42  1 props.setProperty("url", "properties_url_value");
43  1 props.setProperty("username", "properties_user_value");
44  1 props.setProperty("password", "properties_password_value");
45  1 props.setProperty("changeLogFile", "properties_changeLogFile_value");
46  1 createPropertiesFile("update/test.properties", props);
47   
48  1 LiquibaseUpdate mojo = createUpdateMojo();
49  1 setVariableValueToObject(mojo, "propertyFile", "update/test.properties");
50  1 setVariableValueToObject(mojo, "propertyFileWillOverride", true);
51  1 loadPropertiesFileIfPresent(mojo);
52   
53  1 Map values = super.getVariablesAndValuesFromObject(mojo);
54  1 checkValues(props, values);
55    }
56   
 
57  1 toggle public void testOverrideAllButDriverWithPropertiesFile() throws Exception {
58    // Create the properties file for this test
59  1 Properties props = new Properties();
60  1 props.setProperty("url", "properties_url_value");
61  1 props.setProperty("username", "properties_user_value");
62  1 props.setProperty("password", "properties_password_value");
63  1 props.setProperty("changeLogFile", "properties_changeLogFile_value");
64  1 createPropertiesFile("update/test.properties", props);
65   
66  1 LiquibaseUpdate mojo = createUpdateMojo();
67  1 setVariableValueToObject(mojo, "propertyFile", "update/test.properties");
68  1 setVariableValueToObject(mojo, "propertyFileWillOverride", true);
69  1 loadPropertiesFileIfPresent(mojo);
70   
71  1 Map values = getVariablesAndValuesFromObject(mojo);
72  1 checkValues(props, values);
73   
74    // Ensure that the properties file has not overridden the driver value as it was not
75    // specified in the properties.
76  1 assertEquals("Driver should be set to the default value",
77    DEFAULT_PROPERTIES.get("driver"),
78    values.get("driver"));
79    }
80   
 
81  1 toggle public void testPropertiesFilePresentWithNoOverrideAndMissingProperty() throws Exception {
82    // Create the properties file for this test
83  1 Properties props = new Properties();
84  1 props.setProperty("url", "properties_url_value");
85  1 props.setProperty("username", "properties_user_value");
86  1 props.setProperty("password", "properties_password_value");
87  1 props.setProperty("changeLogFile", "properties_changeLogFile_value");
88  1 createPropertiesFile("update/test.properties", props);
89   
90  1 LiquibaseUpdate mojo = createUpdateMojo();
91  1 setVariableValueToObject(mojo, "propertyFile", "update/test.properties");
92  1 setVariableValueToObject(mojo, "propertyFileWillOverride", false);
93  1 loadPropertiesFileIfPresent(mojo);
94   
95  1 Map values = super.getVariablesAndValuesFromObject(mojo);
96    // The password is not specified in the configuration XML so we expect the password
97    // from the properties file to be injected into the mojo.
98  1 Map expected = new HashMap<String, Object>(DEFAULT_PROPERTIES);
99  1 expected.put("password", props.getProperty("password"));
100  1 checkValues(expected, values);
101    }
102   
103   
104    /*-------------------------------------------------------------------------*\
105    * PRIVATE METHODS
106    \*-------------------------------------------------------------------------*/
107   
 
108  4 toggle private LiquibaseUpdate createUpdateMojo() throws Exception {
109  4 LiquibaseUpdate mojo = new LiquibaseUpdate();
110  4 PlexusConfiguration config = loadConfiguration(CONFIG_FILE);
111  4 configureMojo(mojo, config);
112  4 return mojo;
113    }
114    }