/
DefaultProfileServiceTest.java
312 lines (255 loc) · 10.8 KB
/
DefaultProfileServiceTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
package org.apache.continuum.profile;
import org.apache.continuum.dao.DaoUtils;
import org.apache.maven.continuum.AbstractContinuumTest;
import org.apache.maven.continuum.installation.InstallationService;
import org.apache.maven.continuum.model.system.Installation;
import org.apache.maven.continuum.model.system.Profile;
import org.apache.maven.continuum.profile.AlreadyExistsProfileException;
import org.apache.maven.continuum.profile.ProfileService;
import java.util.List;
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* @author <a href="mailto:olamy@codehaus.org">olamy</a>
* @version $Id$
* @since 15 juin 07
*/
public class DefaultProfileServiceTest
extends AbstractContinuumTest
{
Installation jdk1;
String jdk1Name = "jdk1";
Installation jdk2;
String jdk2Name = "jdk2";
Installation mvn205;
String mvn205Name = "mvn 2.0.5";
Installation mvn206;
String mvn206Name = "mvn 2.0.6";
Profile jdk1mvn205;
String jdk1mvn205Name = "jdk1 mvn 2.0.5";
Profile jdk2mvn206;
String jdk2mvn206Name = "jdk2 mvn 2.0.6";
Installation mvnOpts1;
String mvnOpts1Name = "mvnOpts1";
Installation mvnOpts2;
String mvnOpts2Name = "mvnOpts2";
protected void setUp()
throws Exception
{
super.setUp();
DaoUtils daoUtils = (DaoUtils) lookup( DaoUtils.class.getName() );
daoUtils.eraseDatabase();
jdk1 = new Installation();
jdk1.setType( InstallationService.JDK_TYPE );
jdk1.setVarValue( "/foo/bar" );
jdk1.setName( jdk1Name );
jdk1 = getInstallationService().add( jdk1 );
jdk2 = new Installation();
jdk2.setType( InstallationService.JDK_TYPE );
jdk2.setVarValue( "/foo/bar/zloug" );
jdk2.setName( jdk2Name );
jdk2 = getInstallationService().add( jdk2 );
mvn205 = new Installation();
mvn205.setType( InstallationService.MAVEN2_TYPE );
mvn205.setVarValue( "/users/maven-2.0.5" );
mvn205.setName( mvn205Name );
mvn205 = getInstallationService().add( mvn205 );
mvn206 = new Installation();
mvn206.setType( InstallationService.MAVEN2_TYPE );
mvn206.setVarValue( "/users/maven-2.0.6" );
mvn206.setName( mvn206Name );
mvn206 = getInstallationService().add( mvn206 );
jdk1mvn205 = new Profile();
jdk1mvn205.setJdk( jdk1 );
jdk1mvn205.setBuilder( mvn205 );
jdk1mvn205.setName( jdk1mvn205Name );
getProfileService().addProfile( jdk1mvn205 );
jdk2mvn206 = new Profile();
jdk2mvn206.setJdk( jdk2 );
jdk2mvn206.setBuilder( mvn206 );
jdk2mvn206.setName( jdk2mvn206Name );
getProfileService().addProfile( jdk2mvn206 );
mvnOpts1 = new Installation();
mvnOpts1.setType( InstallationService.ENVVAR_TYPE );
mvnOpts1.setVarName( "MAVEN_OPTS" );
mvnOpts1.setVarValue( "-Xmx256m -Djava.awt.headless=true" );
mvnOpts1.setName( mvnOpts1Name );
mvnOpts1 = getInstallationService().add( mvnOpts1 );
mvnOpts2 = new Installation();
mvnOpts2.setType( InstallationService.ENVVAR_TYPE );
mvnOpts2.setVarName( "MAVEN_OPTS" );
mvnOpts2.setVarValue( "-Xmx1024m -Xms1024m" );
mvnOpts2.setName( mvnOpts2Name );
mvnOpts2 = getInstallationService().add( mvnOpts2 );
}
public InstallationService getInstallationService()
throws Exception
{
return (InstallationService) lookup( InstallationService.ROLE, "default" );
}
public ProfileService getProfileService()
throws Exception
{
return (ProfileService) lookup( ProfileService.ROLE, "default" );
}
public void testAddProfile()
throws Exception
{
Profile defaultProfile = new Profile();
String name = "default profile";
defaultProfile.setName( name );
Profile getted = getProfileService().addProfile( defaultProfile );
assertNotNull( getProfileService().getProfile( getted.getId() ) );
assertEquals( name, getProfileService().getProfile( getted.getId() ).getName() );
assertEquals( 3, getProfileService().getAllProfiles().size() );
}
public void testAddDuplicateProfile()
throws Exception
{
Profile defaultProfile = new Profile();
String name = "default profile";
defaultProfile.setName( name );
Profile getted = getProfileService().addProfile( defaultProfile );
assertNotNull( getProfileService().getProfile( getted.getId() ) );
assertEquals( name, getProfileService().getProfile( getted.getId() ).getName() );
assertEquals( 3, getProfileService().getAllProfiles().size() );
defaultProfile = new Profile();
defaultProfile.setName( name );
try
{
getted = getProfileService().addProfile( defaultProfile );
fail( "no AlreadyExistsProfileException with an already exist name " );
}
catch ( AlreadyExistsProfileException e )
{
// we must be here
}
assertEquals( 3, getProfileService().getAllProfiles().size() );
}
public void testDeleteProfile()
throws Exception
{
Profile defaultProfile = new Profile();
defaultProfile.setName( "default profile" );
Profile getted = getProfileService().addProfile( defaultProfile );
int id = getted.getId();
assertNotNull( getProfileService().getProfile( id ) );
getProfileService().deleteProfile( id );
assertNull( getProfileService().getProfile( id ) );
}
public void testgetAllProfile()
throws Exception
{
List<Profile> all = getProfileService().getAllProfiles();
assertNotNull( all );
assertFalse( all.isEmpty() );
assertEquals( 2, all.size() );
}
public void testupdateProfile()
throws Exception
{
Profile profile = getProfileService().getProfile( jdk1mvn205.getId() );
assertEquals( jdk1mvn205Name, profile.getName() );
String newName = "new name";
profile.setName( newName );
getProfileService().updateProfile( profile );
Profile getted = getProfileService().getProfile( jdk1mvn205.getId() );
assertNotNull( getted );
assertEquals( newName, getted.getName() );
}
public void testupdateProfileDuplicateName()
throws Exception
{
Profile profile = getProfileService().getProfile( jdk1mvn205.getId() );
assertEquals( jdk1mvn205Name, profile.getName() );
profile.setName( jdk2mvn206Name );
try
{
getProfileService().updateProfile( profile );
fail( "no AlreadyExistsProfileException with duplicate name" );
}
catch ( AlreadyExistsProfileException e )
{
// we must be here
}
Profile getted = getProfileService().getProfile( jdk1mvn205.getId() );
assertNotNull( getted );
assertEquals( jdk1mvn205Name, getted.getName() );
}
public void testsetJdkInProfile()
throws Exception
{
Profile profile = getProfileService().getProfile( jdk1mvn205.getId() );
getProfileService().setJdkInProfile( profile, jdk2 );
profile = getProfileService().getProfile( jdk1mvn205.getId() );
assertEquals( jdk2.getName(), profile.getJdk().getName() );
assertEquals( jdk2.getVarValue(), profile.getJdk().getVarValue() );
}
public void testsetBuilderInProfile()
throws Exception
{
Profile profile = getProfileService().getProfile( jdk1mvn205.getId() );
getProfileService().setBuilderInProfile( profile, mvn206 );
profile = getProfileService().getProfile( jdk1mvn205.getId() );
assertEquals( mvn206.getName(), profile.getBuilder().getName() );
assertEquals( mvn206.getVarValue(), profile.getBuilder().getVarValue() );
}
public void testaddEnvVarInProfile()
throws Exception
{
Profile profile = getProfileService().getProfile( jdk1mvn205.getId() );
getProfileService().setBuilderInProfile( profile, mvn206 );
getProfileService().addEnvVarInProfile( profile, mvnOpts1 );
profile = getProfileService().getProfile( jdk1mvn205.getId() );
assertFalse( profile.getEnvironmentVariables().isEmpty() );
assertEquals( 1, profile.getEnvironmentVariables().size() );
}
public void testRemoveInstallationLinkedToAProfile()
throws Exception
{
Profile profile = getProfileService().getProfile( jdk1mvn205.getId() );
getProfileService().setJdkInProfile( profile, jdk2 );
profile = getProfileService().getProfile( jdk1mvn205.getId() );
InstallationService installationService = (InstallationService) lookup( InstallationService.ROLE, "default" );
installationService.delete( jdk2 );
}
public void testRemoveEnvVarFromProfile()
throws Exception
{
Profile profile = getProfileService().getProfile( jdk1mvn205.getId() );
getProfileService().setJdkInProfile( profile, jdk2 );
getProfileService().addEnvVarInProfile( profile, mvnOpts1 );
getProfileService().addEnvVarInProfile( profile, mvnOpts2 );
profile = getProfileService().getProfile( jdk1mvn205.getId() );
assertNotNull( profile.getJdk() );
assertEquals( 2, profile.getEnvironmentVariables().size() );
getProfileService().removeInstallationFromProfile( profile, mvnOpts1 );
profile = getProfileService().getProfile( jdk1mvn205.getId() );
assertNotNull( profile.getJdk() );
assertEquals( 1, profile.getEnvironmentVariables().size() );
getProfileService().removeInstallationFromProfile( profile, jdk2 );
profile = getProfileService().getProfile( jdk1mvn205.getId() );
assertNull( profile.getJdk() );
assertEquals( 1, profile.getEnvironmentVariables().size() );
getProfileService().removeInstallationFromProfile( profile, mvnOpts2 );
profile = getProfileService().getProfile( jdk1mvn205.getId() );
assertNull( profile.getJdk() );
assertEquals( 0, profile.getEnvironmentVariables().size() );
}
}