Example #1
0
  public static void main(String[] args) throws Exception {

    int expectedCount = Integer.parseInt(args[0]);
    SimpleReporterAdapter stat = new SimpleReporterAdapter();
    String testSuite = "rar-accesibility";

    InitialContext ic = new InitialContext();
    Object objRef = ic.lookup("java:comp/env/ejb/SimpleSessionHome");
    SimpleSessionHome simpleSessionHome =
        (SimpleSessionHome) javax.rmi.PortableRemoteObject.narrow(objRef, SimpleSessionHome.class);

    stat.addDescription("Running rar_accessibility connector test ");
    SimpleSession bean = simpleSessionHome.create();

    try {
      if (bean.test1(expectedCount)) {
        stat.addStatus(testSuite + " test :  ", stat.PASS);
      } else {
        stat.addStatus(testSuite + " test :  ", stat.FAIL);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    stat.printSummary();
  }
Example #2
0
  private void invokeJsp() throws Exception {

    Socket sock = new Socket(host, new Integer(port).intValue());
    OutputStream os = sock.getOutputStream();
    String get = "GET " + contextRoot + "/jsp/test1.jsp" + " HTTP/1.0\n";
    System.out.println(get);
    os.write(get.getBytes());
    os.write("\n".getBytes());

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

    String line = null;
    while ((line = bis.readLine()) != null) {
      if (line.startsWith("Location:")) {
        break;
      }
    }

    if (line != null) {
      System.out.println(line);

      // Check the path
      if (line.startsWith("Location: " + PATH)) {
        fail = false;
      } else {
        System.err.println("Wrong path: " + line + ", expected: " + PATH);
        stat.addStatus(TEST_NAME, stat.FAIL);
        fail = true;
      }
    } else {
      System.err.println("Missing Location response header");
      stat.addStatus(TEST_NAME, stat.FAIL);
    }
  }
  public void callFedTaxService(boolean intendedResult) {
    double income = 97000.00;
    double deductions = 7000.00;
    try {

      FedTaxIF taxCalIFPort = taxCalService.getFedTaxIFPort();
      ((Stub) taxCalIFPort)._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, fedTaxEndpoint);

      double fedTax = taxCalIFPort.getFedTax(income, deductions);
      System.out.println("Fed tax from Ejb based TaxCalService :" + fedTax);

      if (fedTax == 18000.00 && intendedResult)
        stat.addStatus(testSuite + " FedTaxPort", stat.PASS);
      else {
        System.out.println("Call succeeded while it should have failed");
        stat.addStatus(testSuite + " FedTaxPort", stat.FAIL);
      }
    } catch (Exception ex) {
      if (intendedResult) {
        System.out.println("TaxCalEjbWebService client failed");
        stat.addStatus(testSuite + " FedTaxPort", stat.FAIL);
        ex.printStackTrace();
      } else {
        System.out.println("Expected Exception caught :");
        System.out.println(ex.getMessage());
        stat.addStatus(testSuite + "FedTaxPort", stat.PASS);
      }
    }
  }
Example #4
0
  private void doTestDD() throws Exception {
    String tcName = "connection-factory-definition-embedra-web-ejb-test";
    InputStream ddIS = null;
    try {
      String url = "http://" + host + ":" + port + "/connection-factory-definition-embedra/servlet";
      System.out.println("invoking connection-factory-definition-embedra test servlet at " + url);
      int code = invokeServlet(url);

      if (code != 200) {
        System.out.println("Incorrect return code: " + code);
        stat.addStatus(tcName, stat.FAIL);
      } else {
        stat.addStatus(tcName, stat.PASS);
      }

    } catch (Exception e) {
      stat.addStatus(tcName, stat.FAIL);
      throw e;
    } finally {
      if (ddIS != null) {
        ddIS.close();
      }
    }
    return;
  }
Example #5
0
  public void doTest() {

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

    return;
  }
Example #6
0
  public String doTest() {
    stat.addDescription("This is to test connector 1.5 " + "contracts.");

    String res = "NOT RUN";
    debug("doTest() ENTER...");
    boolean pass = false;
    try {

      try {
        InitialContext ic = new InitialContext();
        System.out.println(
            "appclient lookup of java:app/jdbc/app-level-ds : "
                + ic.lookup("java:app/jdbc/app-level-ds"));
      } catch (Exception e) {
        e.printStackTrace();
      }
      res = "ALL TESTS PASSED";
      int testCount = 1;
      while (!done()) {

        notifyAndWait();
        if (!done()) {
          debug("Running...");
          pass = checkResults(expectedResults());
          debug("Got expected results = " + pass);

          // do not continue if one test failed
          if (!pass) {
            res = "SOME TESTS FAILED";
            stat.addStatus("ID Connector 1.6 test - " + testCount, stat.FAIL);
          } else {
            stat.addStatus("ID Connector 1.6 test - " + testCount, stat.PASS);
          }
        } else {
          break;
        }
        testCount++;
      }

    } catch (Exception ex) {
      System.out.println("Importing transaction test failed.");
      ex.printStackTrace();
      res = "TEST FAILED";
    }
    stat.printSummary("connector1.6ID");

    debug("EXITING... STATUS = " + res);
    return res;
  }
Example #7
0
  private void goGet(String host, int port, String contextPath) throws Exception {

    sock = new Socket(host, port);
    OutputStream os = sock.getOutputStream();

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

    InputStream is = null;
    BufferedReader bis = null;
    String line = null;
    boolean pass = false;
    try {
      is = sock.getInputStream();
      bis = new BufferedReader(new InputStreamReader(is));
      while ((line = bis.readLine()) != null) {
        System.out.println(line);
        // Check if the filter was invoked
        if (EXPECTED_RESPONSE.equals("LLiFFiSSi")) {
          pass = true;
          break;
        }
      }
    } finally {
      try {
        if (is != null) {
          is.close();
        }
      } catch (IOException ioe) {
        // ignore
      }
      try {
        if (bis != null) {
          bis.close();
        }
      } catch (IOException ioe) {
        // ignore
      }
    }

    if (pass) {
      System.out.println("security constraint processed");
      stat.addStatus(TEST_NAME + " PASSED", stat.PASS);
    } else {
      System.out.println("security constraint NOT processed");
      stat.addStatus(TEST_NAME + " FAILED", stat.FAIL);
    }
  }
Example #8
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();
  }
