Search in sources :

Example 6 with ArtifactStub

use of org.apache.maven.plugin.testing.stubs.ArtifactStub in project maven-plugins by apache.

the class WarExplodedMojoTest method testExplodedWarWithXar.

/**
     * @throws Exception in case of an error.
     */
public void testExplodedWarWithXar() throws Exception {
    // setup test data
    String testId = "ExplodedWarWithXar";
    MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
    File webAppDirectory = new File(getTestDirectory(), testId);
    File webAppSource = createWebAppSource(testId);
    File classesDir = createClassesDir(testId, true);
    // Fake here since the xar artifact handler does not exist: no biggie
    ArtifactHandler artifactHandler = (ArtifactHandler) lookup(ArtifactHandler.ROLE, "jar");
    ArtifactStub xarArtifact = new XarArtifactStub(getBasedir(), artifactHandler);
    File xarFile = xarArtifact.getFile();
    assertTrue("jar not found: " + xarFile.toString(), xarFile.exists());
    // configure mojo
    project.addArtifact(xarArtifact);
    this.configureMojo(mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project);
    mojo.execute();
    // validate operation
    File expectedWebSourceFile = new File(webAppDirectory, "pansit.jsp");
    File expectedWebSource2File = new File(webAppDirectory, "org/web/app/last-exile.jsp");
    // final name form is <artifactId>-<version>.<type>
    File expectedJarArtifact = new File(webAppDirectory, "WEB-INF/extensions/xarartifact-0.0-Test.jar");
    assertTrue("source files not found: " + expectedWebSourceFile.toString(), expectedWebSourceFile.exists());
    assertTrue("source files not found: " + expectedWebSource2File.toString(), expectedWebSource2File.exists());
    assertTrue("jar artifact not found: " + expectedJarArtifact.toString(), expectedJarArtifact.exists());
    // house keeping
    expectedWebSourceFile.delete();
    expectedWebSource2File.delete();
    expectedJarArtifact.delete();
}
Also used : XarArtifactStub(org.apache.maven.plugins.war.stub.XarArtifactStub) ArtifactHandler(org.apache.maven.artifact.handler.ArtifactHandler) MavenProjectArtifactsStub(org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub) XarArtifactStub(org.apache.maven.plugins.war.stub.XarArtifactStub) MarArtifactStub(org.apache.maven.plugins.war.stub.MarArtifactStub) EJBArtifactStub(org.apache.maven.plugins.war.stub.EJBArtifactStub) WarArtifactStub(org.apache.maven.plugins.war.stub.WarArtifactStub) PARArtifactStub(org.apache.maven.plugins.war.stub.PARArtifactStub) TLDArtifactStub(org.apache.maven.plugins.war.stub.TLDArtifactStub) IncludeExcludeWarArtifactStub(org.apache.maven.plugins.war.stub.IncludeExcludeWarArtifactStub) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) EJBClientArtifactStub(org.apache.maven.plugins.war.stub.EJBClientArtifactStub) JarArtifactStub(org.apache.maven.plugins.war.stub.JarArtifactStub) AarArtifactStub(org.apache.maven.plugins.war.stub.AarArtifactStub) File(java.io.File)

Example 7 with ArtifactStub

use of org.apache.maven.plugin.testing.stubs.ArtifactStub in project maven-plugins by apache.

the class AbstractWarExplodedMojoTest method setUpMojo.

/**
     * Configures the exploded mojo for the specified test.
     * 
     * If the <tt>sourceFiles</tt> parameter is <tt>null</tt>, sample JSPs are created by default.
     *
     * @param testId the id of the test
     * @param artifactStubs the dependencies (may be null)
     * @param sourceFiles the source files to create (may be null)
     * @return the webapp directory
     * @throws Exception if an error occurs while configuring the mojo
     */
