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.ActivationOS;
25 import org.apache.maven.model.Profile;
26
27
28
29
30
31 public class OperatingSystemProfileActivatorTest extends AbstractProfileActivatorTest<OperatingSystemProfileActivator> {
32
33 public OperatingSystemProfileActivatorTest() throws Exception {
34 super(OperatingSystemProfileActivator.class);
35 }
36
37 private Profile newProfile(ActivationOS os) {
38 org.apache.maven.model.Activation a = new Activation();
39 a.setOs(os);
40
41 Profile p = new Profile();
42 p.setActivation(a);
43
44 return p;
45 }
46
47 private Properties newProperties(String osName, String osVersion, String osArch) {
48 Properties props = new Properties();
49 props.setProperty("os.name", osName);
50 props.setProperty("os.version", osVersion);
51 props.setProperty("os.arch", osArch);
52 return props;
53 }
54
55 public void testVersionStringComparison() throws Exception {
56 ActivationOS os = new ActivationOS();
57 os.setVersion("6.5.0-1014-aws");
58 Profile profile = newProfile(os);
59
60 assertActivation(true, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64")));
61 assertActivation(true, profile, newContext(null, newProperties("windows", "6.5.0-1014-aws", "aarch64")));
62
63 assertActivation(false, profile, newContext(null, newProperties("linux", "3.1.0", "amd64")));
64 }
65
66 public void testVersionRegexMatching() throws Exception {
67 ActivationOS os = new ActivationOS();
68 os.setVersion("regex:.*aws");
69 Profile profile = newProfile(os);
70
71 assertActivation(true, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64")));
72 assertActivation(true, profile, newContext(null, newProperties("windows", "6.5.0-1014-aws", "aarch64")));
73
74 assertActivation(false, profile, newContext(null, newProperties("linux", "3.1.0", "amd64")));
75 }
76
77 public void testName() {
78 ActivationOS os = new ActivationOS();
79 os.setName("windows");
80 Profile profile = newProfile(os);
81
82 assertActivation(false, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64")));
83 assertActivation(true, profile, newContext(null, newProperties("windows", "6.5.0-1014-aws", "aarch64")));
84 }
85
86 public void testNegatedName() {
87 ActivationOS os = new ActivationOS();
88 os.setName("!windows");
89 Profile profile = newProfile(os);
90
91 assertActivation(true, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64")));
92 assertActivation(false, profile, newContext(null, newProperties("windows", "6.5.0-1014-aws", "aarch64")));
93 }
94
95 public void testArch() {
96 ActivationOS os = new ActivationOS();
97 os.setArch("amd64");
98 Profile profile = newProfile(os);
99
100 assertActivation(true, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64")));
101 assertActivation(false, profile, newContext(null, newProperties("windows", "6.5.0-1014-aws", "aarch64")));
102 }
103
104 public void testNegatedArch() {
105 ActivationOS os = new ActivationOS();
106 os.setArch("!amd64");
107 Profile profile = newProfile(os);
108
109 assertActivation(false, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64")));
110 assertActivation(true, profile, newContext(null, newProperties("windows", "6.5.0-1014-aws", "aarch64")));
111 }
112
113 public void testFamily() {
114 ActivationOS os = new ActivationOS();
115 os.setFamily("windows");
116 Profile profile = newProfile(os);
117
118 assertActivation(false, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64")));
119 assertActivation(true, profile, newContext(null, newProperties("windows", "6.5.0-1014-aws", "aarch64")));
120 }
121
122 public void testNegatedFamily() {
123 ActivationOS os = new ActivationOS();
124 os.setFamily("!windows");
125 Profile profile = newProfile(os);
126
127 assertActivation(true, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64")));
128 assertActivation(false, profile, newContext(null, newProperties("windows", "6.5.0-1014-aws", "aarch64")));
129 }
130
131 public void testAllOsConditions() {
132 ActivationOS os = new ActivationOS();
133 os.setFamily("windows");
134 os.setName("windows");
135 os.setArch("aarch64");
136 os.setVersion("99");
137 Profile profile = newProfile(os);
138
139 assertActivation(false, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64")));
140 assertActivation(false, profile, newContext(null, newProperties("windows", "1", "aarch64")));
141 assertActivation(false, profile, newContext(null, newProperties("windows", "99", "amd64")));
142 assertActivation(true, profile, newContext(null, newProperties("windows", "99", "aarch64")));
143 }
144
145 public void testCapitalOsName() {
146 ActivationOS os = new ActivationOS();
147 os.setFamily("Mac");
148 os.setName("Mac OS X");
149 os.setArch("aarch64");
150 os.setVersion("14.5");
151 Profile profile = newProfile(os);
152
153 assertActivation(false, profile, newContext(null, newProperties("linux", "6.5.0-1014-aws", "amd64")));
154 assertActivation(false, profile, newContext(null, newProperties("windows", "1", "aarch64")));
155 assertActivation(false, profile, newContext(null, newProperties("windows", "99", "amd64")));
156 assertActivation(true, profile, newContext(null, newProperties("Mac OS X", "14.5", "aarch64")));
157 }
158 }