Search in sources :

Example 21 with ArtifactStub

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

the class WarOverlaysTest method testOverlaysIncludesExcludesWithMultipleDefinitions.

public void testOverlaysIncludesExcludesWithMultipleDefinitions() throws Exception {
    // setup test data
    final String testId = "overlays-includes-excludes-multiple-defs";
    // 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" });
    Overlay over1 = new DefaultOverlay(overlay3);
    over1.setExcludes("**/a.*,**/c.*,**/*.xml");
    Overlay over2 = new DefaultOverlay(overlay1);
    over2.setIncludes("jsp/d/*");
    over2.setExcludes("jsp/d/a.jsp");
    Overlay over3 = new DefaultOverlay(overlay3);
    over3.setIncludes("**/*.jsp");
    Overlay over4 = new DefaultOverlay(overlay2);
    mojo.setOverlays(new LinkedList<Overlay>());
    mojo.addOverlay(over1);
    mojo.addOverlay(over2);
    mojo.addOverlay(over3);
    mojo.addOverlay(mojo.getCurrentProjectOverlay());
    mojo.addOverlay(over4);
    final List<File> assertedFiles = new ArrayList<File>();
    try {
        mojo.execute();
        assertedFiles.addAll(assertWebXml(webAppDirectory));
        assertedFiles.addAll(assertCustomContent(webAppDirectory, new String[] { "jsp/a.jsp", "jsp/b.jsp", "jsp/c.jsp", "jsp/d/a.jsp", "jsp/d/b.jsp", "jsp/d/c.jsp", "org/sample/company/test.jsp", "WEB-INF/classes/a.class", "WEB-INF/classes/b.class", "WEB-INF/classes/c.class", "WEB-INF/lib/a.jar", "WEB-INF/lib/b.jar", "WEB-INF/lib/c.jar" }, "overlay file not found"));
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/a.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/b.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/c.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/a.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "jsp/d/b.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-full-1", "jsp/d/c.jsp");
        assertDefaultFileContent(testId, webAppDirectory, "org/sample/company/test.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/web.xml");
        assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/a.class");
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/classes/b.class");
        assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/classes/c.class");
        assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/a.jar");
        assertOverlayedFile(webAppDirectory, "overlay-full-3", "WEB-INF/lib/b.jar");
        assertOverlayedFile(webAppDirectory, "overlay-full-2", "WEB-INF/lib/c.jar");
        // 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)

Example 22 with ArtifactStub

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

the class WarOverlaysTest method testDefaultOverlays.

public void testDefaultOverlays() throws Exception {
    // setup test data
    final String testId = "default-overlays";
    // 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 {
        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 overlay1
        assertOverlayedFile(webAppDirectory, "overlay-one", "index.jsp");
        assertOverlayedFile(webAppDirectory, "overlay-one", "login.jsp");
        // admin comes from overlay2
        // index and login comes from overlay1
        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 : ArrayList(java.util.ArrayList) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) FileFilter(java.io.FileFilter) File(java.io.File)

Example 23 with ArtifactStub

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

the class WarOverlaysTest method testScenarioOneWithDefaulSettings.

/**
     * Merge a dependent WAR when a file in the war source directory overrides one found in the WAR.
     * 
     * It also tests completeness of the resulting war as well as the proper order of dependencies.
     *
     * @throws Exception if any error occurs
     */
public void testScenarioOneWithDefaulSettings() throws Exception {
    // setup test data
    final String testId = "scenario-one-default-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" });
    assertScenariOne(testId, webAppDirectory);
}
Also used : ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) File(java.io.File)

Example 24 with ArtifactStub

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

the class OverlayManagerTest method testUnknonwnOverlay.

public void testUnknonwnOverlay() throws Exception {
    final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
    final ArtifactStub first = newWarArtifact("test", "test-webapp");
    project.addArtifact(first);
    final List<Overlay> overlays = new ArrayList<Overlay>();
    overlays.add(new Overlay("test", "test-webapp-2"));
    try {
        final Overlay currentProjectOVerlay = Overlay.createInstance();
        new OverlayManager(overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, currentProjectOVerlay);
        fail("Should have failed to validate an unknown overlay");
    } catch (InvalidOverlayConfigurationException e) {
    // OK
    }
}
Also used : OverlayManager(org.apache.maven.plugins.war.overlay.OverlayManager) MavenProjectArtifactsStub(org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub) ArrayList(java.util.ArrayList) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) WarArtifactStub(org.apache.maven.plugins.war.stub.WarArtifactStub) Overlay(org.apache.maven.plugins.war.Overlay) DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) InvalidOverlayConfigurationException(org.apache.maven.plugins.war.overlay.InvalidOverlayConfigurationException)

Example 25 with ArtifactStub

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

the class OverlayManagerTest method testAutodetectSimpleOverlay.

public void testAutodetectSimpleOverlay(Overlay currentProjectOverlay) throws Exception {
    final MavenProjectArtifactsStub project = new MavenProjectArtifactsStub();
    final ArtifactStub first = newWarArtifact("test", "test-webapp");
    project.addArtifact(first);
    final List<Overlay> overlays = new ArrayList<Overlay>();
    try {
        final Overlay overlay = currentProjectOverlay;
        OverlayManager manager = new OverlayManager(overlays, project, DEFAULT_INCLUDES, DEFAULT_EXCLUDES, overlay);
        assertNotNull(manager.getOverlays());
        assertEquals(2, manager.getOverlays().size());
        assertEquals(overlay, manager.getOverlays().get(0));
        assertEquals(new DefaultOverlay(first), manager.getOverlays().get(1));
    } catch (InvalidOverlayConfigurationException e) {
        e.printStackTrace();
        fail("Should not have failed to validate a valid overlay config " + e.getMessage());
    }
}
Also used : OverlayManager(org.apache.maven.plugins.war.overlay.OverlayManager) DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) MavenProjectArtifactsStub(org.apache.maven.plugins.war.stub.MavenProjectArtifactsStub) ArrayList(java.util.ArrayList) ArtifactStub(org.apache.maven.plugin.testing.stubs.ArtifactStub) WarArtifactStub(org.apache.maven.plugins.war.stub.WarArtifactStub) Overlay(org.apache.maven.plugins.war.Overlay) DefaultOverlay(org.apache.maven.plugins.war.overlay.DefaultOverlay) InvalidOverlayConfigurationException(org.apache.maven.plugins.war.overlay.InvalidOverlayConfigurationException)

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