1 package org.apache.continuum.installation;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.continuum.dao.DaoUtils;
23 import org.apache.maven.continuum.AbstractContinuumTest;
24 import org.apache.maven.continuum.execution.ExecutorConfigurator;
25 import org.apache.maven.continuum.installation.AlreadyExistsInstallationException;
26 import org.apache.maven.continuum.installation.InstallationService;
27 import org.apache.maven.continuum.model.system.Installation;
28 import org.apache.maven.continuum.model.system.Profile;
29 import org.apache.maven.continuum.profile.ProfileService;
30 import org.codehaus.plexus.util.StringUtils;
31
32 import java.util.List;
33
34
35
36
37
38
39 public class DefaultInstallationServiceTest
40 extends AbstractContinuumTest
41 {
42 private static final String NEW_INSTALLATION_NAME = "newInstallation";
43
44 protected void setUp()
45 throws Exception
46 {
47 super.setUp();
48 DaoUtils daoUtils = (DaoUtils) lookup( DaoUtils.class.getName() );
49 daoUtils.eraseDatabase();
50 }
51
52 private InstallationService getInstallationService()
53 throws Exception
54 {
55
56
57 return (InstallationService) lookup( InstallationService.ROLE );
58 }
59
60 private Installation addInstallation( String name, String varName, String varValue, String type )
61 throws Exception
62 {
63
64 Installation installation = new Installation();
65 installation.setType( type );
66 installation.setName( name );
67 installation.setVarName( varName );
68 installation.setVarValue( varValue );
69 return getInstallationService().add( installation );
70 }
71
72 public void testAddInstallation()
73 throws Exception
74 {
75 Installation added = this.addInstallation( NEW_INSTALLATION_NAME, null, "bar", InstallationService.JDK_TYPE );
76 Installation getted = getInstallationService().getInstallation( added.getInstallationId() );
77 assertNotNull( getted );
78 assertEquals( getInstallationService().getEnvVar( InstallationService.JDK_TYPE ), getted.getVarName() );
79 assertEquals( "bar", getted.getVarValue() );
80 assertEquals( 1, getInstallationService().getAllInstallations().size() );
81 assertNotNull( getInstallationService().getInstallation( NEW_INSTALLATION_NAME ) );
82 }
83
84 public void testAddDuplicateInstallation()
85 throws Exception
86 {
87 Installation added = this.addInstallation( NEW_INSTALLATION_NAME, null, "bar", InstallationService.JDK_TYPE );
88 Installation getted = getInstallationService().getInstallation( added.getInstallationId() );
89 assertNotNull( getted );
90 assertEquals( getInstallationService().getEnvVar( InstallationService.JDK_TYPE ), getted.getVarName() );
91 assertEquals( "bar", getted.getVarValue() );
92 try
93 {
94 this.addInstallation( NEW_INSTALLATION_NAME, null, "bar", InstallationService.JDK_TYPE );
95 fail( "not in AlreadyExistsInstallationException" );
96 }
97 catch ( AlreadyExistsInstallationException e )
98 {
99
100 }
101 assertEquals( 1, getInstallationService().getAllInstallations().size() );
102 }
103
104 public void testRemove()
105 throws Exception
106 {
107 String name = "toremove";
108 Installation added = this.addInstallation( name, "foo", "bar", InstallationService.JDK_TYPE );
109 Installation getted = getInstallationService().getInstallation( added.getInstallationId() );
110 assertNotNull( getted );
111 getInstallationService().delete( getted );
112 getted = getInstallationService().getInstallation( added.getInstallationId() );
113 assertNull( getted );
114
115 }
116
117 public void testUpdate()
118 throws Exception
119 {
120 String name = "toupdate";
121 Installation added = this.addInstallation( name, "foo", "bar", InstallationService.JDK_TYPE );
122 Installation getted = getInstallationService().getInstallation( added.getInstallationId() );
123 assertNotNull( getted );
124 assertEquals( getInstallationService().getEnvVar( InstallationService.JDK_TYPE ), getted.getVarName() );
125 assertEquals( "bar", getted.getVarValue() );
126 getted.setVarName( "updatefoo" );
127 getted.setVarValue( "updatedbar" );
128 getInstallationService().update( getted );
129 getted = getInstallationService().getInstallation( added.getInstallationId() );
130 assertNotNull( getted );
131 assertEquals( getInstallationService().getEnvVar( InstallationService.JDK_TYPE ), getted.getVarName() );
132 assertEquals( "updatedbar", getted.getVarValue() );
133 }
134
135 public void testgetDefaultJdkInformations()
136 throws Exception
137 {
138 InstallationService installationService = (InstallationService) lookup( InstallationService.ROLE, "default" );
139 List<String> infos = installationService.getDefaultJdkInformations();
140 assertNotNull( infos );
141 }
142
143 public void testgetJdkInformations()
144 throws Exception
145 {
146 InstallationService installationService = (InstallationService) lookup( InstallationService.ROLE, "default" );
147 String javaHome = System.getenv( "JAVA_HOME" );
148 if ( StringUtils.isEmpty( javaHome ) )
149 {
150 javaHome = System.getProperty( "java.home" );
151 }
152 Installation installation = new Installation();
153 installation.setName( "test" );
154 installation.setType( InstallationService.JDK_TYPE );
155 installation.setVarValue( javaHome );
156
157 List<String> infos = installationService.getJdkInformations( installation );
158 assertNotNull( infos );
159 }
160
161 public void testgetJdkInformationsWithCommonMethod()
162 throws Exception
163 {
164 InstallationService installationService = (InstallationService) lookup( InstallationService.ROLE, "default" );
165 ExecutorConfigurator java = installationService.getExecutorConfigurator( InstallationService.JDK_TYPE );
166 String javaHome = System.getenv( "JAVA_HOME" );
167 if ( StringUtils.isEmpty( javaHome ) )
168 {
169 javaHome = System.getProperty( "java.home" );
170 }
171 List<String> infos = installationService.getExecutorConfiguratorVersion( javaHome, java, null );
172 System.out.println( infos );
173 assertNotNull( infos );
174 }
175
176
177
178
179
180
181
182
183
184
185
186
187 public void testAddInstallationAutomaticProfile()
188 throws Exception
189 {
190
191 Installation installation = new Installation();
192 installation.setType( InstallationService.JDK_TYPE );
193 installation.setName( "automaticJdk" );
194 installation.setVarName( "automaticvarName" );
195 installation.setVarValue( "automaticvarValue" );
196 getInstallationService().add( installation, true );
197 ProfileService profileService = (ProfileService) lookup( ProfileService.ROLE, "default" );
198 List<Profile> profiles = profileService.getAllProfiles();
199 assertEquals( 1, profiles.size() );
200 Profile profile = profiles.get( 0 );
201 assertEquals( "automaticJdk", profile.getName() );
202 Installation jdk = profile.getJdk();
203 assertNotNull( jdk );
204 assertEquals( "automaticJdk", jdk.getName() );
205 }
206
207 public void testUpdateName()
208 throws Exception
209 {
210 Installation installation = new Installation();
211 installation.setType( InstallationService.JDK_TYPE );
212 installation.setName( "automatic" );
213 installation.setVarName( "automaticvarName" );
214 installation.setVarValue( "automaticvarValue" );
215 installation = getInstallationService().add( installation, true );
216
217 installation.setName( "new name here" );
218 getInstallationService().update( installation );
219
220 Installation getted = getInstallationService().getInstallation( installation.getInstallationId() );
221 assertEquals( "new name here", getted.getName() );
222
223
224 }
225 }