use of org.apache.maven.plugin.testing.stubs.MavenProjectStub in project maven-plugins by apache.
the class AllProfilesMojoTest method testProfileFromPom.
/**
* Tests the case when profiles are present in the POM and in a parent POM.
*
* @throws Exception in case of errors.
*/
public void testProfileFromPom() throws Exception {
File testPom = new File(getBasedir(), "target/test-classes/unit/all-profiles/plugin-config.xml");
AllProfilesMojo mojo = (AllProfilesMojo) lookupMojo("all-profiles", testPom);
MavenProjectStub project = new MavenProjectStub();
project.getModel().setProfiles(Arrays.asList(newPomProfile("pro-1", "pom"), newPomProfile("pro-2", "pom")));
project.setParent(new MavenProjectStub());
project.getParent().getModel().setProfiles(Arrays.asList(newPomProfile("pro-3", "pom")));
project.setActiveProfiles(Arrays.asList(newPomProfile("pro-1", "pom")));
setUpMojo(mojo, Arrays.<MavenProject>asList(project), Collections.<org.apache.maven.settings.Profile>emptyList(), "profiles-from-pom.txt");
mojo.execute();
String file = readFile("profiles-from-pom.txt");
assertTrue(file.contains("Profile Id: pro-1 (Active: true , Source: pom)"));
assertTrue(file.contains("Profile Id: pro-2 (Active: false , Source: pom)"));
assertTrue(file.contains("Profile Id: pro-3 (Active: false , Source: pom)"));
}
use of org.apache.maven.plugin.testing.stubs.MavenProjectStub in project maven-plugins by apache.
the class AllProfilesMojoTest method testProfileFromSettings.
/**
* Tests the case when profiles are present in the settings.
*
* @throws Exception in case of errors.
*/
public void testProfileFromSettings() throws Exception {
File testPom = new File(getBasedir(), "target/test-classes/unit/all-profiles/plugin-config.xml");
AllProfilesMojo mojo = (AllProfilesMojo) lookupMojo("all-profiles", testPom);
MavenProject project = new MavenProjectStub();
project.setActiveProfiles(Arrays.asList(newPomProfile("settings-1", "settings.xml")));
List<org.apache.maven.settings.Profile> settingsProfiles = new ArrayList<org.apache.maven.settings.Profile>();
settingsProfiles.add(newSettingsProfile("settings-1"));
settingsProfiles.add(newSettingsProfile("settings-2"));
setUpMojo(mojo, Arrays.<MavenProject>asList(project), settingsProfiles, "profiles-from-settings.txt");
mojo.execute();
String file = readFile("profiles-from-settings.txt");
assertTrue(file.contains("Profile Id: settings-1 (Active: true , Source: settings.xml)"));
assertTrue(file.contains("Profile Id: settings-2 (Active: false , Source: settings.xml)"));
}
use of org.apache.maven.plugin.testing.stubs.MavenProjectStub in project maven-plugins by apache.
the class TestGetMojo method setUp.
protected void setUp() throws Exception {
// required for mojo lookups to work
super.setUp("markers", false);
File testPom = new File(getBasedir(), "target/test-classes/unit/get-test/plugin-config.xml");
assert testPom.exists();
mojo = (GetMojo) lookupMojo("get", testPom);
assertNotNull(mojo);
LegacySupport legacySupport = lookup(LegacySupport.class);
legacySupport.setSession(newMavenSession(new MavenProjectStub()));
DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) legacySupport.getRepositorySession();
repoSession.setLocalRepositoryManager(new SimpleLocalRepositoryManager(testDir.getAbsolutePath()));
setVariableValueToObject(mojo, "session", legacySupport.getSession());
}
use of org.apache.maven.plugin.testing.stubs.MavenProjectStub in project maven-plugins by apache.
the class ProjectInfoReportUtilsTest method getMavenProjectStub.
private MavenProject getMavenProjectStub(boolean https) {
final DistributionManagement distributionManagement = new DistributionManagement();
DeploymentRepository repository = new DeploymentRepository();
repository.setId("localhost");
repository.setUrl((https ? "https" : "http") + "://localhost:" + port);
distributionManagement.setRepository(repository);
distributionManagement.setSnapshotRepository(repository);
return new MavenProjectStub() {
@Override
public DistributionManagement getDistributionManagement() {
return distributionManagement;
}
};
}
Aggregations