1 package org.apache.maven.profiles.activation;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import org.apache.maven.model.Activation;
23 import org.apache.maven.model.Profile;
24
25 import junit.framework.TestCase;
26
27 public class JdkPrefixProfileActivatorTest
28 extends TestCase
29 {
30 public void testDetectionWithoutActivationElement()
31 {
32 JdkPrefixProfileActivator activator = createActivator();
33
34 Profile profile = new Profile();
35
36 assertFalse( activator.canDetectActivation( profile ) );
37 }
38
39 public void testDetectionWithoutJdkElement()
40 {
41 JdkPrefixProfileActivator activator = createActivator();
42
43 Profile profile = createProfile( null );
44
45 assertFalse( activator.canDetectActivation( profile ) );
46 }
47
48 public void testDetectionWithJdkElement()
49 {
50 JdkPrefixProfileActivator activator = createActivator();
51
52 Profile profile = createProfile( "1.5" );
53
54 assertTrue( activator.canDetectActivation( profile ) );
55 }
56
57 public void testActivationWithMatchingJdkVersion()
58 throws ProfileActivationException
59 {
60 JdkPrefixProfileActivator activator = createActivator( "1.5.0_15" );
61
62 Profile profile = createProfile( "1.5" );
63
64 assertTrue( activator.isActive( profile ) );
65 }
66
67 public void testActivationWithDifferentJdkVersion()
68 throws ProfileActivationException
69 {
70 JdkPrefixProfileActivator activator = createActivator( "1.5.0_15" );
71
72 Profile profile = createProfile( "1.4" );
73
74 assertFalse( activator.isActive( profile ) );
75 }
76
77 public void testActivationWithMatchingNegatedJdkVersion()
78 throws ProfileActivationException
79 {
80 JdkPrefixProfileActivator activator = createActivator( "1.5.0_15" );
81
82 Profile profile = createProfile( "!1.4" );
83
84 assertTrue( activator.isActive( profile ) );
85 }
86
87 public void testActivationWithDifferentNegatedJdkVersion()
88 throws ProfileActivationException
89 {
90 JdkPrefixProfileActivator activator = createActivator( "1.5.0_15" );
91
92 Profile profile = createProfile( "!1.5" );
93
94 assertFalse( activator.isActive( profile ) );
95 }
96
97 public void testActivationWithMatchingRangeJdkVersion()
98 throws ProfileActivationException
99 {
100 JdkPrefixProfileActivator activator = createActivator( "1.5.0_15" );
101
102 Profile profile = createProfile( "[1.4,1.6)" );
103
104 assertTrue( activator.isActive( profile ) );
105 }
106
107 public void testActivationWithDifferentRangeJdkVersion()
108 throws ProfileActivationException
109 {
110 JdkPrefixProfileActivator activator = createActivator( "1.5.0_15" );
111
112 Profile profile = createProfile( "[1.4,1.5]" );
113
114 assertFalse( activator.isActive( profile ) );
115 }
116
117 public void testActivationWithBadRangeJdkVersion()
118 throws ProfileActivationException
119 {
120 JdkPrefixProfileActivator activator = createActivator( "1.5.0_15" );
121
122 Profile profile = createProfile( "[1.4," );
123 try
124 {
125 activator.isActive( profile );
126 fail( "Should have raised an exception for invalid format" );
127 }
128 catch ( ProfileActivationException e )
129 {
130 assertTrue( true );
131 }
132 }
133
134 private static JdkPrefixProfileActivator createActivator()
135 {
136 return new JdkPrefixProfileActivator();
137 }
138
139 private static JdkPrefixProfileActivator createActivator( final String testJdkVersion )
140 {
141 return new JdkPrefixProfileActivator()
142 {
143 protected String getJdkVersion()
144 {
145 return testJdkVersion;
146 }
147 };
148 }
149
150 private static Profile createProfile( String jdk )
151 {
152 Profile profile = new Profile();
153 Activation activation = new Activation();
154 activation.setJdk( jdk );
155 profile.setActivation( activation );
156 return profile;
157 }
158 }