protected File setUpMojo(final String testId, ArtifactStub[] artifactStubs, String[] sourceFiles) throws Exception {
    final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
    final File webAppDirectory = new File(getTestDirectory(), testId);
    // Create the webapp sources
    File webAppSource;
    if (sourceFiles == null) {
        webAppSource = createWebAppSource(testId);
    } else {
        webAppSource = createWebAppSource(testId, false);
        for (String sourceFile : sourceFiles) {
            File sample = new File(webAppSource, sourceFile);
            createFile(sample);
        }
    }
    final File classesDir = createClassesDir(testId, true);
    final File workDirectory = new File(getTestDirectory(), "/war/work-" + testId);
    createDir(workDirectory);
    if (artifactStubs != null) {
        for (ArtifactStub artifactStub : artifactStubs) {
            project.addArtifact(artifactStub);
        }
    }
    configureMojo(mojo, new LinkedList<String>(), classesDir, webAppSource, webAppDirectory, project);
    setVariableValueToObject(mojo, "workDirectory", workDirectory);
    return webAppDirectory;
}
Also used : MavenProjectArtifactsStub(org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) File(java.io.File)

Example 8 with ArtifactStub

use of org.apache.maven.plugin.testing.stubs.ArtifactStub in project maven-plugins by apache.

the class WarOverlaysTest method testCacheWithRemovedOverlay.

public void testCacheWithRemovedOverlay() throws Exception {
    // setup test data
    final String testId = "cache-removed-overlay";
    // Add an overlay
    final ArtifactStub overlay = buildWarOverlayStub("overlay-one");
    final ArtifactStub overlay2 = buildWarOverlayStub("overlay-two");
    final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] { overlay, overlay2 });
    final List<File> assertedFiles = new ArrayList<File>();
    try {
        // Use the cache
        setVariableValueToObject(mojo, "useCache", Boolean.TRUE);
        setVariableValueToObject(mojo, "cacheFile", new File(mojo.getWorkDirectory(), "cache.xml"));
        final LinkedList<Overlay> overlays = new LinkedList<Overlay>();
        overlays.add(new DefaultOverlay(overlay));
        overlays.add(new DefaultOverlay(overlay2));
        mojo.setOverlays(overlays);
        mojo.execute();
        // Now remove overlay one the right file is overwritten
        final LinkedList<Overlay> updatedOverlays = new LinkedList<Overlay>();
        updatedOverlays.add(new DefaultOverlay(overlay2));
        mojo.setOverlays(updatedOverlays);
        // Remove overlay one as a dep
        mojo.getProject().getArtifacts().remove(overlay);
        mojo.execute();
        assertedFiles.addAll(assertDefaultContent(webAppDirectory));
        assertedFiles.addAll(assertWebXml(webAppDirectory));
        assertedFiles.addAll(assertCustomContent(webAppDirectory, new String[] { "index.jsp", "login.jsp", "admin.jsp" }, "overlay file not found"));
        // index and login come from overlay2 now
        assertOverlayedFile(webAppDirectory, "overlay-two", "index.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-one", "login.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-two", "admin.jsp");
        // Ok now check that there is no more files/directories
        final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] { MANIFEST_PATH });
        assertWebAppContent(webAppDirectory, assertedFiles, filter);
    } finally {
        cleanDirectory(webAppDirectory);
    }
}
Also used : DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) ArrayList(java.util.ArrayList) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) Overlay(org.apache.maven.plugins.war.Overlay) DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) FileFilter(java.io.FileFilter) File(java.io.File) LinkedList(java.util.LinkedList)

Example 9 with ArtifactStub

use of org.apache.maven.plugin.testing.stubs.ArtifactStub in project maven-plugins by apache.

the class WarOverlaysTest method testScenarioOneWithFullSettings.

/**
     * Tests that specifying the overlay explicitely has the same behavior as the default (i.e. order, etc).
     * 
     * The default project is explicitely specified so this should match the default.
     *
     * @throws Exception if an error occurs
     */