Example #9
0
 public void doRollbackTest() {
   try {
     int intVal = (int) System.currentTimeMillis();
     SLSB slsb = (SLSB) home.create();
     boolean retVal = slsb.doRollbackTest(intVal);
     if (retVal) {
       stat.addStatus("txtests doRollbackTest", stat.PASS);
     } else {
       stat.addStatus("txtests doRollbackTest", stat.FAIL);
     }
   } catch (Exception ex) {
     ex.printStackTrace();
     stat.addStatus("txtests doRollbackTest", stat.FAIL);
   }
 }
Example #10
0
  public String doTest() {

    RpaRemote hr = null;
    String res = null;
    Context ic = null;
    LoginContext lc = null;
    RpaHome home = null;
    String testId = "Sec:: LDAP realm";
    try {
      stat.addDescription("Security:: LDAP realm");
      ic = new InitialContext();
      // create EJB using factory from container
      java.lang.Object objref = ic.lookup("rpaLoginBean");

      System.err.println("Looked up home!!");

      home = (RpaHome) PortableRemoteObject.narrow(objref, RpaHome.class);
      System.err.println("Narrowed home!!");

      hr = home.create("LizHurley");
      System.out.println("Got the EJB!!");

      // invoke 3 overloaded methods on the EJB
      System.out.println("Calling authorized method - addItem");
      hr.addItem("lipstick", 30);
      hr.addItem("mascara", 40);
      hr.addItem("lipstick2", 50);
      hr.addItem("sandals", 200);
      System.out.println(hr.getTotalCost());
      hr.deleteItem("lipstick2");
      java.lang.String[] shoppingList = hr.getItems();
      System.out.println("Shopping list for LizHurley");
      for (int i = 0; i < shoppingList.length; i++) {
        System.out.println(shoppingList[i]);
      }
      System.out.println("Total Cost for Ms Hurley = " + hr.getTotalCost());
      stat.addStatus(testId, stat.PASS);
      System.out.println("LDAP Realm:RpaLoginBean Test Passed");
    } catch (Exception re) {
      re.printStackTrace();
      stat.addStatus(testId, stat.FAIL);
      System.out.println("LDAP Realm:RpaLoginBean Test Failed");
      System.exit(-1);
    } finally {
      stat.printSummary();
    }
    return res;
  }
