001 package org.apache.maven.model.profile.activation;
002
003 /*
004 * Licensed to the Apache Software Foundation (ASF) under one
005 * or more contributor license agreements. See the NOTICE file
006 * distributed with this work for additional information
007 * regarding copyright ownership. The ASF licenses this file
008 * to you under the Apache License, Version 2.0 (the
009 * "License"); you may not use this file except in compliance
010 * with the License. You may obtain a copy of the License at
011 *
012 * http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing,
015 * software distributed under the License is distributed on an
016 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017 * KIND, either express or implied. See the License for the
018 * specific language governing permissions and limitations
019 * under the License.
020 */
021
022 import java.util.Properties;
023
024 import org.apache.maven.model.Activation;
025 import org.apache.maven.model.Profile;
026
027 /**
028 * Tests {@link JdkVersionProfileActivator}.
029 *
030 * @author Benjamin Bentmann
031 */
032 public class JdkVersionProfileActivatorTest
033 extends AbstractProfileActivatorTest<JdkVersionProfileActivator>
034 {
035
036 public JdkVersionProfileActivatorTest()
037 {
038 super( JdkVersionProfileActivator.class );
039 }
040
041 private Profile newProfile( String jdkVersion )
042 {
043 Activation a = new Activation();
044 a.setJdk( jdkVersion );
045
046 Profile p = new Profile();
047 p.setActivation( a );
048
049 return p;
050 }
051
052 private Properties newProperties( String javaVersion )
053 {
054 Properties props = new Properties();
055 props.setProperty( "java.version", javaVersion );
056 return props;
057 }
058
059 public void testNullSafe()
060 throws Exception
061 {
062 Profile p = new Profile();
063
064 assertActivation( false, p, newContext( null, null ) );
065
066 p.setActivation( new Activation() );
067
068 assertActivation( false, p, newContext( null, null ) );
069 }
070
071 public void testPrefix()
072 throws Exception
073 {
074 Profile profile = newProfile( "1.4" );
075
076 assertActivation( true, profile, newContext( null, newProperties( "1.4" ) ) );
077 assertActivation( true, profile, newContext( null, newProperties( "1.4.2" ) ) );
078 assertActivation( true, profile, newContext( null, newProperties( "1.4.2_09" ) ) );
079 assertActivation( true, profile, newContext( null, newProperties( "1.4.2_09-b03" ) ) );
080
081 assertActivation( false, profile, newContext( null, newProperties( "1.3" ) ) );
082
083 assertActivation( false, profile, newContext( null, newProperties( "1.5" ) ) );
084 }
085
086 public void testPrefixNegated()
087 throws Exception
088 {
089 Profile profile = newProfile( "!1.4" );
090
091 assertActivation( false, profile, newContext( null, newProperties( "1.4" ) ) );
092 assertActivation( false, profile, newContext( null, newProperties( "1.4.2" ) ) );
093 assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09" ) ) );
094 assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09-b03" ) ) );
095
096 assertActivation( true, profile, newContext( null, newProperties( "1.3" ) ) );
097
098 assertActivation( true, profile, newContext( null, newProperties( "1.5" ) ) );
099 }
100
101 public void testVersionRangeInclusiveBounds()
102 throws Exception
103 {
104 Profile profile = newProfile( "[1.5,1.6]" );
105
106 assertActivation( false, profile, newContext( null, newProperties( "1.4" ) ) );
107 assertActivation( false, profile, newContext( null, newProperties( "1.4.2" ) ) );
108 assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09" ) ) );
109 assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09-b03" ) ) );
110
111 assertActivation( true, profile, newContext( null, newProperties( "1.5" ) ) );
112 assertActivation( true, profile, newContext( null, newProperties( "1.5.0" ) ) );
113 assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09" ) ) );
114 assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09-b03" ) ) );
115 assertActivation( true, profile, newContext( null, newProperties( "1.5.1" ) ) );
116
117 assertActivation( true, profile, newContext( null, newProperties( "1.6" ) ) );
118 assertActivation( true, profile, newContext( null, newProperties( "1.6.0" ) ) );
119 assertActivation( true, profile, newContext( null, newProperties( "1.6.0_09" ) ) );
120 assertActivation( true, profile, newContext( null, newProperties( "1.6.0_09-b03" ) ) );
121 }
122
123 public void testVersionRangeExclusiveBounds()
124 throws Exception
125 {
126 Profile profile = newProfile( "(1.3,1.6)" );
127
128 assertActivation( false, profile, newContext( null, newProperties( "1.3" ) ) );
129 assertActivation( false, profile, newContext( null, newProperties( "1.3.0" ) ) );
130 assertActivation( false, profile, newContext( null, newProperties( "1.3.0_09" ) ) );
131 assertActivation( false, profile, newContext( null, newProperties( "1.3.0_09-b03" ) ) );
132
133 assertActivation( true, profile, newContext( null, newProperties( "1.3.1" ) ) );
134 assertActivation( true, profile, newContext( null, newProperties( "1.3.1_09" ) ) );
135 assertActivation( true, profile, newContext( null, newProperties( "1.3.1_09-b03" ) ) );
136
137 assertActivation( true, profile, newContext( null, newProperties( "1.5" ) ) );
138 assertActivation( true, profile, newContext( null, newProperties( "1.5.0" ) ) );
139 assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09" ) ) );
140 assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09-b03" ) ) );
141 assertActivation( true, profile, newContext( null, newProperties( "1.5.1" ) ) );
142
143 assertActivation( false, profile, newContext( null, newProperties( "1.6" ) ) );
144 }
145
146 public void testVersionRangeInclusiveLowerBound()
147 throws Exception
148 {
149 Profile profile = newProfile( "[1.5,)" );
150
151 assertActivation( false, profile, newContext( null, newProperties( "1.4" ) ) );
152 assertActivation( false, profile, newContext( null, newProperties( "1.4.2" ) ) );
153 assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09" ) ) );
154 assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09-b03" ) ) );
155
156 assertActivation( true, profile, newContext( null, newProperties( "1.5" ) ) );
157 assertActivation( true, profile, newContext( null, newProperties( "1.5.0" ) ) );
158 assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09" ) ) );
159 assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09-b03" ) ) );
160 assertActivation( true, profile, newContext( null, newProperties( "1.5.1" ) ) );
161
162 assertActivation( true, profile, newContext( null, newProperties( "1.6" ) ) );
163 assertActivation( true, profile, newContext( null, newProperties( "1.6.0" ) ) );
164 assertActivation( true, profile, newContext( null, newProperties( "1.6.0_09" ) ) );
165 assertActivation( true, profile, newContext( null, newProperties( "1.6.0_09-b03" ) ) );
166 }
167
168 public void testVersionRangeExclusiveUpperBound()
169 throws Exception
170 {
171 Profile profile = newProfile( "(,1.6)" );
172
173 assertActivation( true, profile, newContext( null, newProperties( "1.5" ) ) );
174 assertActivation( true, profile, newContext( null, newProperties( "1.5.0" ) ) );
175 assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09" ) ) );
176 assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09-b03" ) ) );
177 assertActivation( true, profile, newContext( null, newProperties( "1.5.1" ) ) );
178
179 assertActivation( false, profile, newContext( null, newProperties( "1.6" ) ) );
180 assertActivation( false, profile, newContext( null, newProperties( "1.6.0" ) ) );
181 assertActivation( false, profile, newContext( null, newProperties( "1.6.0_09" ) ) );
182 assertActivation( false, profile, newContext( null, newProperties( "1.6.0_09-b03" ) ) );
183 }
184
185 }