From 699c3d46cea89acd95de41a62c9f14cfe9a971f0 Mon Sep 17 00:00:00 2001 From: Ben Alex Date: Fri, 2 Apr 2004 11:51:08 +0000 Subject: [PATCH] Refactored into separate tests to support the two Contacts sample application WAR versions. --- .../web/ContactsWarTests.java | 279 ------------------ 1 file changed, 279 deletions(-) delete mode 100644 integration-test/src/net/sf/acegisecurity/integrationtests/web/ContactsWarTests.java diff --git a/integration-test/src/net/sf/acegisecurity/integrationtests/web/ContactsWarTests.java b/integration-test/src/net/sf/acegisecurity/integrationtests/web/ContactsWarTests.java deleted file mode 100644 index 1b13c7edf5..0000000000 --- a/integration-test/src/net/sf/acegisecurity/integrationtests/web/ContactsWarTests.java +++ /dev/null @@ -1,279 +0,0 @@ -/* Copyright 2004 Acegi Technology Pty Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package net.sf.acegisecurity.integrationtests.web; - -import com.meterware.httpunit.GetMethodWebRequest; -import com.meterware.httpunit.WebConversation; -import com.meterware.httpunit.WebForm; -import com.meterware.httpunit.WebLink; -import com.meterware.httpunit.WebRequest; -import com.meterware.httpunit.WebResponse; - -import junit.framework.TestCase; - -import java.net.URL; - - -/** - * Tests the Contacts sample application and container integration from a HTTP - * user's perspective. - * - *

- * NB: Assumes a default container configuration concerning the usernames and - * passwords in acegisecurity.xml. Also assumes default - * configuration in terms of password and username case sensitivity. - * Importantly, the Contacts application is expected to be started "clean", in - * that all default contacts data is present, without any additional data. - * This means it is necessary to restart the Contacts application between - * successive test runs. - *

- * - * @author Ben Alex - * @version $Id$ - */ -public class ContactsWarTests extends TestCase { - //~ Methods ================================================================ - - public final void setUp() throws Exception { - super.setUp(); - } - - public static void main(String[] args) { - junit.textui.TestRunner.run(ContactsWarTests.class); - } - - public void testHelloPageAccessible() throws Exception { - WebConversation conversation = new WebConversation(); - WebRequest request = new GetMethodWebRequest( - "http://localhost:8080/contacts"); - - WebResponse response = conversation.getResponse(request); - assertEquals("Contacts Security Demo", response.getTitle()); - assertEquals(2, response.getLinks().length); // debug and manage links - assertTrue(response.getText().lastIndexOf("sample.contact.Contact@") != -1); - } - - public void testLoginNameCaseSensitive() throws Exception { - WebConversation conversation = new WebConversation(); - WebRequest request = new GetMethodWebRequest( - "http://localhost:8080/contacts"); - - WebResponse helloPage = conversation.getResponse(request); - WebLink debugLink = helloPage.getLinkWith("Debug"); - WebResponse loginPage = debugLink.click(); - assertEquals(1, loginPage.getForms()[0].getSubmitButtons().length); - - WebForm loginForm = loginPage.getForms()[0]; - loginPage = null; - - loginForm.setParameter("j_username", "mArIsSA"); - loginForm.setParameter("j_password", "koala"); - - WebResponse loginOutcome = conversation.getResponse(loginForm - .getRequest("submit")); - - assertTrue(loginOutcome.getText().lastIndexOf("SUCCESS! Your container adapter appears to be properly configured!") != -1); - } - - public void testLoginPasswordCaseSensitive() throws Exception { - WebConversation conversation = new WebConversation(); - WebRequest request = new GetMethodWebRequest( - "http://localhost:8080/contacts"); - - WebResponse helloPage = conversation.getResponse(request); - WebLink debugLink = helloPage.getLinkWith("Debug"); - WebResponse loginPage = debugLink.click(); - assertEquals(1, loginPage.getForms()[0].getSubmitButtons().length); - - WebForm loginForm = loginPage.getForms()[0]; - loginPage = null; - - loginForm.setParameter("j_username", "dianne"); - loginForm.setParameter("j_password", "EmU"); - - WebResponse loginOutcome = conversation.getResponse(loginForm - .getRequest("submit")); - - assertEquals("Login", loginOutcome.getTitle()); - } - - public void testLoginSuccess() throws Exception { - WebConversation conversation = new WebConversation(); - WebRequest request = new GetMethodWebRequest( - "http://localhost:8080/contacts"); - - WebResponse helloPage = conversation.getResponse(request); - WebLink debugLink = helloPage.getLinkWith("Debug"); - WebResponse loginPage = debugLink.click(); - assertEquals(1, loginPage.getForms()[0].getSubmitButtons().length); - - WebForm loginForm = loginPage.getForms()[0]; - loginPage = null; - - loginForm.setParameter("j_username", "marissa"); - loginForm.setParameter("j_password", "koala"); - - WebResponse loginOutcome = conversation.getResponse(loginForm - .getRequest("submit")); - - assertTrue(loginOutcome.getText().lastIndexOf("SUCCESS! Your container adapter appears to be properly configured!") != -1); - } - - public void testLoginUnknownUsername() throws Exception { - WebConversation conversation = new WebConversation(); - WebRequest request = new GetMethodWebRequest( - "http://localhost:8080/contacts"); - - WebResponse helloPage = conversation.getResponse(request); - WebLink debugLink = helloPage.getLinkWith("Debug"); - WebResponse loginPage = debugLink.click(); - assertEquals(1, loginPage.getForms()[0].getSubmitButtons().length); - - WebForm loginForm = loginPage.getForms()[0]; - loginPage = null; - - loginForm.setParameter("j_username", "angella"); - loginForm.setParameter("j_password", "echidna"); - - WebResponse loginOutcome = conversation.getResponse(loginForm - .getRequest("submit")); - - assertEquals("Login", loginOutcome.getTitle()); - } - - public void testSessionAsMarissa() throws Exception { - WebConversation conversation = new WebConversation(); - WebRequest request = new GetMethodWebRequest( - "http://localhost:8080/contacts"); - - WebResponse helloPage = conversation.getResponse(request); - WebLink manageLink = helloPage.getLinkWith("Manage"); - WebResponse loginPage = manageLink.click(); - manageLink = null; - assertEquals(1, loginPage.getForms()[0].getSubmitButtons().length); - - WebForm loginForm = loginPage.getForms()[0]; - loginPage = null; - - loginForm.setParameter("j_username", "marissa"); - loginForm.setParameter("j_password", "koala"); - - WebResponse loginOutcome = conversation.getResponse(loginForm - .getRequest("submit")); - - assertEquals("Your Contacts", loginOutcome.getTitle()); - assertTrue(loginOutcome.getText().lastIndexOf("marissa's Contacts") != -1); - assertEquals(4, loginOutcome.getTables()[0].getRowCount()); // 3 contacts + header - assertEquals(5, loginOutcome.getLinks().length); // 3 contacts + add + logoff - - WebLink addLink = loginOutcome.getLinkWith("Add"); - loginOutcome = null; - - WebResponse addPage = addLink.click(); - WebForm addForm = addPage.getForms()[0]; - addPage = null; - - addForm.setParameter("name", ""); - addForm.setParameter("email", ""); - - WebResponse addOutcomeFail = conversation.getResponse(addForm - .getRequest("execute")); - - assertEquals(new URL("http://localhost:8080/contacts/secure/add.htm"), - addOutcomeFail.getURL()); - assertTrue(addOutcomeFail.getText().lastIndexOf("Please fix all errors!") != -1); - addOutcomeFail = null; - - addForm.setParameter("name", "somebody"); - addForm.setParameter("email", "them@somewhere.com"); - - WebResponse addOutcomeSuccess = conversation.getResponse(addForm - .getRequest("execute")); - - assertEquals("Your Contacts", addOutcomeSuccess.getTitle()); - assertTrue(addOutcomeSuccess.getText().lastIndexOf("marissa's Contacts") != -1); - assertEquals(5, addOutcomeSuccess.getTables()[0].getRowCount()); // 4 contacts + header - assertEquals(6, addOutcomeSuccess.getLinks().length); // 4 contacts + add + logoff - - WebLink logout = addOutcomeSuccess.getLinkWith("Logoff"); - addOutcomeSuccess = null; - - WebResponse loggedOut = logout.click(); - assertEquals("Contacts Security Demo", loggedOut.getTitle()); - - WebLink debugLink = loggedOut.getLinkWith("Debug"); - loggedOut = null; - - WebResponse loginAgainPage = debugLink.click(); - assertEquals("Login", loginAgainPage.getTitle()); - } - - public void testSessionAsScott() throws Exception { - WebConversation conversation = new WebConversation(); - WebRequest request = new GetMethodWebRequest( - "http://localhost:8080/contacts"); - - WebResponse helloPage = conversation.getResponse(request); - WebLink manageLink = helloPage.getLinkWith("Manage"); - WebResponse loginPage = manageLink.click(); - manageLink = null; - assertEquals(1, loginPage.getForms()[0].getSubmitButtons().length); - - WebForm loginForm = loginPage.getForms()[0]; - loginPage = null; - - loginForm.setParameter("j_username", "scott"); - loginForm.setParameter("j_password", "wombat"); - - WebResponse loginOutcome = conversation.getResponse(loginForm - .getRequest("submit")); - - assertEquals("Your Contacts", loginOutcome.getTitle()); - assertTrue(loginOutcome.getText().lastIndexOf("scott's Contacts") != -1); - assertEquals(3, loginOutcome.getTables()[0].getRowCount()); // 2 contacts + header - assertEquals(2, loginOutcome.getLinks().length); // add + logoff only - - WebLink addLink = loginOutcome.getLinkWith("Add"); - loginOutcome = null; - - WebResponse addPage = addLink.click(); - WebForm addForm = addPage.getForms()[0]; - addPage = null; - - addForm.setParameter("name", "somebody"); - addForm.setParameter("email", "them@somewhere.com"); - - WebResponse addOutcomeSuccess = conversation.getResponse(addForm - .getRequest("execute")); - - assertEquals("Your Contacts", addOutcomeSuccess.getTitle()); - assertTrue(addOutcomeSuccess.getText().lastIndexOf("scott's Contacts") != -1); - assertEquals(4, addOutcomeSuccess.getTables()[0].getRowCount()); // 3 contacts + header - assertEquals(2, addOutcomeSuccess.getLinks().length); // add + logoff only - - WebLink logout = addOutcomeSuccess.getLinkWith("Logoff"); - addOutcomeSuccess = null; - - WebResponse loggedOut = logout.click(); - assertEquals("Contacts Security Demo", loggedOut.getTitle()); - - WebLink debugLink = loggedOut.getLinkWith("Debug"); - loggedOut = null; - - WebResponse loginAgainPage = debugLink.click(); - assertEquals("Login", loginAgainPage.getTitle()); - } -}