Example #11
0
  public void testExample3a() {
    String servlet = "/Example3a";
    String descriptionOpen = contextPathOpen + servlet;
    String descriptionDeny = contextPathDeny + servlet;

    StringBuffer output = new StringBuffer();
    boolean success = doIndividualTest(servlet, null, 200, username, contextPathOpen, output);
    if (success) {
      stat.addStatus(descriptionOpen, stat.PASS);
    } else stat.addStatus(descriptionOpen, stat.FAIL);

    output = new StringBuffer();
    success = doIndividualTest(servlet, null, 200, username, contextPathDeny, output);
    if (success) stat.addStatus(descriptionDeny, stat.PASS);
    else stat.addStatus(descriptionDeny, stat.FAIL);
  }
Example #12
0
  public static void main(String args[]) {

    // The stat reporter writes out the test info and results
    // into the top-level quicklook directory during a run.

    stat.addDescription("http-listener reader-threads unit tests.");

    String host = args[0];
    String portS = args[1];
    String contextRoot = args[2];

    int port = new Integer(portS).intValue();
    String name;

    try {
      goGet(host, port, "FILTER", contextRoot + "/ServletTest");
    } catch (Throwable t) {
      System.out.println(t.getMessage());
    }

    if (count != EXPECTED_COUNT) {
      stat.addStatus("web-readerThreadsConfig", stat.FAIL);
    }
    stat.printSummary("web/standalonewar---> expect " + EXPECTED_COUNT);
  }
Example #13
0
  public void secondRun() throws Exception {
    // Read the JSESSIONID from the previous run
    FileInputStream fis = new FileInputStream(JSESSIONID);
    BufferedReader br = new BufferedReader(new InputStreamReader(fis));
    String jsessionId = br.readLine();
    new File(JSESSIONID).delete();

    Socket sock = new Socket(host, new Integer(port).intValue());
    OutputStream os = sock.getOutputStream();
    String get = "GET " + contextRoot + "/ResumeSession" + " HTTP/1.0\n";
    System.out.println(get);
    os.write(get.getBytes());
    String cookie = "Cookie: " + jsessionId + "\n";
    os.write(cookie.getBytes());
    os.write("\n".getBytes());

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

    String line = null;
    boolean found = false;
    while ((line = br.readLine()) != null) {
      System.out.println(line);
      if (line.contains(EXPECTED_RESPONSE)) {
        found = true;
        break;
      }
    }

    if (found) {
      stat.addStatus(TEST_NAME, stat.PASS);
    } else {
      throw new Exception("Wrong response. Expected response: " + EXPECTED_RESPONSE + " not found");
    }
  }
