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