use of org.apache.maven.plugins.war.stub.WarArtifact4CCStub in project maven-plugins by apache.
the class WarMojoTest method testFailOnMissingWebXmlTrue.
public void testFailOnMissingWebXmlTrue() throws Exception {
String testId = "SimpleWarMissingWebXmlTrue";
MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
File webAppDirectory = new File(getTestDirectory(), testId);
WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir());
String warName = "simple";
File webAppSource = createWebAppSource(testId);
File classesDir = createClassesDir(testId, true);
project.setArtifact(warArtifact);
this.configureMojo(mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project);
setVariableValueToObject(mojo, "outputDirectory", outputDir);
setVariableValueToObject(mojo, "warName", warName);
mojo.setFailOnMissingWebXml(true);
try {
mojo.execute();
fail("Building of the war isn't possible because web.xml is missing");
} catch (MojoExecutionException e) {
// expected behaviour
}
}
use of org.apache.maven.plugins.war.stub.WarArtifact4CCStub in project maven-plugins by apache.
the class WarMojoTest method testAttachClasses.
public void testAttachClasses() throws Exception {
String testId = "AttachClasses";
MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
File webAppDirectory = new File(getTestDirectory(), testId);
WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir());
String warName = "simple";
File webAppSource = createWebAppSource(testId);
File classesDir = createClassesDir(testId, false);
File xmlSource = createXMLConfigDir(testId, new String[] { "web.xml" });
project.setArtifact(warArtifact);
this.configureMojo(mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project);
setVariableValueToObject(mojo, "outputDirectory", outputDir);
setVariableValueToObject(mojo, "warName", warName);
mojo.setWebXml(new File(xmlSource, "web.xml"));
mojo.setAttachClasses(true);
mojo.setClassesClassifier("classes");
mojo.execute();
// validate jar file
File expectedJarFile = new File(outputDir, "simple-classes.jar");
assertJarContent(expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "sample-servlet.class" }, new String[] { null, null });
}
use of org.apache.maven.plugins.war.stub.WarArtifact4CCStub in project maven-plugins by apache.
the class WarMojoTest method testFailOnMissingWebXmlNotSpecifiedAndServlet30Used.
public void testFailOnMissingWebXmlNotSpecifiedAndServlet30Used() throws Exception {
String testId = "SimpleWarUnderServlet30";
MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
File webAppDirectory = new File(getTestDirectory(), testId);
WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir());
String warName = "simple";
File webAppSource = createWebAppSource(testId);
File classesDir = createClassesDir(testId, true);
final ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
JarArtifactStub jarArtifactStub = new JarArtifactStub(getBasedir(), artifactHandler);
jarArtifactStub.setFile(new File(getBasedir(), "/target/test-classes/unit/sample_wars/javax.servlet-api-3.0.1.jar"));
jarArtifactStub.setScope(Artifact.SCOPE_PROVIDED);
project.addArtifact(jarArtifactStub);
project.setArtifact(warArtifact);
project.setFile(warArtifact.getFile());
this.configureMojo(mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project);
setVariableValueToObject(mojo, "outputDirectory", outputDir);
setVariableValueToObject(mojo, "warName", warName);
mojo.execute();
// validate war file
File expectedWarFile = new File(outputDir, "simple.war");
final Map<String, JarEntry> jarContent = assertJarContent(expectedWarFile, new String[] { "META-INF/MANIFEST.MF", "pansit.jsp", "org/web/app/last-exile.jsp", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null, null, null, null, null });
assertFalse("web.xml should be missing", jarContent.containsKey("WEB-INF/web.xml"));
}
use of org.apache.maven.plugins.war.stub.WarArtifact4CCStub in project maven-plugins by apache.
the class WarMojoTest method testMetaInfContentWithContainerConfig.
public void testMetaInfContentWithContainerConfig() throws Exception {
String testId = "SimpleWarWithContainerConfig";
MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
File webAppDirectory = new File(getTestDirectory(), testId);
WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir());
String warName = "simple";
File webAppSource = createWebAppSource(testId);
File classesDir = createClassesDir(testId, true);
File xmlSource = createXMLConfigDir(testId, new String[] { "web.xml" });
// Create the sample config.xml
final File configFile = new File(webAppSource, "META-INF/config.xml");
createFile(configFile, "<config></config>");
project.setArtifact(warArtifact);
this.configureMojo(mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project);
setVariableValueToObject(mojo, "outputDirectory", outputDir);
setVariableValueToObject(mojo, "warName", warName);
mojo.setWebXml(new File(xmlSource, "web.xml"));
mojo.setContainerConfigXML(configFile);
mojo.execute();
// validate jar file
File expectedJarFile = new File(outputDir, "simple.war");
assertJarContent(expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "META-INF/config.xml", "WEB-INF/web.xml", "pansit.jsp", "org/web/app/last-exile.jsp", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null, null, mojo.getWebXml().toString(), null, null, null, null });
}
use of org.apache.maven.plugins.war.stub.WarArtifact4CCStub in project maven-plugins by apache.
the class WarMojoTest method testClassifier.
public void testClassifier() throws Exception {
String testId = "Classifier";
MavenProject4CopyConstructor project = new MavenProject4CopyConstructor();
String outputDir = getTestDirectory().getAbsolutePath() + "/" + testId + "-output";
File webAppDirectory = new File(getTestDirectory(), testId);
WarArtifact4CCStub warArtifact = new WarArtifact4CCStub(getBasedir());
ProjectHelperStub projectHelper = new ProjectHelperStub();
String warName = "simple";
File webAppSource = createWebAppSource(testId);
File classesDir = createClassesDir(testId, true);
File xmlSource = createXMLConfigDir(testId, new String[] { "web.xml" });
project.setArtifact(warArtifact);
this.configureMojo(mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project);
setVariableValueToObject(mojo, "projectHelper", projectHelper);
setVariableValueToObject(mojo, "classifier", "test-classifier");
setVariableValueToObject(mojo, "outputDirectory", outputDir);
setVariableValueToObject(mojo, "warName", warName);
mojo.setWebXml(new File(xmlSource, "web.xml"));
mojo.execute();
// validate jar file
File expectedJarFile = new File(outputDir, "simple-test-classifier.war");
assertJarContent(expectedJarFile, new String[] { "META-INF/MANIFEST.MF", "WEB-INF/web.xml", "pansit.jsp", "org/web/app/last-exile.jsp", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.xml", "META-INF/maven/org.apache.maven.plugin.test/maven-war-plugin-test/pom.properties" }, new String[] { null, mojo.getWebXml().toString(), null, null, null, null });
}
Aggregations