9N/A/*
9N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
9N/A *
9N/A * Copyright (c) 1997-2010 Oracle and/or its affiliates. All rights reserved.
9N/A *
9N/A * The contents of this file are subject to the terms of either the GNU
9N/A * General Public License Version 2 only ("GPL") or the Common Development
9N/A * and Distribution License("CDDL") (collectively, the "License"). You
9N/A * may not use this file except in compliance with the License. You can
9N/A * obtain a copy of the License at
9N/A * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
9N/A * or packager/legal/LICENSE.txt. See the License for the specific
9N/A * language governing permissions and limitations under the License.
9N/A *
9N/A * When distributing the software, include this License Header Notice in each
9N/A * file and include the License file at packager/legal/LICENSE.txt.
9N/A *
9N/A * GPL Classpath Exception:
9N/A * Oracle designates this particular file as subject to the "Classpath"
9N/A * exception as provided by Oracle in the GPL Version 2 section of the License
5680N/A * file that accompanied this code.
5680N/A *
5506N/A * Modifications:
9N/A * If applicable, add the following below the License Header, with the fields
9N/A * enclosed by brackets [] replaced by your own identifying information:
9N/A * "Portions Copyright [year] [name of copyright owner]"
9N/A *
814N/A * Contributor(s):
5567N/A * If you wish your version of this file to be governed by only the CDDL or
814N/A * only the GPL Version 2, indicate your decision by adding "[Contributor]
814N/A * elects to include this software in this distribution under the [CDDL or GPL
814N/A * Version 2] license." If you don't indicate a single choice of license, a
814N/A * recipient has the option to distribute your version of this file under
814N/A * either the CDDL, the GPL Version 2 or to extend the choice of license to
814N/A * its licensees as provided above. However, if you add GPL Version 2 code
1845N/A * and therefore, elected the GPL Version 2 license, then the option applies
7102N/A * only if the new code is made subject to such option by the copyright
1845N/A * holder.
1845N/A */
1845N/A
1845N/Apackage test.web.strutsbasic;
1845N/A
3441N/Aimport org.testng.annotations.Configuration;
3441N/Aimport org.testng.annotations.ExpectedExceptions;
1845N/Aimport org.testng.annotations.Test;
1845N/Aimport org.testng.annotations.*;
1845N/Aimport org.testng.Assert;
814N/A
7102N/Aimport java.io.*;
7102N/Aimport java.net.*;
7102N/Aimport java.util.*;
7102N/A
7102N/A
7102N/Apublic class StrutsWebTestNG {
7102N/A
7102N/A private static final String TEST_NAME =
7102N/A "struts-webapp";
7102N/A
7102N/A private static final String EXPECTED_RESPONSE =
7102N/A "JSP Page Test";
814N/A
1470N/A private String strContextRoot="strutsbasic";
1470N/A
1470N/A static String result = "";
1470N/A String m_host="";
1470N/A String m_port="";
1470N/A String host=System.getProperty("http.host");
1470N/A String port=System.getProperty("http.port");
16N/A
16N/A //@Parameters({"host","port"})
16N/A @BeforeMethod
16N/A //public void beforeTest(String httpHost,String httpPort){
16N/A public void beforeTest(){
1470N/A m_host=System.getProperty("http.host");
9N/A m_port=System.getProperty("http.port");
16N/A System.out.println("Host is-->"+m_host);
1470N/A System.out.println("Port is-->"+m_port);
16N/A }
16N/A
1470N/A /*
1470N/A *If two asserts are mentioned in one method, then last assert is taken in
16N/A *to account.
16N/A *Each method can act as one test within one test suite
1470N/A */
5506N/A
6130N/A
@Test(groups ={ "pulse"} ) // test method
//public void webtest(String host, String port, String contextroot) throws Exception{
public void strutsAppDeployedtest() throws Exception{
try{
String testurl = "http://" + m_host + ":" + m_port + "/"+ strContextRoot + "/index.jsp";
System.out.println("URL is: "+testurl);
URL url = new URL(testurl);
echo("Connecting to: " + url.toString());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.connect();
int responseCode = conn.getResponseCode();
InputStream is = conn.getInputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(is));
String line = null;
boolean result=false;
String testLine = null;
while ((line = input.readLine()) != null) {
if(line.indexOf("Struts Welcome Page")!=-1){
result=true;
testLine = line;
System.out.println(testLine);
}
}
Assert.assertEquals(result, true,"Unexpected HTML");
}catch(Exception e){
e.printStackTrace();
throw new Exception(e);
}
}
@Test(groups ={ "pulse"} ) // test method
public void strutsBasicHTMLTest() throws Exception{
try{
String testurl = "http://" + m_host + ":" + m_port + "/"+ strContextRoot + "/Welcome.do";
System.out.println("URL is: "+testurl);
URL url = new URL(testurl);
echo("Connecting to: " + url.toString());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.connect();
int responseCode = conn.getResponseCode();
InputStream is = conn.getInputStream();
BufferedReader input = new BufferedReader(new InputStreamReader(is));
String line = null;
boolean result=false;
String testLine = null;
while ((line = input.readLine()) != null) {
if(line.indexOf("Struts Applications in Netbeans!")!=-1){
result=true;
testLine = line;
System.out.println(testLine);
}
}
Assert.assertEquals(result, true,"Unexpected HTML");
}catch(Exception e){
e.printStackTrace();
throw new Exception(e);
}
}
public static void echo(String msg) {
System.out.println(msg);
}
}