001: package org.apache.maven.profiles.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 org.apache.maven.context.BuildContextManager;
023: import org.apache.maven.context.DefaultBuildContextManager;
024: import org.apache.maven.context.SystemBuildContext;
025: import org.apache.maven.model.Activation;
026: import org.apache.maven.model.ActivationProperty;
027: import org.apache.maven.model.Profile;
028: import org.codehaus.plexus.PlexusTestCase;
029:
030: import java.util.Properties;
031:
032: public class SystemPropertyProfileActivatorTest extends PlexusTestCase {
033:
034: private BuildContextManager buildContextManager;
035: private SystemPropertyProfileActivator activator;
036:
037: public void setUp() throws Exception {
038: super .setUp();
039:
040: buildContextManager = (BuildContextManager) lookup(
041: BuildContextManager.ROLE,
042: DefaultBuildContextManager.ROLE_HINT);
043:
044: SystemBuildContext sysContext = SystemBuildContext
045: .getSystemBuildContext(buildContextManager, true);
046: sysContext.store(buildContextManager);
047:
048: activator = (SystemPropertyProfileActivator) lookup(
049: ProfileActivator.ROLE, "system-property");
050: }
051:
052: public void testCanDetect_ShouldReturnTrueWhenActivationPropertyIsPresent()
053: throws Exception {
054: ActivationProperty prop = new ActivationProperty();
055: prop.setName("test");
056:
057: Activation activation = new Activation();
058:
059: activation.setProperty(prop);
060:
061: Profile profile = new Profile();
062:
063: profile.setActivation(activation);
064:
065: assertTrue(activator.canDetermineActivation(profile));
066: }
067:
068: public void testCanDetect_ShouldReturnFalseWhenActivationPropertyIsNotPresent()
069: throws Exception {
070: Activation activation = new Activation();
071:
072: Profile profile = new Profile();
073:
074: profile.setActivation(activation);
075:
076: assertFalse(activator.canDetermineActivation(profile));
077: }
078:
079: public void testIsActive_ShouldReturnTrueWhenPropertyNameSpecifiedAndPresent()
080: throws Exception {
081: ActivationProperty prop = new ActivationProperty();
082: prop.setName("test");
083:
084: Activation activation = new Activation();
085:
086: activation.setProperty(prop);
087:
088: Profile profile = new Profile();
089:
090: profile.setActivation(activation);
091:
092: System.setProperty("test", "true");
093:
094: assertTrue(activator.isActive(profile));
095: }
096:
097: public void testIsActive_ShouldReturnFalseWhenPropertyNameSpecifiedAndMissing()
098: throws Exception {
099: ActivationProperty prop = new ActivationProperty();
100: prop.setName("test");
101:
102: Activation activation = new Activation();
103:
104: activation.setProperty(prop);
105:
106: Profile profile = new Profile();
107:
108: profile.setActivation(activation);
109:
110: Properties props = System.getProperties();
111: props.remove("test");
112: System.setProperties(props);
113:
114: assertFalse(activator.isActive(profile));
115: }
116:
117: }
|