refactored some test methods,
authormaxcooper <maxcooper>
Sat, 14 Jun 2003 14:11:44 +0000 (14:11 +0000)
committermaxcooper <maxcooper>
Sat, 14 Jun 2003 14:11:44 +0000 (14:11 +0000)
added LogoutTest

src/test/org/securityfilter/test/http/TestBase.java
src/test/org/securityfilter/test/http/form/DefaultPageTest.java
src/test/org/securityfilter/test/http/form/JustInTimeTest.java
src/test/org/securityfilter/test/http/form/LogoutTest.java [new file with mode: 0644]

index c04bfea..a67cd15 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * $Header: /cvsroot/securityfilter/securityfilter/src/test/org/securityfilter/test/http/TestBase.java,v 1.4 2003/06/10 12:11:26 maxcooper Exp $
- * $Revision: 1.4 $
- * $Date: 2003/06/10 12:11:26 $
+ * $Header: /cvsroot/securityfilter/securityfilter/src/test/org/securityfilter/test/http/TestBase.java,v 1.5 2003/06/14 14:11:44 maxcooper Exp $
+ * $Revision: 1.5 $
+ * $Date: 2003/06/14 14:11:44 $
  *
  * ====================================================================
  * The SecurityFilter Software License, Version 1.1
@@ -63,11 +63,12 @@ import org.securityfilter.example.Constants;
  * TestBase
  *
  * @author Max Cooper (max@maxcooper.com)