Example #14
0
  public static void main(String args[]) {

    // The stat reporter writes out the test info and results
    // into the top-level quicklook directory during a run.

    stat.addDescription("Unit test for IT 13555");

    WebTest webTest = new WebTest(args);

    int port = new Integer(webTest.portS).intValue();
    String name;

    try {
      webTest.goGet(webTest.host, port, webTest.contextRoot + "/test");
    } catch (Throwable t) {
      System.out.println(t.getMessage());
      stat.addStatus(" Test " + TEST_NAME + " UNPREDICTED-FAILURE", stat.FAIL);
    } finally {
      try {
        if (webTest.sock != null) {
          webTest.sock.close();
        }
      } catch (IOException ioe) {
        // ignore
      }
    }

    stat.printSummary(TEST_NAME + " ---> PASS");
  }
Example #15
0
  public void firstRun() throws Exception {

    Socket sock = new Socket(host, new Integer(port).intValue());
    OutputStream os = sock.getOutputStream();
    String get = "GET " + contextRoot + "/test.jsp" + " HTTP/1.0\n";
    System.out.println(get);
    os.write(get.getBytes());
    os.write("\n".getBytes());

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

    // Get the JSESSIONID from the response
    String line = null;
    while ((line = br.readLine()) != null) {
      System.out.println(line);
      if (line.startsWith("Set-Cookie:") || line.startsWith("Set-cookie:")) {
        break;
      }
    }

    if (line == null) {
      throw new Exception("Missing Set-Cookie response header");
    }

    String jsessionId = getSessionIdFromCookie(line, JSESSIONID);

    // Store the JSESSIONID in a file
    FileOutputStream fos = new FileOutputStream(JSESSIONID);
    OutputStreamWriter osw = new OutputStreamWriter(fos);
    osw.write(jsessionId);
    osw.close();

    stat.addStatus(TEST_NAME, stat.PASS);
  }
Example #16
0
  public void testExample1() {
    String servlet = "/Example1";
    String descriptionOpen = contextPathOpen + servlet;
    String descriptionDeny = contextPathDeny + servlet;

    StringBuffer output = new StringBuffer();
    boolean success = doIndividualTest(servlet, null, 302, username, contextPathOpen, output);
    int index = output.indexOf("https://");
    if (success && (index != -1)) {
      stat.addStatus(descriptionOpen, stat.PASS);
    } else stat.addStatus(descriptionOpen, stat.FAIL);

    output = new StringBuffer();
    success = doIndividualTest(servlet, null, 302, username, contextPathDeny, output);
    if (success) stat.addStatus(descriptionDeny, stat.PASS);
    else stat.addStatus(descriptionDeny, stat.FAIL);
  }
Example #17
0
  public void testCovered3aDelete() {
    String servlet = "/Covered3a";
    String method = "DELETE";
    String descriptionOpen = contextPathOpen + servlet + "-" + method;
    String descriptionDeny = contextPathDeny + servlet + "-" + method;

    StringBuffer output = new StringBuffer();
    boolean success = doIndividualTest(servlet, method, 200, username, contextPathOpen, output);
    if (success) {
      stat.addStatus(descriptionOpen, stat.PASS);
    } else stat.addStatus(descriptionOpen, stat.FAIL);

    output = new StringBuffer();
    success = doIndividualTest(servlet, method, 200, username, contextPathDeny, output);
    if (success) stat.addStatus(descriptionDeny, stat.PASS);
    else stat.addStatus(descriptionDeny, stat.FAIL);
  }
  public static void main(String[] args) throws Exception {

    SimpleReporterAdapter stat = new SimpleReporterAdapter();
    String testSuite = "StatementWrapper ";

    InitialContext ic = new InitialContext();
    Object objRef = ic.lookup("java:comp/env/ejb/SimpleBMPHome");
    SimpleBMPHome simpleBMPHome =
        (SimpleBMPHome) javax.rmi.PortableRemoteObject.narrow(objRef, SimpleBMPHome.class);

    SimpleBMP simpleBMP = simpleBMPHome.create();
    stat.addDescription("JDBC Statement Wrapper Tests");

    if (simpleBMP.statementTest()) {
      stat.addStatus(testSuite + " statementTest : ", stat.PASS);
    } else {
      stat.addStatus(testSuite + " statementTest : ", stat.FAIL);
    }

    if (simpleBMP.preparedStatementTest()) {
      stat.addStatus(testSuite + " preparedStatementTest : ", stat.PASS);
    } else {
      stat.addStatus(testSuite + " preparedStatementTest : ", stat.FAIL);
    }

    if (simpleBMP.callableStatementTest()) {
      stat.addStatus(testSuite + " callableStatementTest : ", stat.PASS);
    } else {
      stat.addStatus(testSuite + " callableStatementTest : ", stat.FAIL);
    }

    if (simpleBMP.metaDataTest()) {
      stat.addStatus(testSuite + " metaDataTest : ", stat.PASS);
    } else {
      stat.addStatus(testSuite + " metaDataTest : ", stat.FAIL);
    }

    if (simpleBMP.resultSetTest()) {
      stat.addStatus(testSuite + " resultSetTest : ", stat.PASS);
    } else {
      stat.addStatus(testSuite + " resultSetTest : ", stat.FAIL);
    }

    stat.printSummary();
  }
