1 package org.apache.maven.profiles; 2 3 import org.apache.maven.model.Activation; 4 import org.apache.maven.model.ActivationProperty; 5 import org.apache.maven.model.Profile; 6 import org.apache.maven.model.ActivationOS; 7 import org.apache.maven.profiles.activation.ProfileActivationException; 8 import org.codehaus.plexus.PlexusTestCase; 9 10 import java.util.List ; 11 12 public class DefaultProfileManagerTest 13 extends PlexusTestCase 14 { 15 16 public void testShouldActivateDefaultProfile() throws ProfileActivationException 17 { 18 Profile notActivated = new Profile(); 19 notActivated.setId("notActivated"); 20 21 Activation nonActivation = new Activation(); 22 23 nonActivation.setJdk("19.2"); 24 25 notActivated.setActivation( nonActivation ); 26 27 Profile defaultActivated = new Profile(); 28 defaultActivated.setId("defaultActivated"); 29 30 Activation defaultActivation = new Activation(); 31 32 defaultActivation.setActiveByDefault(true); 33 34 defaultActivated.setActivation( defaultActivation ); 35 36 ProfileManager profileManager = new DefaultProfileManager(getContainer()); 37 38 profileManager.addProfile(notActivated); 39 profileManager.addProfile(defaultActivated); 40 41 List active = profileManager.getActiveProfiles(); 42 43 assertNotNull( active ); 44 assertEquals( 1, active.size() ); 45 assertEquals("defaultActivated", ((Profile)active.get(0)).getId()); 46 } 47 48 public void testShouldNotActivateDefaultProfile() throws ProfileActivationException 49 { 50 Profile syspropActivated = new Profile(); 51 syspropActivated.setId("syspropActivated"); 52 53 Activation syspropActivation = new Activation(); 54 55 ActivationProperty syspropProperty = new ActivationProperty(); 56 syspropProperty.setName("java.version"); 57 58 syspropActivation.setProperty(syspropProperty); 59 60 syspropActivated.setActivation( syspropActivation ); 61 62 Profile defaultActivated = new Profile(); 63 defaultActivated.setId("defaultActivated"); 64 65 Activation defaultActivation = new Activation(); 66 67 defaultActivation.setActiveByDefault(true); 68 69 defaultActivated.setActivation( defaultActivation ); 70 71 ProfileManager profileManager = new DefaultProfileManager(getContainer()); 72 73 profileManager.addProfile(syspropActivated); 74 profileManager.addProfile(defaultActivated); 75 76 List active = profileManager.getActiveProfiles(); 77 78 assertNotNull( active ); 79 assertEquals( 1, active.size() ); 80 assertEquals("syspropActivated", ((Profile)active.get(0)).getId()); 81 } 82 83 public void testShouldNotActivateReversalOfPresentSystemProperty() throws ProfileActivationException 84 { 85 Profile syspropActivated = new Profile(); 86 syspropActivated.setId("syspropActivated"); 87 88 Activation syspropActivation = new Activation(); 89 90 ActivationProperty syspropProperty = new ActivationProperty(); 91 syspropProperty.setName("!java.version"); 92 93 syspropActivation.setProperty(syspropProperty); 94 95 syspropActivated.setActivation( syspropActivation ); 96 97 ProfileManager profileManager = new DefaultProfileManager(getContainer()); 98 99 profileManager.addProfile(syspropActivated); 100 101 List active = profileManager.getActiveProfiles(); 102 103 assertNotNull( active ); 104 assertEquals( 0, active.size() ); 105 } 106 107 public void testShouldOverrideAndActivateInactiveProfile() throws ProfileActivationException 108 { 109 Profile syspropActivated = new Profile(); 110 syspropActivated.setId("syspropActivated"); 111 112 Activation syspropActivation = new Activation(); 113 114 ActivationProperty syspropProperty = new ActivationProperty(); 115 syspropProperty.setName("!java.version"); 116 117 syspropActivation.setProperty(syspropProperty); 118 119 syspropActivated.setActivation( syspropActivation ); 120 121 ProfileManager profileManager = new DefaultProfileManager(getContainer()); 122 123 profileManager.addProfile(syspropActivated); 124 125 profileManager.explicitlyActivate("syspropActivated"); 126 127 List active = profileManager.getActiveProfiles(); 128 129 assertNotNull( active ); 130 assertEquals( 1, active.size() ); 131 assertEquals( "syspropActivated", ((Profile)active.get(0)).getId()); 132 } 133 134 public void testShouldOverrideAndDeactivateActiveProfile() throws ProfileActivationException 135 { 136 Profile syspropActivated = new Profile(); 137 syspropActivated.setId("syspropActivated"); 138 139 Activation syspropActivation = new Activation(); 140 141 ActivationProperty syspropProperty = new ActivationProperty(); 142 syspropProperty.setName("java.version"); 143 144 syspropActivation.setProperty(syspropProperty); 145 146 syspropActivated.setActivation( syspropActivation ); 147 148 ProfileManager profileManager = new DefaultProfileManager(getContainer()); 149 150 profileManager.addProfile(syspropActivated); 151 152 profileManager.explicitlyDeactivate("syspropActivated"); 153 154 List active = profileManager.getActiveProfiles(); 155 156 assertNotNull( active ); 157 assertEquals( 0, active.size() ); 158 } 159 160 public void testOsActivationProfile() throws ProfileActivationException 161 { 162 Profile osActivated = new Profile(); 163 osActivated.setId("os-profile"); 164 165 Activation osActivation = new Activation(); 166 167 ActivationOS activationOS = new ActivationOS(); 168 169 activationOS.setName("!dddd"); 170 171 osActivation.setOs(activationOS); 172 173 osActivated.setActivation(osActivation); 174 175 ProfileManager profileManager = new DefaultProfileManager(getContainer()); 176 177 profileManager.addProfile(osActivated); 178 179 List active = profileManager.getActiveProfiles(); 180 181 assertNotNull( active ); 182 assertEquals( 1, active.size() ); 183 } 184 185 } 186 | Popular Tags |