001: /**
002: * EasyBeans
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id:EasyBeansManagedRuntime.java 1477 2007-06-16 16:50:19Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.assemblies.tomcat.test;
025:
026: import org.testng.Assert;
027: import org.testng.annotations.BeforeClass;
028: import org.testng.annotations.Test;
029:
030: import net.sourceforge.jwebunit.junit.WebTester;
031:
032: /**
033: * Test the Tomcat assembly.
034: * @author Florent Benoit
035: */
036: public class TomcatTest {
037:
038: /**
039: * Tester object.
040: */
041: private WebTester webTester;
042:
043: /**
044: * Initialize the test framework.
045: * @throws Exception if the framework is not initalized.
046: */
047: @BeforeClass
048: protected void init() throws Exception {
049:
050: // Build tester object
051: this .webTester = new WebTester();
052:
053: // Get the http port property
054: String httpPort = System.getProperty("http.port");
055:
056: if (httpPort == null) {
057: throw new Exception(
058: "Cannot get the http.port system property");
059: }
060:
061: this .webTester.getTestContext().setBaseUrl(
062: "http://localhost:" + httpPort + "/");
063: }
064:
065: /**
066: * Check that the EasyBeans war is available (and then deployed).
067: * @throws Exception if EasyBeans is not available
068: */
069: @Test
070: public void easyBeansAvailable() throws Exception {
071: webTester.beginAt("/ow2-easybeans");
072: webTester.getPageSource().contains("EasyBeans");
073: }
074:
075: /**
076: * Test if the EAR example is working.
077: */
078: @Test(dependsOnMethods="easyBeansAvailable")
079: public void testEarWebSample() {
080: webTester.beginAt("/ear-web");
081:
082: // Get content
083: String pageContent = webTester.getPageSource();
084:
085: // Check if authors Victor Hugo & Balzac are present
086: if (!pageContent.contains("Honore de Balzac")
087: || !pageContent.contains("Victor Hugo")) {
088: Assert.fail("Page '" + pageContent
089: + "' does not contain the authors !");
090: }
091:
092: // Some books available too ?
093: if (!pageContent.contains("Les Chouans")
094: || !pageContent.contains("Les Miserables")) {
095: Assert.fail("Page '" + pageContent
096: + "' does not contain the books !");
097: }
098:
099: }
100: }
|