Example #19
0
  public void testCovered3bPut() {
    String servlet = "/Covered3b";
    String method = "PUT";
    String descriptionOpen = contextPathOpen + servlet + "-" + method;
    String descriptionDeny = contextPathDeny + servlet + "-" + method;

    StringBuffer output = new StringBuffer();
    boolean success = doIndividualTest(servlet, method, 302, username, contextPathOpen, output);
    int index = output.indexOf("https://");
    if (success && (index != -1)) {
      stat.addStatus(descriptionOpen, stat.PASS);
    } else stat.addStatus(descriptionOpen, stat.FAIL);

    output = new StringBuffer();
    success = doIndividualTest(servlet, method, 302, username, contextPathDeny, output);
    if (success) stat.addStatus(descriptionDeny, stat.PASS);
    else stat.addStatus(descriptionDeny, stat.FAIL);
  }
Example #20
0
 public void doTest() {
   try {
     invoke();
   } catch (Exception ex) {
     System.out.println(TEST_NAME + " test failed");
     stat.addStatus(TEST_NAME, stat.FAIL);
     ex.printStackTrace();
   }
 }
Example #21
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();
  }
Example #22
0
  private void invoke() throws Exception {

    String url = "http://" + host + ":" + port + contextRoot + "/myurl";
    System.out.println("opening connection to " + url);
    HttpURLConnection conn = (HttpURLConnection) (new URL(url)).openConnection();

    int code = conn.getResponseCode();
    if (code != 200) {
      System.out.println("Unexpected return code: " + code);
      stat.addStatus(TEST_NAME, stat.FAIL);
    } else {
      InputStream is = null;
      BufferedReader input = null;
      String line = null;
      try {
        is = conn.getInputStream();
        input = new BufferedReader(new InputStreamReader(is));
        line = input.readLine();
        System.out.println("line = " + line);
      } finally {
        try {
          if (is != null) {
            is.close();
          }
        } catch (IOException ioe) {
          // ignore
        }
        try {
          if (input != null) {
            input.close();
          }
        } catch (IOException ioe) {
          // ignore
        }
      }
      if (EXPECTED_RESPONSE.equals(line)) {
        stat.addStatus(TEST_NAME, stat.PASS);
      } else {
        System.out.println(
            "Wrong response. Expected: " + EXPECTED_RESPONSE + ", received: " + line);
        stat.addStatus(TEST_NAME, stat.FAIL);
      }
    }
  }
Example #23
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;
  }
