jvanzyl 2002/07/14 16:44:51
Added: src/plugins-build/j2ee/src/test/java/org/apache/maven/j2ee
ValidationBroadcasterTest.java
ValidationEventTest.java
ValidationStatusListenerTest.java WarFileTest.java
WarValidatorTest.java
src/plugins-build/j2ee/src/test/java/org/apache/maven/j2ee/war
FormLoginConfigTest.java
Log:
o move to plugin
Revision Changes Path
1.1
jakarta-turbine-maven/src/plugins-build/j2ee/src/test/java/org/apache/maven/j2ee/ValidationBroadcasterTest.java
Index: ValidationBroadcasterTest.java
===================================================================
package org.apache.maven.j2ee;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import junit.framework.TestCase;
/**
* Test cases for the {@link ValidationBroadcaster}
*
* @author <a href="mailto:[EMAIL PROTECTED]">dIon Gillard</a>
* @version $Id: ValidationBroadcasterTest.java,v 1.1 2002/07/14 23:44:51 jvanzyl
Exp $
*/
public class ValidationBroadcasterTest extends TestCase
{
/** instance for unit testing */
private ValidationBroadcaster instance;
/** listener used to check status/events firing */
private ValidationStatusListener status;
/**
* Creates a new instance of ValidationBroadcasterTest
* @param testName the name of the test
*/
public ValidationBroadcasterTest(String testName)
{
super(testName);
}
/**
* Initialize per test data
* @throws Exception when there is an unexpected problem
*/
public void setUp() throws Exception
{
setInstance(new ValidationBroadcaster());
setStatus(new ValidationStatusListener());
getInstance().addValidationListener(getStatus());
}
/**
* test that the fireStartedEvent method works
* @throws Exception when there is an unexpected problem
*/
public void testStartedBroadcast() throws Exception
{
assertTrue("status was started before starting",
!getStatus().isStarted());
getInstance().fireStartedEvent(new ValidationEvent(this));
assertTrue("status was not started after broadcast",
getStatus().isStarted());
}
/**
* test that the fireErrorEvent method works
* @throws Exception when there is an unexpected problem
*/
public void testErrorBroadcast() throws Exception
{
assertTrue("status was error before starting",
!getStatus().isError());
getInstance().fireErrorEvent(new ValidationEvent(this));
assertTrue("status was not error after broadcast",
getStatus().isError());
}
/**
* test that the fireErrorEvent method works
* @throws Exception when there is an unexpected problem
*/
public void testWarningBroadcast() throws Exception
{
assertTrue("status was warning before starting",
!getStatus().isWarning());
getInstance().fireWarningEvent(new ValidationEvent(this));
assertTrue("status was not warning after broadcast",
getStatus().isWarning());
}
/**
* test that the fireEndedEvent method works
* @throws Exception when there is an unexpected problem
*/
public void testEndedBroadcast() throws Exception
{
assertTrue("status was ended before starting",
!getStatus().isEnded());
getInstance().fireEndedEvent(new ValidationEvent(this));
assertTrue("status was not ended after broadcast",
getStatus().isEnded());
}
/**
* test that the removeValidationListeners method works
* @throws Exception when there is an unexpected problem
*/
public void testRemoveListener() throws Exception
{
assertTrue("status was started before starting",
!getStatus().isStarted());
getInstance().removeValidationListener(getStatus());
getInstance().fireStartedEvent(new ValidationEvent(this));
assertTrue("event received after removing", !getStatus().isStarted());
}
/** Getter for property instance.
* @return Value of property instance.
*/
private ValidationBroadcaster getInstance()
{
return instance;
}
/** Setter for property instance.
* @param instance New value of property instance.
*/
private void setInstance(ValidationBroadcaster instance)
{
this.instance = instance;
}
/** Getter for property status.
* @return Value of property status.
*/
private ValidationStatusListener getStatus()
{
return status;
}
/** Setter for property status.
* @param status New value of property status.
*/
private void setStatus(ValidationStatusListener status)
{
this.status = status;
}
}
1.1
jakarta-turbine-maven/src/plugins-build/j2ee/src/test/java/org/apache/maven/j2ee/ValidationEventTest.java
Index: ValidationEventTest.java
===================================================================
package org.apache.maven.j2ee;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import junit.framework.TestCase;
/**
* Unit test for <code>ValidationEvent</code>.
*
* @author <a href="mailto:[EMAIL PROTECTED]">dIon Gillard</a>
* @version $Id: ValidationEventTest.java,v 1.1 2002/07/14 23:44:51 jvanzyl Exp $
*/
public class ValidationEventTest extends TestCase
{
/** instance to be used for testing */
private ValidationEvent event;
/**
* Creates a new instance of ValidationEventTest
* @param testName the name of the test
*/
public ValidationEventTest(String testName)
{
super(testName);
}
/** Tests for the constructor, and as a by product, all get methods
* @throws Exception if any error occurs
*/
public void testConstructor() throws Exception
{
Object dummySource = this;
event = new ValidationEvent(this);
assertSame("Source returned is not the same as the one provided",
this, event.getSource());
assertNull("Message is not null", event.getMessage());
assertNull("Subject is not null", event.getSubject());
String dummySubject = "dummySubject";
String dummyMessage = "dummyMessage";
event = new ValidationEvent(dummySource, dummySubject, dummyMessage);
assertSame("Source returned is not the same as the one provided",
this, event.getSource());
assertSame("Subject returned is not the same as the one provided",
dummySubject, event.getSubject());
assertSame("Message returned is not the same as the one provided",
dummyMessage, event.getMessage());
}
/** Tests for the setMessage
* @throws Exception if any error occurs
*/
public void testSetMessage() throws Exception
{
event = new ValidationEvent(this);
String dummyMessage = "message";
event.setMessage(dummyMessage);
assertSame("Message set is not the same as the one from get",
dummyMessage, event.getMessage());
}
/** Tests for the setSubject
* @throws Exception if any error occurs
*/
public void testSetSubject() throws Exception
{
event = new ValidationEvent(this);
String dummySubject = "subject";
event.setSubject(dummySubject);
assertSame("Subject set is not the same as the one from get",
dummySubject, event.getSubject());
}
}
1.1
jakarta-turbine-maven/src/plugins-build/j2ee/src/test/java/org/apache/maven/j2ee/ValidationStatusListenerTest.java
Index: ValidationStatusListenerTest.java
===================================================================
package org.apache.maven.j2ee;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import junit.framework.TestCase;
/**
* Unit test for {@link ValidationStatusListener}.
*
* @author <a href="mailto:[EMAIL PROTECTED]">dIon Gillard</a>
* @version $Id: ValidationStatusListenerTest.java,v 1.1 2002/07/14 23:44:51 jvanzyl
Exp $
*/
public class ValidationStatusListenerTest extends TestCase
{
/** instance used for testing */
private ValidationStatusListener instance;
/**
* Creates a new instance of ValidationStatusListenerTest
* @param testName the name of the test
*/
public ValidationStatusListenerTest(String testName)
{
super(testName);
}
/**
* test that the zero arg constructor works
* @throws Exception when there is an unexpected problem
*/
public void testDefaultConstructor() throws Exception
{
instance = new ValidationStatusListener();
assertNotNull("Constructor hasn't returned a value", instance);
assertEquals("started property isn't false", false,
instance.isStarted());
assertEquals("error property isn't false", false, instance.isError());
assertEquals("warning property isn't false", false,
instance.isWarning());
assertEquals("ended property isn't false", false, instance.isEnded());
}
/**
* test that the listener handles validation started events correctly
* @throws Exception when there is an unexpected problem
*/
public void testStarted() throws Exception
{
instance = new ValidationStatusListener();
instance.validationStarted(new ValidationEvent(this));
assertTrue("started property is not being set", instance.isStarted());
}
/**
* test that the listener handles validation error events correctly
* @throws Exception when there is an unexpected problem
*/
public void testError() throws Exception
{
testStarted();
instance.validationError(new ValidationEvent(this));
assertTrue("error property is not being set", instance.isError());
}
/**
* test that the listener handles validation warning events correctly
* @throws Exception when there is an unexpected problem
*/
public void testWarning() throws Exception
{
testStarted();
instance.validationWarning(new ValidationEvent(this));
assertTrue("warning property is not being set", instance.isWarning());
}
/**
* test that the listener handles validation ended events correctly
* @throws Exception when there is an unexpected problem
*/
public void testEnded() throws Exception
{
testStarted();
instance.validationEnded(new ValidationEvent(this));
assertTrue("ended property is not being set", instance.isEnded());
}
}
1.1
jakarta-turbine-maven/src/plugins-build/j2ee/src/test/java/org/apache/maven/j2ee/WarFileTest.java
Index: WarFileTest.java
===================================================================
package org.apache.maven.j2ee;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.jar.JarEntry;
import junit.framework.TestCase;
import org.apache.maven.TestConstantsTest;
/**
* Unit test for {@link WarFile}.
*
* @author <a href="mailto:[EMAIL PROTECTED]">dIon Gillard</a>
* @version $Id: WarFileTest.java,v 1.1 2002/07/14 23:44:51 jvanzyl Exp $
*/
public class WarFileTest extends TestCase
{
/** instance used for testing */
private WarFile instance;
/** file name for the empty war used during testing */
private String emptyWarFile;
/** file name for manifest-only war used during testing */
private String manifestOnlyWarFile;
/** file name for simple war (manifest & web.xml) used during testing */
private String simpleWarFile;
/** file name for dummy war (two dummy servlets) */
private String dummyWarFile;
/** file name for dummy jsp war (dummy war + a jsp-file entry) */
private String dummyJspWarFile;
/** file name for dummy taglib war (dummy war + 2 taglibs) */
private String dummyTaglibWarFile;
/** file name for error pages war (dummy war + 2 error pages) */
private String errorPagesWarFile;
/** file name for form login config war (dummy war + login config) */
private String loginPagesWarFile;
/** Creates a new instance of WarFileTest
* @param testName the name of the test
*/
public WarFileTest(String testName)
{
super(testName);
}
/**
* Initialize per test data
* @throws Exception when there is an unexpected problem
*/
public void setUp() throws Exception
{
String baseDir = System.getProperty("basedir");
assertNotNull("The system property basedir was not defined.", baseDir);
emptyWarFile = baseDir + TestConstantsTest.J2EE_DIR + "empty.war";
manifestOnlyWarFile = baseDir + TestConstantsTest.J2EE_DIR +
"manifest-only.war";
simpleWarFile = baseDir + TestConstantsTest.J2EE_DIR + "simple.war";
dummyWarFile = baseDir + TestConstantsTest.J2EE_DIR + "dummy-servlet.war";
dummyJspWarFile = baseDir + TestConstantsTest.J2EE_DIR + "dummy-jsp.war";
dummyTaglibWarFile = baseDir + TestConstantsTest.J2EE_DIR +
"dummy-taglib.war";
errorPagesWarFile = baseDir + TestConstantsTest.J2EE_DIR + "error-pages.war";
loginPagesWarFile = baseDir + TestConstantsTest.J2EE_DIR + "login-pages.war";
}
/**
* test that an empty war file produces an error
* @throws Exception when there is an unexpected problem
*/
public void testEmptyWar() throws Exception
{
try
{
instance = new WarFile(emptyWarFile);
fail("Empty war file (with no META-INF, or WEB-INF/web.xml) has" +
" succeeded");
}
catch (IOException ioe)
{
// this is the expected behaviour
}
}
/** test that a manifest only war (no web.xml) returns null for the web.xml!
* @throws Exception when there is an unexpected problem
*/
public void testManifestOnlyWar() throws Exception
{
instance = new WarFile(manifestOnlyWarFile);
assertNull("web.xml for manifest only war is not null",
instance.getWebXmlEntry());
}
/** test that a simple war (web.xml + manifest) returns an entry for web.xml
* test that a simple war returns zero servlets
* @throws Exception when there is an unexpected problem
*/
public void testSimpleWar() throws Exception
{
instance = new WarFile(simpleWarFile);
assertNotNull("web.xml for simple war is null",
instance.getWebXmlEntry());
assertEquals("number of servlets for simple war is not zero", 0,
instance.getServlets().size());
}
/** test that the dummy war returns two servlets
* @throws Exception when there is an unexpected problem
*/
public void testDummyWarServlets() throws Exception
{
instance = new WarFile(dummyWarFile);
assertEquals("number of servlets for dummy war is not two", 2,
instance.getServlets().size());
assertTrue("servlet list doesn't contain 'dummy servlet'",
instance.getServlets().keySet().contains("dummy servlet"));
assertTrue("servlet list doesn't contain 'dummy number 2'",
instance.getServlets().keySet().contains("dummy number 2"));
assertTrue("servlet list doesn't contain HttpServlet",
instance.getServlets().containsValue(
"javax.servlet.http.HttpServlet"));
assertTrue("servlet list doesn't contain Servlet",
instance.getServlets().containsValue(
"java.servlet.Servlet"));
}
/** test the getLibEntries method
* @throws Exception when there is an unexpected problem
*/
public void testDummyWarLib() throws Exception
{
instance = new WarFile(dummyWarFile);
assertEquals("number of lib entries for dummy war is not two", 2,
instance.getLibEntries().size());
JarEntry entry = null;
List list = new ArrayList();
for (Iterator entries = instance.getLibEntries().iterator();
entries.hasNext();)
{
entry = (JarEntry) entries.next();
list.add(entry.getName());
}
Collections.sort(list);
assertEquals("First entry is a.jar", "WEB-INF/lib/a.jar",
list.get(0));
assertEquals("Second entry is b.jar", "WEB-INF/lib/b.jar",
list.get(1));
}
/** test the file extraction
* @throws Exception when there is an unexpected problem
*/
public void testDummyWarExtract() throws Exception
{
instance = new WarFile(dummyWarFile);
Set libs = instance.getLibEntries();
File[] files = new File[libs.size()];
JarEntry entry = null;
int i = 0;
for (Iterator entries = instance.getLibEntries().iterator();
entries.hasNext();)
{
entry = (JarEntry) entries.next();
files[i] = instance.extract(entry);
assertTrue("Extracted file " + files[i].getAbsolutePath() +
" doesn't exist", files[i].exists());
i++;
}
}
/** test that the dummy jsp war returns two servlets
* @throws Exception when there is an unexpected problem
*/
public void testDummyJspWar() throws Exception
{
instance = new WarFile(dummyJspWarFile);
assertEquals("Number of jsps is wrong", 1,
instance.getJSPs().size());
assertTrue("List of jsps doesn't contain /a.jsp",
instance.getJSPs().values().contains("/a.jsp"));
assertEquals("Number of taglibs is wrong", 0,
instance.getTaglibs().size());
}
/** test that the dummy taglib war returns two taglibs
* @throws Exception when there is an unexpected problem
*/
public void testDummyTaglibWar() throws Exception
{
instance = new WarFile(dummyTaglibWarFile);
assertEquals("Number of taglibs is wrong", 2,
instance.getTaglibs().size());
assertEquals("Number of error pages is wrong", 0,
instance.getErrorPages().size());
assertNull("Form Login Config isn't null",
instance.getFormLoginConfig());
assertTrue("List of taglibs doesn't contain /WEB-INF/a.tld",
instance.getTaglibs().values().contains("/WEB-INF/a.tld"));
assertTrue("List of taglibs doesn't contain /WEB-INF/b.tld",
instance.getTaglibs().values().contains("/WEB-INF/b.tld"));
}
/** test the error pages war contains 2 error pages
* @throws Exception when there is an unexpected problem
*/
public void testErrorPagesWar() throws Exception
{
instance = new WarFile(errorPagesWarFile);
assertEquals("Number of error pages is wrong", 2,
instance.getErrorPages().size());
assertTrue("Error page list doesn't contain error.jsp",
instance.getErrorPages().values().contains("/error.jsp"));
assertTrue("Error page list doesn't contain error404.jsp",
instance.getErrorPages().values().contains("/error404.jsp"));
}
/** test the login pages war contains a form login config object with the
* login and error pages set
* @throws Exception when there is an unexpected problem
*/
public void testLoginPagesWar() throws Exception
{
instance = new WarFile(loginPagesWarFile);
assertNotNull("Form login config is null",
instance.getFormLoginConfig());
assertEquals("Login page is not /login.html",
"/login.html", instance.getFormLoginConfig().getLoginPage());
assertEquals("Error page is not /error.jsp",
"/error.jsp", instance.getFormLoginConfig().getErrorPage());
}
/** test the servlet mappings comes back with the correct entries
* @throws Exception when there is an unexpected problem
*/
public void testServletMappings() throws Exception
{
instance = new WarFile(dummyWarFile);
assertEquals("# of servlet mappings for dummy war file is wrong", 2,
instance.getServletMappings().size());
instance = new WarFile(loginPagesWarFile);
assertEquals("# of servlet mappings in login pages war is wrong", 0,
instance.getServletMappings().size());
}
}
1.1
jakarta-turbine-maven/src/plugins-build/j2ee/src/test/java/org/apache/maven/j2ee/WarValidatorTest.java
Index: WarValidatorTest.java
===================================================================
package org.apache.maven.j2ee;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import junit.framework.TestCase;
import org.apache.tools.ant.BuildException;
import org.apache.maven.TestConstantsTest;
/**
* Unit test for <code>WarValidator</code>.
*
* @author <a href="mailto:[EMAIL PROTECTED]">dIon Gillard</a>
* @version $Id: WarValidatorTest.java,v 1.1 2002/07/14 23:44:51 jvanzyl Exp $
*/
public class WarValidatorTest extends TestCase
{
/** the validator being tested */
private WarValidator validator = null;
/** file name for the empty war*/
private String emptyWarFile = null;
/** file name for manifest-only war */
private String manifestOnlyWarFile = null;
/** file name for simple war (manifest & web.xml)*/
private String simpleWarFile = null;
/** file name for dummy war */
private String dummyWarFile = null;
/** file name for dummy jsp war (dummy war + a jsp-file entry) */
private String dummyJspWarFile;
/** file name for dummy taglib war (dummy war + 2 taglibs) */
private String dummyTaglibWarFile;
/** file name for error pages war (dummy war + 2 error pages) */
private String errorPagesWarFile;
/** file name for form login config war (dummy war + login config) */
private String loginPagesWarFile;
/**
* Creates a new instance of WarValidatorTest
* @param testName the name of the test
*/
public WarValidatorTest(String testName)
{
super(testName);
}
/**
* Initialize per test data
* @throws Exception when there is an unexpected problem
*/
public void setUp() throws Exception
{
validator = new WarValidator();
String baseDir = System.getProperty("basedir");
assertNotNull("The system property basedir was not defined.", baseDir);
emptyWarFile = baseDir + TestConstantsTest.J2EE_DIR + "empty.war";
manifestOnlyWarFile = baseDir + TestConstantsTest.J2EE_DIR +
"manifest-only.war";
simpleWarFile = baseDir + TestConstantsTest.J2EE_DIR + "simple.war";
dummyWarFile = baseDir + TestConstantsTest.J2EE_DIR + "dummy-servlet.war";
dummyJspWarFile = baseDir + TestConstantsTest.J2EE_DIR + "dummy-jsp.war";
dummyTaglibWarFile = baseDir + TestConstantsTest.J2EE_DIR +
"dummy-taglib.war";
errorPagesWarFile = baseDir + TestConstantsTest.J2EE_DIR + "error-pages.war";
loginPagesWarFile = baseDir + TestConstantsTest.J2EE_DIR + "login-pages.war";
}
/**
* test that the warFileName property is mandatory for validation
* @throws Exception when there is an unexpected problem
*/
public void testWarFileMandatory() throws Exception
{
try
{
validator.execute();
fail("war validator executed without a war file");
}
catch (NullPointerException e)
{
// this is the expected behaviour
}
}
/**
* test that an empty war file produces an error
* @throws Exception when there is an unexpected problem
*/
public void testEmptyWar() throws Exception
{
try
{
validator.setFailOnError(true);
validator.setWarFileName(emptyWarFile);
validator.addFormatter(new ValidationFormatter());
validator.execute();
fail("Empty war file (with no META-INF, or WEB-INF/web.xml) has" +
" succeeded");
}
catch (BuildException be)
{
// this is the expected behaviour
}
}
/**
* test that the failOnError property when set to false doesn't throw
* an exception.
* @throws Exception when there is an unexpected problem
*/
public void testFailOnError() throws Exception
{
try
{
validator.setFailOnError(false);
validator.setWarFileName(emptyWarFile);
validator.addFormatter(new ValidationFormatter());
validator.execute();
assertTrue("Error not fired for an empty war file " +
"(with no META-INF, or WEB-INF/web.xml)",
validator.getStatus().isError());
}
catch (BuildException be)
{
fail("Empty war file (with no META-INF, or WEB-INF/web.xml) failed"
+ " the build process with failOnError=false");
}
}
/**
* test that a manifest only war file produces a warning
* @throws Exception when there is an unexpected problem
*/
public void testManifestOnlyWar() throws Exception
{
validator.setWarFileName(manifestOnlyWarFile);
validator.addFormatter(new ValidationFormatter());
validator.execute();
assertTrue("Manifest only war file (with no WEB-INF/web.xml) has" +
" succeeded without a warning", validator.getStatus().isWarning());
}
/**
* test that a simple war (MANIFEST and web.xml) file produces no warning
* @throws Exception when there is an unexpected problem
*/
public void testSimpleWar() throws Exception
{
validator.setWarFileName(simpleWarFile);
validator.addFormatter(new ValidationFormatter());
validator.execute();
assertTrue("Simple war file has generated a warning",
!validator.getStatus().isWarning());
assertTrue("Simple war file has generated an error",
!validator.getStatus().isError());
}
/**
* test that a dummy war file produces no warning and an error
* (as there is an intentionally bad class (java.servlet.Servlet) in
* web.xml)
* @throws Exception when there is an unexpected problem
*/
public void testDummyWar() throws Exception
{
validator.setWarFileName(dummyWarFile);
validator.addFormatter(new ValidationFormatter());
validator.setFailOnError(false);
validator.execute();
assertTrue("Dummy war file has generated a warning",
!validator.getStatus().isWarning());
assertTrue("Dummy war file has not generated an error",
validator.getStatus().isError());
}
/**
*/
public void testDummyJspWar() throws Exception
{
}
}
1.1
jakarta-turbine-maven/src/plugins-build/j2ee/src/test/java/org/apache/maven/j2ee/war/FormLoginConfigTest.java
Index: FormLoginConfigTest.java
===================================================================
package org.apache.maven.j2ee.war;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import junit.framework.TestCase;
/**
* Unit tests for {@link FormLoginConfig}
*
* @author dion
* @version $Id: FormLoginConfigTest.java,v 1.1 2002/07/14 23:44:51 jvanzyl Exp $
*/
public class FormLoginConfigTest extends TestCase
{
/** Creates a new instance of FormLoginConfigTest
* @param testName the name of the test
*/
public FormLoginConfigTest(String testName)
{
super(testName);
}
/** Test the constructor succeeds and that both properties are null */
public void testDefaultConstructor()
{
FormLoginConfig instance = new FormLoginConfig();
assertNull("loginPage is not null", instance.getLoginPage());
assertNull("errorPage is not null", instance.getErrorPage());
}
/** Test the constructor succeeds and that both properties are set correctly
*/
public void testConstructor()
{
String loginPage = "lPage";
String errorPage = "ePage";
FormLoginConfig instance = new FormLoginConfig(loginPage, errorPage);
assertEquals("loginPage was not set", loginPage, instance.getLoginPage());
assertEquals("errorPage was not set", errorPage, instance.getErrorPage());
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>