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 javax.inject.Inject;
22
23 import java.util.List;
24 import java.util.Properties;
25
26 import org.apache.maven.model.Activation;
27 import org.apache.maven.model.ActivationProperty;
28 import org.apache.maven.model.Profile;
29 import org.apache.maven.profiles.DefaultProfileManager;
30 import org.apache.maven.profiles.ProfileManager;
31 import org.codehaus.plexus.PlexusContainer;
32 import org.codehaus.plexus.testing.PlexusTest;
33 import org.junit.jupiter.api.Disabled;
34 import org.junit.jupiter.api.Test;
35
36 import static org.junit.jupiter.api.Assertions.assertEquals;
37 import static org.junit.jupiter.api.Assertions.assertNotNull;
38
39 @PlexusTest
40 @Deprecated
41 class DefaultProfileManagerTest {
42
43 @Inject
44 PlexusContainer container;
45
46 protected PlexusContainer getContainer() {
47 return container;
48 }
49
50 @Test
51 void testShouldActivateDefaultProfile() throws Exception {
52 Profile notActivated = new Profile();
53 notActivated.setId("notActivated");
54
55 Activation nonActivation = new Activation();
56
57 nonActivation.setJdk("19.2");
58
59 notActivated.setActivation(nonActivation);
60
61 Profile defaultActivated = new Profile();
62 defaultActivated.setId("defaultActivated");
63
64 Activation defaultActivation = new Activation();
65
66 defaultActivation.setActiveByDefault(true);
67
68 defaultActivated.setActivation(defaultActivation);
69
70 Properties props = System.getProperties();
71
72 ProfileManager profileManager = new DefaultProfileManager(getContainer(), props);
73
74 profileManager.addProfile(notActivated);
75 profileManager.addProfile(defaultActivated);
76
77 List active = profileManager.getActiveProfiles();
78
79 assertNotNull(active);
80 assertEquals(1, active.size());
81 assertEquals("defaultActivated", ((Profile) active.get(0)).getId());
82 }
83
84 @Test
85 void testShouldNotActivateDefaultProfile() throws Exception {
86 Profile syspropActivated = new Profile();
87 syspropActivated.setId("syspropActivated");
88
89 Activation syspropActivation = new Activation();
90
91 ActivationProperty syspropProperty = new ActivationProperty();
92 syspropProperty.setName("java.version");
93
94 syspropActivation.setProperty(syspropProperty);
95
96 syspropActivated.setActivation(syspropActivation);
97
98 Profile defaultActivated = new Profile();
99 defaultActivated.setId("defaultActivated");
100
101 Activation defaultActivation = new Activation();
102
103 defaultActivation.setActiveByDefault(true);
104
105 defaultActivated.setActivation(defaultActivation);
106
107 Properties props = System.getProperties();
108
109 ProfileManager profileManager = new DefaultProfileManager(getContainer(), props);
110
111 profileManager.addProfile(syspropActivated);
112 profileManager.addProfile(defaultActivated);
113
114 List active = profileManager.getActiveProfiles();
115
116 assertNotNull(active);
117 assertEquals(1, active.size());
118 assertEquals("syspropActivated", ((Profile) active.get(0)).getId());
119 }
120
121 @Test
122 void testShouldNotActivateReversalOfPresentSystemProperty() throws Exception {
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 @Test
148 void testShouldOverrideAndActivateInactiveProfile() throws Exception {
149 Profile syspropActivated = new Profile();
150 syspropActivated.setId("syspropActivated");
151
152 Activation syspropActivation = new Activation();
153
154 ActivationProperty syspropProperty = new ActivationProperty();
155 syspropProperty.setName("!java.version");
156
157 syspropActivation.setProperty(syspropProperty);
158
159 syspropActivated.setActivation(syspropActivation);
160
161 Properties props = System.getProperties();
162
163 ProfileManager profileManager = new DefaultProfileManager(getContainer(), props);
164
165 profileManager.addProfile(syspropActivated);
166
167 profileManager.explicitlyActivate("syspropActivated");
168
169 List active = profileManager.getActiveProfiles();
170
171 assertNotNull(active);
172 assertEquals(1, active.size());
173 assertEquals("syspropActivated", ((Profile) active.get(0)).getId());
174 }
175
176 @Test
177 void testShouldOverrideAndDeactivateActiveProfile() throws Exception {
178 Profile syspropActivated = new Profile();
179 syspropActivated.setId("syspropActivated");
180
181 Activation syspropActivation = new Activation();
182
183 ActivationProperty syspropProperty = new ActivationProperty();
184 syspropProperty.setName("java.version");
185
186 syspropActivation.setProperty(syspropProperty);
187
188 syspropActivated.setActivation(syspropActivation);
189
190 Properties props = System.getProperties();
191
192 ProfileManager profileManager = new DefaultProfileManager(getContainer(), props);
193
194 profileManager.addProfile(syspropActivated);
195
196 profileManager.explicitlyDeactivate("syspropActivated");
197
198 List active = profileManager.getActiveProfiles();
199
200 assertNotNull(active);
201 assertEquals(0, active.size());
202 }
203
204 @Test
205 @Disabled
206 void testOsActivationProfile() throws Exception {
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 }