Example #24
0
  public static void main(String[] args) throws Exception {

    SimpleReporterAdapter stat = new SimpleReporterAdapter();
    String testSuite = "notxconn";

    InitialContext ic = new InitialContext();
    Object objRef = ic.lookup("java:comp/env/ejb/SimpleSessionHome");
    SimpleSessionHome simpleSessionHome =
        (SimpleSessionHome) javax.rmi.PortableRemoteObject.narrow(objRef, SimpleSessionHome.class);

    stat.addDescription("Running notxops testSuite2 ");
    SimpleSession simpleSession = simpleSessionHome.create();
    if (simpleSession.test1()) {
      stat.addStatus(testSuite + " test1 : ", stat.PASS);
    } else {
      stat.addStatus(testSuite + " test1 : ", stat.FAIL);
    }

    stat.printSummary();
  }
Example #25
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();
  }
Example #26
0
  public static void main(String args[]) {

    // The stat reporter writes out the test info and results
    // into the top-level quicklook directory during a run.

    stat.addDescription("Test BodyTag behavior when tag is reused");

    String host = args[0];
    String portS = args[1];
    String contextRoot = args[2];
    int port = new Integer(portS).intValue();

    try {
      goGet(host, port, contextRoot + "/test.jsp");
      stat.addStatus("BodyTag test", pass ? stat.PASS : stat.FAIL);
    } catch (Throwable t) {
      System.out.println(t.getMessage());
      stat.addStatus("Test UNPREDICTED-FAILURE", stat.FAIL);
    }

    stat.printSummary("BodyTag Reuse");
  }
Example #27
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) {
      }
    }
  }
Example #28
0
  private static void goGet(String host, int port, String result, String contextPath)
      throws Exception {
    long time = System.currentTimeMillis();
    Socket s = new Socket(host, port);
    s.setSoTimeout(5000);
    OutputStream os = s.getOutputStream();

    System.out.println(("GET " + contextPath + " HTTP/1.1\n"));
    os.write(("GET " + contextPath + " HTTP/1.1\n").getBytes());
    os.write(("Host: localhost\n").getBytes());
    os.write("\n".getBytes());

    InputStream is = s.getInputStream();
    System.out.println("Time: " + (System.currentTimeMillis() - time));
    BufferedReader bis = new BufferedReader(new InputStreamReader(is));
    String line = null;

    try {
      int index;
      while ((line = bis.readLine()) != null) {
        index = line.indexOf(result);
        System.out.println(line);
        if (index != -1) {
          index = line.indexOf(":");
          String status = line.substring(index + 1);

          if (status.equalsIgnoreCase("PASS")) {
            stat.addStatus("web-readerThreadsConfig: " + line.substring(0, index), stat.PASS);
          } else {
            stat.addStatus("web-readerThreadsConfig: " + line.substring(0, index), stat.FAIL);
          }
          count++;
        }
      }
    } catch (Exception ex) {
    }
  }
Example #29
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) {
      }
    }
  }
  public void callStateTaxService(boolean intendedResult) {
    double income = 85000.00;
    double deductions = 5000.00;

    // String targetEndpointAddress =
    //	"http://localhost:1024/taxcalculator";

    try {

      StateTaxIF taxCalIFPort = taxCalService.getStateTaxIFPort();

      ((Stub) taxCalIFPort)._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, stateTaxEndpoint);

      double stateTax = taxCalIFPort.getStateTax(income, deductions);
      System.out.println("State tax from ejb based TaxCalService :" + stateTax);

      if (stateTax == 24000.00 && intendedResult)
        stat.addStatus(testSuite + " StateTaxPort", stat.PASS);
      else {
        System.out.println("Call succeeded while it should have failed");
        stat.addStatus(testSuite + " StateTaxPort", stat.FAIL);
      }

    } catch (Exception ex) {
      if (intendedResult) {
        System.out.println("TaxCalEjbWebservice client failed");
        stat.addStatus(testSuite + " StateTaxPort", stat.FAIL);
        ex.printStackTrace();
      } else {
        System.out.println("Expected Exception caught :");
        System.out.println(ex.getMessage());
        ex.printStackTrace();
        stat.addStatus(testSuite + "StateTaxPort", stat.PASS);
      }
    }
  }