public void testScenarioOneWithFullSettings() throws Exception {
    // setup test data
    final String testId = "scenario-one-full-settings";
    // Add an overlay
    final ArtifactStub overlay1 = buildWarOverlayStub("overlay-full-1");
    final ArtifactStub overlay2 = buildWarOverlayStub("overlay-full-2");
    final ArtifactStub overlay3 = buildWarOverlayStub("overlay-full-3");
    final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] { overlay1, overlay2, overlay3 }, new String[] { "org/sample/company/test.jsp", "jsp/b.jsp" });
    // Add the tags
    final List<Overlay> overlays = new ArrayList<Overlay>();
    // Add the default project explicitely
    overlays.add(mojo.getCurrentProjectOverlay());
    // Other overlays
    overlays.add(new DefaultOverlay(overlay1));
    overlays.add(new DefaultOverlay(overlay2));
    overlays.add(new DefaultOverlay(overlay3));
    mojo.setOverlays(overlays);
    // current project ignored. Should be on top of the list
    assertScenariOne(testId, webAppDirectory);
}
Also used : DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) ArrayList(java.util.ArrayList) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) Overlay(org.apache.maven.plugins.war.Overlay) DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) File(java.io.File)

Example 10 with ArtifactStub

use of org.apache.maven.plugin.testing.stubs.ArtifactStub in project maven-plugins by apache.

the class WarOverlaysTest method testDefaultOverlay.

public void testDefaultOverlay() throws Exception {
    // setup test data
    final String testId = "default-overlay";
    // Add an overlay
    final ArtifactStub overlay = buildWarOverlayStub("overlay-one");
    final File webAppDirectory = setUpMojo(testId, new ArtifactStub[] { overlay });
    final List<File> assertedFiles = new ArrayList<File>();
    try {
        mojo.execute();
        assertedFiles.addAll(assertDefaultContent(webAppDirectory));
        assertedFiles.addAll(assertWebXml(webAppDirectory));
        assertedFiles.addAll(assertCustomContent(webAppDirectory, new String[] { "index.jsp", "login.jsp" }, "overlay file not found"));
        // index and login come from overlay1
        assertOverlayedFile(webAppDirectory, "overlay-one", "index.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-one", "login.jsp");
        // Ok now check that there is no more files/directories
        final FileFilter filter = new FileFilterImpl(webAppDirectory, new String[] { MANIFEST_PATH });
        assertWebAppContent(webAppDirectory, assertedFiles, filter);
    } finally {
        cleanDirectory(webAppDirectory);
    }
}
Also used : ArrayList(java.util.ArrayList) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) FileFilter(java.io.FileFilter) File(java.io.File)

Aggregations

ArtifactStub (org.apache.maven.plugin.testing.stubs.ArtifactStub)26 File (java.io.File)17 ArrayList (java.util.ArrayList)13 Overlay (org.apache.maven.plugins.war.Overlay)11 DefaultOverlay (org.apache.maven.plugins.war.overlay.DefaultOverlay)11 MavenProjectArtifactsStub (org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub)11 WarArtifactStub (org.apache.maven.plugins.war.stub.WarArtifactStub)10 ArtifactHandler (org.apache.maven.artifact.handler.ArtifactHandler)9 JarArtifactStub (org.apache.maven.plugins.war.stub.JarArtifactStub)9 FileFilter (java.io.FileFilter)6 InvalidOverlayConfigurationException (org.apache.maven.plugins.war.overlay.InvalidOverlayConfigurationException)5 OverlayManager (org.apache.maven.plugins.war.overlay.OverlayManager)5 AarArtifactStub (org.apache.maven.plugins.war.stub.AarArtifactStub)5 EJBArtifactStub (org.apache.maven.plugins.war.stub.EJBArtifactStub)5 EJBClientArtifactStub (org.apache.maven.plugins.war.stub.EJBClientArtifactStub)5 IncludeExcludeWarArtifactStub (org.apache.maven.plugins.war.stub.IncludeExcludeWarArtifactStub)5 MarArtifactStub (org.apache.maven.plugins.war.stub.MarArtifactStub)5 PARArtifactStub (org.apache.maven.plugins.war.stub.PARArtifactStub)5 TLDArtifactStub (org.apache.maven.plugins.war.stub.TLDArtifactStub)5 XarArtifactStub (org.apache.maven.plugins.war.stub.XarArtifactStub)5