Пример #1
0
 public void doTest() {
   try {
     invoke();
   } catch (Exception ex) {
     System.out.println(TEST_NAME + " test failed");
     stat.addStatus(TEST_NAME, stat.FAIL);
     ex.printStackTrace();
   }
 }
Пример #2
0
  public void doTest() {

    try {
      invokeJsp();
      stat.addStatus(TEST_NAME, stat.PASS);
    } catch (Exception ex) {
      stat.addStatus(TEST_NAME, stat.FAIL);
      ex.printStackTrace();
    }

    return;
  }
Пример #3
0
  public static void main(String[] args) {

    stat.addDescription("Unit test for resource injection into " + "ServletRequestListener");
    WebTest webTest = new WebTest(args);

    try {
      webTest.doTest();
      stat.addStatus(TEST_NAME, stat.PASS);
    } catch (Exception ex) {
      ex.printStackTrace();
      stat.addStatus(TEST_NAME, stat.FAIL);
    }

    stat.printSummary();
  }
Пример #4
0
  public static void main(String[] args) {

    stat.addDescription(
        "Unit test for ensuring binary compatibility "
            + "of GlassFish-style valves compiled against the old Valve "
            + "interface");
    WebTest webTest = new WebTest(args);

    try {
      webTest.doTest();
      stat.addStatus(TEST_NAME, stat.PASS);
    } catch (Exception ex) {
      ex.printStackTrace();
      stat.addStatus(TEST_NAME, stat.FAIL);
    }

    stat.printSummary();
  }
Пример #5
0
  public void doTest() {
    try {
      Socket sock = new Socket(host, new Integer(port).intValue());
      OutputStream os = sock.getOutputStream();
      String get = "GET " + contextRoot + "/index.jsp HTTP/1.0\n";
      System.out.print(get);
      os.write(get.getBytes());
      os.write("\n".getBytes());

      InputStream is = sock.getInputStream();
      BufferedReader br = new BufferedReader(new InputStreamReader(is));

      String line = null;
      int cookieCount = 0;
      String cookie = null;
      String value = null;
      while ((line = br.readLine()) != null) {
        System.out.println(line);
        if (line.startsWith("Set-Cookie: ")) {
          cookieCount += 1;
          int start = line.indexOf("=");
          int end = line.indexOf(";");
          if (end != -1) {
            cookie = line.substring(start + 1, end);
          } else {
            cookie = line.substring(start + 1);
          }
        } else if (line.startsWith("result=")) {
          value = line.substring("result=".length());
        }
      }

      boolean status = (cookieCount == 1) && cookie != null && cookie.equals(value);
      stat.addStatus(TEST_NAME, ((status) ? stat.PASS : stat.FAIL));
    } catch (Exception ex) {
      System.out.println(TEST_NAME + " test failed");
      stat.addStatus(TEST_NAME, stat.FAIL);
      ex.printStackTrace();
    }

    return;
  }
Пример #6
0
  public static void main(String[] args) {

    stat.addDescription("Unit test for CR 6716503");
    WebTest webTest = new WebTest(args);

    try {
      if ("first".equals(webTest.run)) {
        TEST_NAME = TEST_ROOT_NAME + "-first";
        webTest.firstRun();
      } else {
        TEST_NAME = TEST_ROOT_NAME + "-second";
        webTest.secondRun();
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      stat.addStatus(TEST_NAME, stat.FAIL);
    }

    stat.printSummary();
  }
Пример #7
0
  public static void main(String[] args) {

    stat.addDescription("Unit test for IT 12891, 17377");
    WebTest webTest = new WebTest(args);

    try {
      webTest.doTest("hello", 200);
      webTest.doTest("hello", 200);
      webTest.doTest("hello2", 500);
      webTest.doTest("hello2", 200);

      webTest.doTest("pages/test.jsp", 200);
      stat.addStatus(TEST_NAME, stat.PASS);
    } catch (Exception ex) {
      ex.printStackTrace();
      stat.addStatus(TEST_NAME, stat.FAIL);
    }

    stat.printSummary();
  }
Пример #8
0
  public void doTest() {

    BufferedReader bis = null;
    try {
      URL url = new URL("http://" + host + ":" + port + contextRoot + "/jsp/test.jspx");
      System.out.println("Connecting to: " + url.toString());
      HttpURLConnection conn = (HttpURLConnection) url.openConnection();
      conn.connect();
      int responseCode = conn.getResponseCode();
      if (responseCode != 200) {
        stat.addStatus(
            "Wrong response code. Expected: 200" + ", received: " + responseCode, stat.FAIL);
      } else {

        bis = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line = null;
        String lastLine = null;
        while ((line = bis.readLine()) != null) {
          lastLine = line;
        }
        if (!EXPECTED.equals(lastLine)) {
          stat.addStatus(
              "Wrong response body. Expected: " + EXPECTED + ", received: " + lastLine, stat.FAIL);
        } else {
          stat.addStatus(TEST_NAME, stat.PASS);
        }
      }
    } catch (Exception ex) {
      System.out.println(TEST_NAME + " test failed.");
      stat.addStatus(TEST_NAME, stat.FAIL);
      ex.printStackTrace();
    } finally {
      try {
        if (bis != null) bis.close();
      } catch (IOException ex) {
      }
    }
  }
Пример #9
0
  public void doTest() {

    BufferedReader bis = null;
    try {
      URL url = new URL("http://" + host + ":" + port + contextRoot + "/jsp/test.jsp");
      System.out.println("Connecting to: " + url.toString());
      HttpURLConnection conn = (HttpURLConnection) url.openConnection();
      conn.connect();
      int responseCode = conn.getResponseCode();
      if (responseCode != 200) {
        System.err.println("Wrong response code. Expected: 200" + ", received: " + responseCode);
        stat.addStatus(TEST_NAME, stat.FAIL);
      } else {

        bis = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line = null;
        int index = 0;
        while ((line = bis.readLine()) != null) {
          if (line.trim().length() == 0) continue;
          if (!line.equals(expected[index++])) {
            System.err.println("Wrong response: " + line + ", expected: " + expected[index]);
            stat.addStatus(TEST_NAME, stat.FAIL);
            return;
          }
        }
        stat.addStatus(TEST_NAME, stat.PASS);
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      stat.addStatus(TEST_NAME, stat.FAIL);
    } finally {
      try {
        if (bis != null) bis.close();
      } catch (IOException ex) {
      }
    }
  }
Пример #10
0
  private static void goGet(String host, int port, String contextPath) throws Exception {
    Socket s = new Socket(host, port);
    OutputStream os = s.getOutputStream();

    System.out.println("GET " + contextPath + " HTTP/1.0");
    os.write(("GET " + contextPath + " HTTP/1.0\n").getBytes());
    os.write("\n".getBytes());

    InputStream is = s.getInputStream();
    BufferedReader bis = new BufferedReader(new InputStreamReader(is));
    String line = null;

    int count = 0;
    try {
      while ((line = bis.readLine()) != null) {
        if (line.trim().length() > 0) System.out.println(line);
        if (line.indexOf("xxBodyTagxx") >= 0) count++;
      }
    } catch (Exception ex) {
      ex.printStackTrace();
      throw new Exception("Test UNPREDICTED-FAILURE");
    }
    if (count == 1) pass = true;
  }