1 package org.apache.maven.profiles.manager;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.List;
23 import java.util.Properties;
24
25 import org.apache.maven.model.Activation;
26 import org.apache.maven.model.ActivationProperty;
27 import org.apache.maven.model.Profile;
28 import org.apache.maven.profiles.DefaultProfileManager;
29 import org.apache.maven.profiles.ProfileManager;
30 import org.codehaus.plexus.PlexusTestCase;
31
32 public class DefaultProfileManagerTest
33 extends PlexusTestCase
34 {
35
36 public void setUp()
37 throws Exception
38 {
39 super.setUp();
40 }
41
42 public void testShouldActivateDefaultProfile()
43 throws Exception
44 {
45 Profile notActivated = new Profile();
46 notActivated.setId( "notActivated" );
47
48 Activation nonActivation = new Activation();
49
50 nonActivation.setJdk( "19.2" );
51
52 notActivated.setActivation( nonActivation );
53
54 Profile defaultActivated = new Profile();
55 defaultActivated.setId( "defaultActivated" );
56
57 Activation defaultActivation = new Activation();
58
59 defaultActivation.setActiveByDefault( true );
60
61 defaultActivated.setActivation( defaultActivation );
62
63 Properties props = System.getProperties();
64
65 ProfileManager profileManager = new DefaultProfileManager( getContainer(), props );
66
67 profileManager.addProfile( notActivated );
68 profileManager.addProfile( defaultActivated );
69
70 List active = profileManager.getActiveProfiles();
71
72 assertNotNull( active );
73 assertEquals( 1, active.size() );
74 assertEquals( "defaultActivated", ( (Profile) active.get( 0 ) ).getId() );
75 }
76
77 public void testShouldNotActivateDefaultProfile()
78 throws Exception
79 {
80 Profile syspropActivated = new Profile();
81 syspropActivated.setId( "syspropActivated" );
82
83 Activation syspropActivation = new Activation();
84
85 ActivationProperty syspropProperty = new ActivationProperty();
86 syspropProperty.setName( "java.version" );
87
88 syspropActivation.setProperty( syspropProperty );
89
90 syspropActivated.setActivation( syspropActivation );
91
92 Profile defaultActivated = new Profile();
93 defaultActivated.setId( "defaultActivated" );
94
95 Activation defaultActivation = new Activation();
96
97 defaultActivation.setActiveByDefault( true );
98
99 defaultActivated.setActivation( defaultActivation );
100
101 Properties props = System.getProperties();
102
103 ProfileManager profileManager = new DefaultProfileManager( getContainer(), props );
104
105 profileManager.addProfile( syspropActivated );
106 profileManager.addProfile( defaultActivated );
107
108 List active = profileManager.getActiveProfiles();
109
110 assertNotNull( active );
111 assertEquals( 1, active.size() );
112 assertEquals( "syspropActivated", ( (Profile) active.get( 0 ) ).getId() );
113 }
114
115
116 public void testShouldNotActivateReversalOfPresentSystemProperty()
117 throws Exception
118 {
119 Profile syspropActivated = new Profile();
120 syspropActivated.setId( "syspropActivated" );
121
122 Activation syspropActivation = new Activation();
123
124 ActivationProperty syspropProperty = new ActivationProperty();
125 syspropProperty.setName( "!java.version" );
126
127 syspropActivation.setProperty( syspropProperty );
128
129 syspropActivated.setActivation( syspropActivation );
130
131 Properties props = System.getProperties();
132
133 ProfileManager profileManager = new DefaultProfileManager( getContainer(), props );
134
135 profileManager.addProfile( syspropActivated );
136
137 List active = profileManager.getActiveProfiles();
138
139 assertNotNull( active );
140 assertEquals( 0, active.size() );
141 }
142
143 public void testShouldOverrideAndActivateInactiveProfile()
144 throws Exception
145 {
146 Profile syspropActivated = new Profile();
147 syspropActivated.setId( "syspropActivated" );
148
149 Activation syspropActivation = new Activation();
150
151 ActivationProperty syspropProperty = new ActivationProperty();
152 syspropProperty.setName( "!java.version" );
153
154 syspropActivation.setProperty( syspropProperty );
155
156 syspropActivated.setActivation( syspropActivation );
157
158 Properties props = System.getProperties();
159
160 ProfileManager profileManager = new DefaultProfileManager( getContainer(), props );
161
162 profileManager.addProfile( syspropActivated );
163
164 profileManager.explicitlyActivate( "syspropActivated" );
165
166 List active = profileManager.getActiveProfiles();
167
168 assertNotNull( active );
169 assertEquals( 1, active.size() );
170 assertEquals( "syspropActivated", ( (Profile) active.get( 0 ) ).getId() );
171 }
172
173 public void testShouldOverrideAndDeactivateActiveProfile()
174 throws Exception
175 {
176 Profile syspropActivated = new Profile();
177 syspropActivated.setId( "syspropActivated" );
178
179 Activation syspropActivation = new Activation();
180
181 ActivationProperty syspropProperty = new ActivationProperty();
182 syspropProperty.setName( "java.version" );
183
184 syspropActivation.setProperty( syspropProperty );
185
186 syspropActivated.setActivation( syspropActivation );
187
188 Properties props = System.getProperties();
189
190 ProfileManager profileManager = new DefaultProfileManager( getContainer(), props );
191
192 profileManager.addProfile( syspropActivated );
193
194 profileManager.explicitlyDeactivate( "syspropActivated" );
195
196 List active = profileManager.getActiveProfiles();
197
198 assertNotNull( active );
199 assertEquals( 0, active.size() );
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 }