diff options
Diffstat (limited to 'framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation')
3 files changed, 462 insertions, 0 deletions
diff --git a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/AbstractProfileActivatorTest.java b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/AbstractProfileActivatorTest.java new file mode 100644 index 00000000..0ec3b326 --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/AbstractProfileActivatorTest.java @@ -0,0 +1,92 @@ +package org.apache.maven.model.profile.activation; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.Properties; + +import org.apache.maven.model.Profile; +import org.apache.maven.model.building.SimpleProblemCollector; +import org.apache.maven.model.profile.DefaultProfileActivationContext; +import org.apache.maven.model.profile.ProfileActivationContext; +import org.codehaus.plexus.PlexusTestCase; +import org.codehaus.plexus.component.annotations.Component; + +/** + * Provides common services to test {@link ProfileActivator} implementations. + * + * @author Benjamin Bentmann + */ +public abstract class AbstractProfileActivatorTest<T extends ProfileActivator> + extends PlexusTestCase +{ + + private Class<T> activatorClass; + + private String roleHint; + + protected T activator; + + public AbstractProfileActivatorTest( Class<T> activatorClass ) + { + if ( activatorClass == null ) + { + throw new IllegalArgumentException( "class of profile activator to test is not specified" ); + } + + this.activatorClass = activatorClass; + + roleHint = activatorClass.getAnnotation( Component.class ).hint(); + } + + @Override + protected void setUp() + throws Exception + { + super.setUp(); + + activator = activatorClass.cast( lookup( ProfileActivator.class, roleHint ) ); + } + + @Override + protected void tearDown() + throws Exception + { + activator = null; + + super.tearDown(); + } + + protected ProfileActivationContext newContext( final Properties userProperties, final Properties systemProperties ) + { + DefaultProfileActivationContext context = new DefaultProfileActivationContext(); + return context.setUserProperties( userProperties ).setSystemProperties( systemProperties ); + } + + protected void assertActivation( boolean active, Profile profile, ProfileActivationContext context ) + { + SimpleProblemCollector problems = new SimpleProblemCollector(); + + assertEquals( active, activator.isActive( profile, context, problems ) ); + + assertEquals( problems.getErrors().toString(), 0, problems.getErrors().size() ); + assertEquals( problems.getWarnings().toString(), 0, problems.getWarnings().size() ); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java new file mode 100644 index 00000000..440f120b --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/JdkVersionProfileActivatorTest.java @@ -0,0 +1,185 @@ +package org.apache.maven.model.profile.activation; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.Properties; + +import org.apache.maven.model.Activation; +import org.apache.maven.model.Profile; + +/** + * Tests {@link JdkVersionProfileActivator}. + * + * @author Benjamin Bentmann + */ +public class JdkVersionProfileActivatorTest + extends AbstractProfileActivatorTest<JdkVersionProfileActivator> +{ + + public JdkVersionProfileActivatorTest() + { + super( JdkVersionProfileActivator.class ); + } + + private Profile newProfile( String jdkVersion ) + { + Activation a = new Activation(); + a.setJdk( jdkVersion ); + + Profile p = new Profile(); + p.setActivation( a ); + + return p; + } + + private Properties newProperties( String javaVersion ) + { + Properties props = new Properties(); + props.setProperty( "java.version", javaVersion ); + return props; + } + + public void testNullSafe() + throws Exception + { + Profile p = new Profile(); + + assertActivation( false, p, newContext( null, null ) ); + + p.setActivation( new Activation() ); + + assertActivation( false, p, newContext( null, null ) ); + } + + public void testPrefix() + throws Exception + { + Profile profile = newProfile( "1.4" ); + + assertActivation( true, profile, newContext( null, newProperties( "1.4" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.4.2" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.4.2_09" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.4.2_09-b03" ) ) ); + + assertActivation( false, profile, newContext( null, newProperties( "1.3" ) ) ); + + assertActivation( false, profile, newContext( null, newProperties( "1.5" ) ) ); + } + + public void testPrefixNegated() + throws Exception + { + Profile profile = newProfile( "!1.4" ); + + assertActivation( false, profile, newContext( null, newProperties( "1.4" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.4.2" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09-b03" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "1.3" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "1.5" ) ) ); + } + + public void testVersionRangeInclusiveBounds() + throws Exception + { + Profile profile = newProfile( "[1.5,1.6]" ); + + assertActivation( false, profile, newContext( null, newProperties( "1.4" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.4.2" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09-b03" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "1.5" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09-b03" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.1" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "1.6" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.6.0" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.6.0_09" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.6.0_09-b03" ) ) ); + } + + public void testVersionRangeExclusiveBounds() + throws Exception + { + Profile profile = newProfile( "(1.3,1.6)" ); + + assertActivation( false, profile, newContext( null, newProperties( "1.3" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.3.0" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.3.0_09" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.3.0_09-b03" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "1.3.1" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.3.1_09" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.3.1_09-b03" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "1.5" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09-b03" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.1" ) ) ); + + assertActivation( false, profile, newContext( null, newProperties( "1.6" ) ) ); + } + + public void testVersionRangeInclusiveLowerBound() + throws Exception + { + Profile profile = newProfile( "[1.5,)" ); + + assertActivation( false, profile, newContext( null, newProperties( "1.4" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.4.2" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.4.2_09-b03" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "1.5" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09-b03" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.1" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "1.6" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.6.0" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.6.0_09" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.6.0_09-b03" ) ) ); + } + + public void testVersionRangeExclusiveUpperBound() + throws Exception + { + Profile profile = newProfile( "(,1.6)" ); + + assertActivation( true, profile, newContext( null, newProperties( "1.5" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.0_09-b03" ) ) ); + assertActivation( true, profile, newContext( null, newProperties( "1.5.1" ) ) ); + + assertActivation( false, profile, newContext( null, newProperties( "1.6" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.6.0" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.6.0_09" ) ) ); + assertActivation( false, profile, newContext( null, newProperties( "1.6.0_09-b03" ) ) ); + } + +} diff --git a/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/PropertyProfileActivatorTest.java b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/PropertyProfileActivatorTest.java new file mode 100644 index 00000000..73ab967e --- /dev/null +++ b/framework/src/maven/apache-maven-3.3.3/maven-model-builder/src/test/java/org/apache/maven/model/profile/activation/PropertyProfileActivatorTest.java @@ -0,0 +1,185 @@ +package org.apache.maven.model.profile.activation; + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import java.util.Properties; + +import org.apache.maven.model.Activation; +import org.apache.maven.model.ActivationProperty; +import org.apache.maven.model.Profile; + +/** + * Tests {@link PropertyProfileActivator}. + * + * @author Benjamin Bentmann + */ +public class PropertyProfileActivatorTest + extends AbstractProfileActivatorTest<PropertyProfileActivator> +{ + + public PropertyProfileActivatorTest() + { + super( PropertyProfileActivator.class ); + } + + private Profile newProfile( String key, String value ) + { + ActivationProperty ap = new ActivationProperty(); + ap.setName( key ); + ap.setValue( value ); + + Activation a = new Activation(); + a.setProperty( ap ); + + Profile p = new Profile(); + p.setActivation( a ); + + return p; + } + + private Properties newProperties( String key, String value ) + { + Properties props = new Properties(); + props.setProperty( key, value ); + return props; + } + + public void testNullSafe() + throws Exception + { + Profile p = new Profile(); + + assertActivation( false, p, newContext( null, null ) ); + + p.setActivation( new Activation() ); + + assertActivation( false, p, newContext( null, null ) ); + } + + public void testWithNameOnly_UserProperty() + throws Exception + { + Profile profile = newProfile( "prop", null ); + + assertActivation( true, profile, newContext( newProperties( "prop", "value" ), null ) ); + + assertActivation( false, profile, newContext( newProperties( "prop", "" ), null ) ); + + assertActivation( false, profile, newContext( newProperties( "other", "value" ), null ) ); + } + + public void testWithNameOnly_SystemProperty() + throws Exception + { + Profile profile = newProfile( "prop", null ); + + assertActivation( true, profile, newContext( null, newProperties( "prop", "value" ) ) ); + + assertActivation( false, profile, newContext( null, newProperties( "prop", "" ) ) ); + + assertActivation( false, profile, newContext( null, newProperties( "other", "value" ) ) ); + } + + public void testWithNegatedNameOnly_UserProperty() + throws Exception + { + Profile profile = newProfile( "!prop", null ); + + assertActivation( false, profile, newContext( newProperties( "prop", "value" ), null ) ); + + assertActivation( true, profile, newContext( newProperties( "prop", "" ), null ) ); + + assertActivation( true, profile, newContext( newProperties( "other", "value" ), null ) ); + } + + public void testWithNegatedNameOnly_SystemProperty() + throws Exception + { + Profile profile = newProfile( "!prop", null ); + + assertActivation( false, profile, newContext( null, newProperties( "prop", "value" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "prop", "" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "other", "value" ) ) ); + } + + public void testWithValue_UserProperty() + throws Exception + { + Profile profile = newProfile( "prop", "value" ); + + assertActivation( true, profile, newContext( newProperties( "prop", "value" ), null ) ); + + assertActivation( false, profile, newContext( newProperties( "prop", "other" ), null ) ); + + assertActivation( false, profile, newContext( newProperties( "prop", "" ), null ) ); + } + + public void testWithValue_SystemProperty() + throws Exception + { + Profile profile = newProfile( "prop", "value" ); + + assertActivation( true, profile, newContext( null, newProperties( "prop", "value" ) ) ); + + assertActivation( false, profile, newContext( null, newProperties( "prop", "other" ) ) ); + + assertActivation( false, profile, newContext( null, newProperties( "other", "" ) ) ); + } + + public void testWithNegatedValue_UserProperty() + throws Exception + { + Profile profile = newProfile( "prop", "!value" ); + + assertActivation( false, profile, newContext( newProperties( "prop", "value" ), null ) ); + + assertActivation( true, profile, newContext( newProperties( "prop", "other" ), null ) ); + + assertActivation( true, profile, newContext( newProperties( "prop", "" ), null ) ); + } + + public void testWithNegatedValue_SystemProperty() + throws Exception + { + Profile profile = newProfile( "prop", "!value" ); + + assertActivation( false, profile, newContext( null, newProperties( "prop", "value" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "prop", "other" ) ) ); + + assertActivation( true, profile, newContext( null, newProperties( "other", "" ) ) ); + } + + public void testWithValue_UserPropertyDominantOverSystemProperty() + throws Exception + { + Profile profile = newProfile( "prop", "value" ); + + Properties props1 = newProperties( "prop", "value" ); + Properties props2 = newProperties( "prop", "other" ); + + assertActivation( true, profile, newContext( props1, props2 ) ); + + assertActivation( false, profile, newContext( props2, props1 ) ); + } + +} |