- * @version $Revision: 1.4 $ $Date: 2003/06/10 12:11:26 $
+ * @version $Revision: 1.5 $ $Date: 2003/06/14 14:11:44 $
  */
 public class TestBase extends TestCase {
 
    protected String baseUrl;
+   protected WebConversation session;
 
    /**
     * Constructor
@@ -85,13 +86,8 @@ public class TestBase extends TestCase {
       baseUrl = System.getProperty("base.url");
       HttpUnitOptions.setExceptionsThrownOnErrorStatus(true);
       HttpUnitOptions.setMatchesIgnoreCase(true);
-   }
-
-   /**
-    * Assert that the baseUrl has been set
-    */
-   protected void assertBaseUrlIsSet() {
       assertNotNull("base.url is null", baseUrl);
+      session = new WebConversation();
    }
 
    /**
@@ -104,11 +100,7 @@ public class TestBase extends TestCase {
     * @throws Exception
     */
    protected WebResponse performJustInTimeLogin(String uri) throws Exception {
-      // make sure the baseUrl was set
-      assertBaseUrlIsSet();
-
       // request the secure page
-      WebConversation session = new WebConversation();
       WebRequest request = new GetMethodWebRequest(baseUrl + uri);
       WebResponse response = session.getResponse(request);
 
index e3ad1fb..f23d14a 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * $Header: /cvsroot/securityfilter/securityfilter/src/test/org/securityfilter/test/http/form/DefaultPageTest.java,v 1.2 2003/06/10 12:11:26 maxcooper Exp $
- * $Revision: 1.2 $
- * $Date: 2003/06/10 12:11:26 $
+ * $Header: /cvsroot/securityfilter/securityfilter/src/test/org/securityfilter/test/http/form/DefaultPageTest.java,v 1.3 2003/06/14 14:11:44 maxcooper Exp $
+ * $Revision: 1.3 $
+ * $Date: 2003/06/14 14:11:44 $
  *
  * ====================================================================
  * The SecurityFilter Software License, Version 1.1
 
 package org.securityfilter.test.http.form;
 
-import org.securityfilter.test.http.TestBase;
-import org.securityfilter.example.Constants;
 import com.meterware.httpunit.*;
+import org.securityfilter.example.Constants;
+import org.securityfilter.test.http.TestBase;
 
 /**
  * DefaultPageTest
  *
  * @author Max Cooper (max@maxcooper.com)
- * @version $Revision: 1.2 $ $Date: 2003/06/10 12:11:26 $
+ * @version $Revision: 1.3 $ $Date: 2003/06/14 14:11:44 $
  */
 public class DefaultPageTest extends TestBase {
-
    /**
     * Constructor
     *
@@ -89,9 +88,6 @@ public class DefaultPageTest extends TestBase {
     * @throws Exception
     */
    public void testDefaultPageAfterLoginPage() throws Exception {
-      // make sure the baseUrl was set
-      assertBaseUrlIsSet();
-
       // request the login page
       WebConversation session = new WebConversation();
       WebRequest request = new GetMethodWebRequest(baseUrl + "/loginForm.jsp");
@@ -121,9 +117,6 @@ public class DefaultPageTest extends TestBase {
     * @throws Exception
     */
    public void testDefaultPageAfterSpontaneousLogin() throws Exception {
-      // make sure the baseUrl was set
-      assertBaseUrlIsSet();
-
       // submit valid login credentials
       WebConversation session = new WebConversation();
       WebRequest request = new PostMethodWebRequest(baseUrl + "/j_security_check");
index 84286d5..0099135 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * $Header: /cvsroot/securityfilter/securityfilter/src/test/org/securityfilter/test/http/form/JustInTimeTest.java,v 1.5 2003/06/10 12:11:26 maxcooper Exp $
- * $Revision: 1.5 $
- * $Date: 2003/06/10 12:11:26 $
+ * $Header: /cvsroot/securityfilter/securityfilter/src/test/org/securityfilter/test/http/form/JustInTimeTest.java,v 1.6 2003/06/14 14:11:44 maxcooper Exp $
+ * $Revision: 1.6 $
+ * $Date: 2003/06/14 14:11:44 $
  *
  * ====================================================================
  * The SecurityFilter Software License, Version 1.1
 
 package org.securityfilter.test.http.form;
 
-import com.meterware.httpunit.*;
 import org.securityfilter.example.Constants;
 import org.securityfilter.test.http.TestBase;
 
 /**
- * JustInTimeTest - This tests basic just-in-time login behavior.
+ * JustInTimeTest - This tests normal just-in-time login behavior.
  *
  * @author Max Cooper (max@maxcooper.com)
- * @version $Revision: 1.5 $ $Date: 2003/06/10 12:11:26 $
+ * @version $Revision: 1.6 $ $Date: 2003/06/14 14:11:44 $
  */
 public class JustInTimeTest extends TestBase {
    /**
@@ -76,7 +75,7 @@ public class JustInTimeTest extends TestBase {
    }
 
    /**
-    * Test that the user is asked to login before accessing /securePage.jsp.
+    * Test that the user is asked to loging before accessing /securePage.jsp.
     *
     * @throws Exception
     */
diff --git a/src/test/org/securityfilter/test/http/form/LogoutTest.java b/src/test/org/securityfilter/test/http/form/LogoutTest.java
new file mode 100644 (file)
index 0000000..27f8040
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * $Header: /cvsroot/securityfilter/securityfilter/src/test/org/securityfilter/test/http/form/LogoutTest.java,v 1.1 2003/06/14 14:11:44 maxcooper Exp $
+ * $Revision: 1.1 $
+ * $Date: 2003/06/14 14:11:44 $
+ *
+ * ====================================================================
+ * The SecurityFilter Software License, Version 1.1
+ *
+ * (this license is derived and fully compatible with the Apache Software
+ * License - see http://www.apache.org/LICENSE.txt)
+ *
+ * Copyright (c) 2002 SecurityFilter.org. 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
+ *        SecurityFilter.org (http://www.securityfilter.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ *
+ * 4. The name "SecurityFilter" must not be used to endorse or promote
+ *    products derived from this software without prior written permission.
+ *    For written permission, please contact license@securityfilter.org .
+ *
+ * 5. Products derived from this software may not be called "SecurityFilter",
+ *    nor may "SecurityFilter" appear in their name, without prior written
+ *    permission of SecurityFilter.org.
+ *
+ * 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 SECURITY FILTER PROJECT 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.
+ * ====================================================================
+ */
+
+package org.securityfilter.test.http.form;
+
+import com.meterware.httpunit.GetMethodWebRequest;
+import com.meterware.httpunit.WebRequest;
+import com.meterware.httpunit.WebResponse;
+import org.securityfilter.example.Constants;
+import org.securityfilter.test.http.TestBase;
+
+/**
+ * LogoutTest - tests the logout functionality.
+ *
+ * @author Max Cooper (max@maxcooper.com)
+ * @version $Revision: 1.1 $ $Date: 2003/06/14 14:11:44 $
+ */
+public class LogoutTest extends TestBase {
+   /**
+    * Constructor
+    *
+    * @param name
+    */
+   public LogoutTest(String name) {
+      super(name);
+   }
+
+   /**
+    * Test that the user is asked to login before accessing /securePage.jsp.
+    *
+    * @throws Exception
+    */
+   public void testLogout() throws Exception {
+      // ensure that we get the secure page, loggin in on the way
+      assertPageTitleAfterLogin("/securePage.jsp", Constants.SECURE_TITLE);
+
+      // logout
+      WebRequest request = new GetMethodWebRequest(baseUrl + "/logout.jsp");
+      WebResponse response = session.getResponse(request);
+      assertPageTitle(response, Constants.LOGOUT_TITLE);
+
+      // ensure that we get the secure page, loggin in on the way
+      assertPageTitleAfterLogin("/securePage.jsp", Constants.SECURE_TITLE);
+   }
+}