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