1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.model.profile.activation;
20
21 import java.util.Properties;
22
23 import org.apache.maven.model.Activation;
24 import org.apache.maven.model.ActivationProperty;
25 import org.apache.maven.model.Profile;
26
27
28
29
30
31
32 public class PropertyProfileActivatorTest extends AbstractProfileActivatorTest<PropertyProfileActivator> {
33
34 public PropertyProfileActivatorTest() {
35 super(PropertyProfileActivator.class);
36 }
37
38 private Profile newProfile(String key, String value) {
39 ActivationProperty ap = new ActivationProperty();
40 ap.setName(key);
41 ap.setValue(value);
42
43 Activation a = new Activation();
44 a.setProperty(ap);
45
46 Profile p = new Profile();
47 p.setActivation(a);
48
49 return p;
50 }
51
52 private Properties newProperties(String key, String value) {
53 Properties props = new Properties();
54 props.setProperty(key, value);
55 return props;
56 }
57
58 public void testNullSafe() throws Exception {
59 Profile p = new Profile();
60
61 assertActivation(false, p, newContext(null, null));
62
63 p.setActivation(new Activation());
64
65 assertActivation(false, p, newContext(null, null));
66 }
67
68 public void testWithNameOnly_UserProperty() throws Exception {
69 Profile profile = newProfile("prop", null);
70
71 assertActivation(true, profile, newContext(newProperties("prop", "value"), null));
72
73 assertActivation(false, profile, newContext(newProperties("prop", ""), null));
74
75 assertActivation(false, profile, newContext(newProperties("other", "value"), null));
76 }
77
78 public void testWithNameOnly_SystemProperty() throws Exception {
79 Profile profile = newProfile("prop", null);
80
81 assertActivation(true, profile, newContext(null, newProperties("prop", "value")));
82
83 assertActivation(false, profile, newContext(null, newProperties("prop", "")));
84
85 assertActivation(false, profile, newContext(null, newProperties("other", "value")));
86 }
87
88 public void testWithNegatedNameOnly_UserProperty() throws Exception {
89 Profile profile = newProfile("!prop", null);
90
91 assertActivation(false, profile, newContext(newProperties("prop", "value"), null));
92
93 assertActivation(true, profile, newContext(newProperties("prop", ""), null));
94
95 assertActivation(true, profile, newContext(newProperties("other", "value"), null));
96 }
97
98 public void testWithNegatedNameOnly_SystemProperty() throws Exception {
99 Profile profile = newProfile("!prop", null);
100
101 assertActivation(false, profile, newContext(null, newProperties("prop", "value")));
102
103 assertActivation(true, profile, newContext(null, newProperties("prop", "")));
104
105 assertActivation(true, profile, newContext(null, newProperties("other", "value")));
106 }
107
108 public void testWithValue_UserProperty() throws Exception {
109 Profile profile = newProfile("prop", "value");
110
111 assertActivation(true, profile, newContext(newProperties("prop", "value"), null));
112
113 assertActivation(false, profile, newContext(newProperties("prop", "other"), null));
114
115 assertActivation(false, profile, newContext(newProperties("prop", ""), null));
116 }
117
118 public void testWithValue_SystemProperty() throws Exception {
119 Profile profile = newProfile("prop", "value");
120
121 assertActivation(true, profile, newContext(null, newProperties("prop", "value")));
122
123 assertActivation(false, profile, newContext(null, newProperties("prop", "other")));
124
125 assertActivation(false, profile, newContext(null, newProperties("other", "")));
126 }
127
128 public void testWithNegatedValue_UserProperty() throws Exception {
129 Profile profile = newProfile("prop", "!value");
130
131 assertActivation(false, profile, newContext(newProperties("prop", "value"), null));
132
133 assertActivation(true, profile, newContext(newProperties("prop", "other"), null));
134
135 assertActivation(true, profile, newContext(newProperties("prop", ""), null));
136 }
137
138 public void testWithNegatedValue_SystemProperty() throws Exception {
139 Profile profile = newProfile("prop", "!value");
140
141 assertActivation(false, profile, newContext(null, newProperties("prop", "value")));
142
143 assertActivation(true, profile, newContext(null, newProperties("prop", "other")));
144
145 assertActivation(true, profile, newContext(null, newProperties("other", "")));
146 }
147
148 public void testWithValue_UserPropertyDominantOverSystemProperty() throws Exception {
149 Profile profile = newProfile("prop", "value");
150
151 Properties props1 = newProperties("prop", "value");
152 Properties props2 = newProperties("prop", "other");
153
154 assertActivation(true, profile, newContext(props1, props2));
155
156 assertActivation(false, profile, newContext(props2, props1));
157 }
158 }