Skip to content

Commit

Permalink
test cases for bug 350414
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Eisenberg committed May 22, 2012
1 parent acdd35c commit 22feff4
Show file tree
Hide file tree
Showing 3 changed files with 212 additions and 0 deletions.
Expand Up @@ -17,6 +17,7 @@


public class LifecycleMappingMetadataPrioritiesTest extends AbstractLifecycleMappingTest {

// Tests lifecycle mapping declared in default lifecycle mapping metadata
public void testDefaultMetadataSource() throws Exception {
LifecycleMappingMetadataSource defaultMetadata = loadLifecycleMappingMetadataSource("projects/lifecyclemapping/lifecycleMappingMetadata/LifecycleMappingMetadataPrioritiesTest/defaultMetadata.xml");
Expand Down Expand Up @@ -133,4 +134,5 @@ public void testParent() throws Exception {
WorkspaceHelpers.assertLifecycleIdErrorMarkerAttributes(marker,
"no such lifecycle mapping for test-packaging-a - override");
}

}
Expand Up @@ -19,6 +19,12 @@

@SuppressWarnings("restriction")
public class PluginExecutionMetadataPrioritiesTest extends AbstractLifecycleMappingTest {
protected void tearDown() throws Exception {
super.tearDown();
// ensure there is no workspace lifecycle mapping
setWorkspaceLifecycleMappingMetadataSource("");
}

public void testDefaultMetadataSource() throws Exception {
LifecycleMappingMetadataSource defaultMetadata = loadLifecycleMappingMetadataSource("projects/lifecyclemapping/lifecycleMappingMetadata/PluginExecutionMetadataPrioritiesTest/defaultMetadata.xml");
LifecycleMappingFactory.setDefaultLifecycleMappingMetadataSource(defaultMetadata);
Expand Down Expand Up @@ -159,4 +165,151 @@ public void testParent() throws Exception {
WorkspaceHelpers.assertErrorMarker(IMavenConstants.MARKER_LIFECYCLEMAPPING_ID, expectedErrorMessage,
null /*lineNumber*/, project);
}

// Workspace mappings override plugin mappings
public void testWorkspace() throws Exception {

// now set the lifecycle mapping in the workspace.
setWorkspaceLifecycleMappingMetadataSource(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<lifecycleMappingMetadata>\n" +
" <pluginExecutions>\n" +
" <pluginExecution>\n" +
" <pluginExecutionFilter>\n" +
" <groupId>org.eclipse.m2e.test.lifecyclemapping</groupId>\n" +
" <artifactId>test-lifecyclemapping-plugin</artifactId>\n" +
" <versionRange>[1.0.0,)</versionRange>\n" +
" <goals>\n" +
" <goal>test-goal-for-eclipse-extension2</goal>\n" +
" </goals>\n" +
" </pluginExecutionFilter>\n" +
" <action>\n" +
" <ignore/>\n" +
" </action>\n" +
" </pluginExecution>\n" +
" </pluginExecutions>\n" +
"</lifecycleMappingMetadata>");

LifecycleMappingMetadataSource defaultMetadata = loadLifecycleMappingMetadataSource("projects/lifecyclemapping/lifecycleMappingMetadata/PluginExecutionMetadataPrioritiesTest/defaultMetadata.xml");
LifecycleMappingFactory.setDefaultLifecycleMappingMetadataSource(defaultMetadata);

IMavenProjectFacade facade = importMavenProject(
"projects/lifecyclemapping/lifecycleMappingMetadata/PluginExecutionMetadataPrioritiesTest",
"testDefaultMetadataSource/pom.xml");
assertNotNull("Expected not null MavenProjectFacade", facade);
IProject project = facade.getProject();
List<IMarker> errorMarkers = WorkspaceHelpers.findErrorMarkers(project);
assertNotNull(errorMarkers);
assertEquals(WorkspaceHelpers.toString(errorMarkers), 2, errorMarkers.size());

// should still have lifecycle errors
String expectedErrorMessage = "Plugin execution not covered by lifecycle configuration: org.eclipse.m2e.test.lifecyclemapping:test-lifecyclemapping-plugin:1.0.0:test-goal-1 (execution: default-test-goal-1, phase: process-resources)";
WorkspaceHelpers.assertErrorMarker(IMavenConstants.MARKER_LIFECYCLEMAPPING_ID, expectedErrorMessage,
11 /*lineNumber*/, project);

// should not have any plugin execution errors
expectedErrorMessage = "Project configurator \"missing default project configurator id for test-lifecyclemapping-plugin:test-goal-1\" is not available. To enable full functionality, install the project configurator and run Maven->Update Project Configuration.";
WorkspaceHelpers.assertErrorMarker(IMavenConstants.MARKER_LIFECYCLEMAPPING_ID,
expectedErrorMessage, null /*lineNumber*/, project);
}
// Embedded metadata should override Workspace mappings
public void testPomOverridesWorkspace() throws Exception {

// now set the lifecycle mapping in the workspace.
setWorkspaceLifecycleMappingMetadataSource(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<lifecycleMappingMetadata>\n" +
" <pluginExecutions>\n" +
" <pluginExecution>\n" +
" <pluginExecutionFilter>\n" +
" <groupId>org.eclipse.m2e.test.lifecyclemapping</groupId>\n" +
" <artifactId>test-lifecyclemapping-plugin</artifactId>\n" +
" <versionRange>[1.0.0,)</versionRange>\n" +
" <goals>\n" +
" <goal>test-goal-for-eclipse-extension2</goal>\n" +
" </goals>\n" +
" </pluginExecutionFilter>\n" +
" <action>\n" +
" <configurator>\n" +
" <id>no such project configurator id for test-lifecyclemapping-plugin:test-goal-for-eclipse-extension2 - embedded from pom</id>\n" +
" </configurator>\n" +
" </action>\n" +
" </pluginExecution>\n" +
" </pluginExecutions>\n" +
"</lifecycleMappingMetadata>");

IMavenProjectFacade parentFacade = importMavenProject(
"projects/lifecyclemapping/lifecycleMappingMetadata/PluginExecutionMetadataPrioritiesTest",
"testParent/pom.xml");
assertNotNull("Expected not null MavenProjectFacade", parentFacade);
IProject project = parentFacade.getProject();
WorkspaceHelpers.assertNoErrors(project);

// parent pom should have no errors even though bad metadata is in the workspace mappings
IMavenProjectFacade facade = importMavenProject(
"projects/lifecyclemapping/lifecycleMappingMetadata/PluginExecutionMetadataPrioritiesTest",
"testParent/useParent/pom.xml");
assertNotNull("Expected not null MavenProjectFacade", facade);
project = facade.getProject();
List<IMarker> errorMarkers = WorkspaceHelpers.findErrorMarkers(project);
assertNotNull(errorMarkers);
assertEquals(WorkspaceHelpers.toString(errorMarkers), 2, errorMarkers.size());
String expectedErrorMessage = "Plugin execution not covered by lifecycle configuration: org.eclipse.m2e.test.lifecyclemapping:test-lifecyclemapping-plugin:1.0.0:test-goal-1 (execution: default-test-goal-1, phase: process-resources)";
IMarker marker = WorkspaceHelpers.assertErrorMarker(IMavenConstants.MARKER_LIFECYCLEMAPPING_ID,
expectedErrorMessage, null /*lineNumber*/, project);
SourceLocation causeLocation = new SourceLocation(parentFacade.getMavenProject().getFile().getAbsolutePath(),
WorkspaceHelpers.getModelId(parentFacade.getMavenProject()), 11, 7, 14);
WorkspaceHelpers.assertMarkerLocation(new SourceLocation(5, 3, 10, causeLocation), marker);
expectedErrorMessage = "Project configurator \"no such project configurator id for test-lifecyclemapping-plugin:test-goal-1 - parent\" is not available. To enable full functionality, install the project configurator and run Maven->Update Project Configuration.";
marker = WorkspaceHelpers.assertErrorMarker(IMavenConstants.MARKER_LIFECYCLEMAPPING_ID, expectedErrorMessage,
null /*lineNumber*/, project);
WorkspaceHelpers.assertMarkerLocation(new SourceLocation(5, 3, 10, causeLocation), marker);
}

// metadata from workspace should override eclipse extension metadata
public void testWorkspaceOverridesEclipseExtensions() throws Exception {
// now set the lifecycle mapping in the workspace.
setWorkspaceLifecycleMappingMetadataSource(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<lifecycleMappingMetadata>\n" +
" <pluginExecutions>\n" +
" <pluginExecution>\n" +
" <pluginExecutionFilter>\n" +
" <groupId>org.eclipse.m2e.test.lifecyclemapping</groupId>\n" +
" <artifactId>test-lifecyclemapping-plugin</artifactId>\n" +
" <versionRange>[1.0.0,)</versionRange>\n" +
" <goals>\n" +
" <goal>test-goal-for-eclipse-extension2</goal>\n" +
" </goals>\n" +
" </pluginExecutionFilter>\n" +
" <action>\n" +
" <configurator>\n" +
" <id>no such project configurator id for test-lifecyclemapping-plugin:test-goal-for-eclipse-extension2 - workspace</id>\n" +
" </configurator>\n" +
" </action>\n" +
" </pluginExecution>\n" +
" </pluginExecutions>\n" +
"</lifecycleMappingMetadata>");
LifecycleMappingMetadataSource defaultMetadata = loadLifecycleMappingMetadataSource("projects/lifecyclemapping/lifecycleMappingMetadata/PluginExecutionMetadataPrioritiesTest/defaultMetadata.xml");
LifecycleMappingFactory.setDefaultLifecycleMappingMetadataSource(defaultMetadata);

IMavenProjectFacade facade = importMavenProject(
"projects/lifecyclemapping/lifecycleMappingMetadata/PluginExecutionMetadataPrioritiesTest",
"testEclipseExtension/pom.xml");
assertNotNull("Expected not null MavenProjectFacade", facade);
IProject project = facade.getProject();

// should have an error since workspace overrides with bad lifecycle data
String expectedErrorMessage = "Plugin execution not covered by lifecycle configuration: org.eclipse.m2e.test.lifecyclemapping:test-lifecyclemapping-plugin:1.0.0:test-goal-for-eclipse-extension2 (execution: default-test-goal-for-eclipse-extension2, phase: compile)";
WorkspaceHelpers.assertErrorMarker(IMavenConstants.MARKER_LIFECYCLEMAPPING_ID, expectedErrorMessage,
11 /*lineNumber*/, project);

expectedErrorMessage = "Project configurator \"no such project configurator id for test-lifecyclemapping-plugin:test-goal-for-eclipse-extension2 - workspace\" is not available. To enable full functionality, install the project configurator and run Maven->Update Project Configuration.";
IMarker marker = WorkspaceHelpers.assertErrorMarker(IMavenConstants.MARKER_LIFECYCLEMAPPING_ID,
expectedErrorMessage, 11 /*lineNumber*/, project);
WorkspaceHelpers
.assertConfiguratorErrorMarkerAttributes(
marker,
"no such project configurator id for test-lifecyclemapping-plugin:test-goal-for-eclipse-extension2 - workspace");
}
}
@@ -0,0 +1,57 @@
/*******************************************************************************
* Copyright (c) 2012 VMware, Inc
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Andrew Eisenberg - Work on Bug 350414
*******************************************************************************/

package org.eclipse.m2e.tests.lifecycle;

import org.eclipse.m2e.tests.common.AbstractLifecycleMappingTest;


/**
* Tests for changing the workspace lifecycle mappings file
* WorkspaceMappingsFileTest
*
* @author andrew
*/
public class WorkspaceMappingsFileTest extends AbstractLifecycleMappingTest {

protected void tearDown() throws Exception {
mavenConfiguration.setWorkspaceMappingsFile(null);
super.tearDown();
}

public void testIsDefault() throws Exception {
assertEquals(mavenConfiguration.getDefaultWorkspaceMappingsFile(),
mavenConfiguration.getWorkspaceMappingsFile());
}

public void testChangeFromDefault() throws Exception {
String newFile = "foo";
mavenConfiguration.setWorkspaceMappingsFile(newFile);
assertEquals(newFile,
mavenConfiguration.getWorkspaceMappingsFile());
}
public void testChangeToDefault() throws Exception {
String newFile = "foo";
mavenConfiguration.setWorkspaceMappingsFile(newFile);
mavenConfiguration.setWorkspaceMappingsFile(null);
assertEquals(mavenConfiguration.getDefaultWorkspaceMappingsFile(),
mavenConfiguration.getWorkspaceMappingsFile());
}

public void testChangeText() throws Exception {
String origText = mavenConfiguration.getWorkspaceMappings();
String newText = "blah!";
mavenConfiguration.setWorkspaceMappings(newText);
assertEquals(newText, mavenConfiguration.getWorkspaceMappings());
mavenConfiguration.setWorkspaceMappings(origText);
assertEquals(origText, mavenConfiguration.getWorkspaceMappings());
}
}

0 comments on commit 22feff4

Please sign in to comment.