[Lipog-commit] net.heilancoo.bingo.test/src/net/heilancoo/bingo/test BingoApp.java, NONE, 1.1
Status: Beta
Brought to you by:
jbu
From: Joerg B. <jb...@us...> - 2009-07-26 16:49:11
|
Update of /cvsroot/lipog/net.heilancoo.bingo.test/src/net/heilancoo/bingo/test In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv15438/src/net/heilancoo/bingo/test Added Files: BingoApp.java Log Message: web application test tutorial example --- NEW FILE: BingoApp.java --- /* * Copyright (c) 2009 Heilan' Coo -- Joerg Bullmann * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which is available at http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Joerg Bullmann <jb...@he...> */ package net.heilancoo.bingo.test; import static org.junit.Assert.assertEquals; import java.io.IOException; import java.net.MalformedURLException; import net.heilancoo.bingo.BingoSession; import net.heilancoo.portal.application.ApplicationException; import net.heilancoo.portal.session.SessionException; import net.heilancoo.portal.testutils.PortalTest; import org.junit.BeforeClass; import org.junit.Test; import com.gargoylesoftware.htmlunit.FailingHttpStatusCodeException; import com.gargoylesoftware.htmlunit.WebClient; import com.gargoylesoftware.htmlunit.html.HtmlForm; import com.gargoylesoftware.htmlunit.html.HtmlPage; /** * @author joerg * */ public class BingoApp { /** * @throws java.lang.Exception */ @BeforeClass public static void setUpBeforeClass() throws Exception { PortalTest.startPortal(500); } @Test public void doLoginTest() throws FailingHttpStatusCodeException, MalformedURLException, IOException, SessionException, ApplicationException { // =========================================================== // Log into the web application. This is client side activity. WebClient cl = new WebClient(); HtmlPage pg = cl.getPage("http://127.0.0.1:8080/bingo"); assertEquals("Login", pg.getTitleText()); HtmlForm login = pg.getFormByName("input"); login.getInputByName("user").setValueAttribute("joerg"); login.getInputByName("password").setValueAttribute("joerg"); HtmlPage loggedIn = login.getInputByName("button").click(); // ========================================================== // Now peep directly into the server side of the application: BingoSession s = (BingoSession) PortalTest.getSessionForPage(loggedIn); assertEquals(1, s.getAccessCounter()); // ===================================================== // Back on the client side. Continue with some activity. loggedIn.getAnchorByHref("main").click(); // ================================== // And again inspect the server side: assertEquals(2, s.getAccessCounter()); } } |