Exemplo n.º 1
0
  @Test(
      groups = {"wso2.as"},
      description = "PUT request by super admin",
      dependsOnMethods = "testAddNewStudent")
  public void testUpdateStudent()
      throws IOException, EndpointAdminEndpointAdminException,
          LoginAuthenticationExceptionException, XMLStreamException {

    String updateStudentData =
        "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n"
            + "<p:updateStudent xmlns:p=\"http://axis2.apache.org\">\n"
            + "      <!--0 to 1 occurrence-->\n"
            + "      <ns:student xmlns:ns=\"http://axis2.apache.org\">\n"
            + "         <!--0 to 1 occurrence-->\n"
            + "         <xs:age xmlns:xs=\"http://axis2.apache.org\">999</xs:age>\n"
            + "         <!--0 to 1 occurrence-->\n"
            + "         <xs:name xmlns:xs=\"http://axis2.apache.org\">"
            + studentName
            + "</xs:name>\n"
            + "         <!--0 or more occurrences-->\n"
            + "         <xs:subjects xmlns:xs=\"http://axis2.apache.org\">testAutomationUpdated</xs:subjects>\n"
            + "      </ns:student>\n"
            + "</p:updateStudent>";

    String securedRestURL = getSecuredServiceEndpoint(SERVICE_NAME) + "/student/" + studentName;

    HttpsResponse response =
        HttpsURLConnectionClient.putWithBasicAuth(
            securedRestURL,
            updateStudentData,
            "application/xml",
            userInfo.getUserName(),
            userInfo.getPassword());

    assertTrue(
        response.getData().contains(studentName), "response doesn't contain the expected output");

    // check whether the student is added.
    String studentGetUri = getSecuredServiceEndpoint(SERVICE_NAME) + "/student/" + studentName;
    HttpsResponse getResponse =
        HttpsURLConnectionClient.getWithBasicAuth(
            studentGetUri, null, userInfo.getPassword(), userInfo.getPassword());
    assertTrue(
        getResponse
            .getData()
            .contains(
                "<ns:getStudentResponse xmlns:ns=\"http://axis2.apache.org\"><ns:return>"
                    + "<ns:age>999</ns:age>"
                    + "<ns:name>"
                    + studentName
                    + "</ns:name>"
                    + "<ns:subjects>testAutomationUpdated</ns:subjects>"
                    + "</ns:return></ns:getStudentResponse>"));
  }
  @Test(
      groups = {"wso2.as"},
      description = "POST request by invalid user",
      expectedExceptions = IOException.class,
      enabled = false)
  public void testAddNewStudent()
      throws IOException, EndpointAdminEndpointAdminException,
          LoginAuthenticationExceptionException, XMLStreamException {

    String addStudentData =
        "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n"
            + "   <p:addStudent xmlns:p=\"http://axis2.apache.org\">\n"
            + "      <!--0 to 1 occurrence-->\n"
            + "      <ns:student xmlns:ns=\"http://axis2.apache.org\">\n"
            + "         <!--0 to 1 occurrence-->\n"
            + "         <xs:age xmlns:xs=\"http://axis2.apache.org\">100</xs:age>\n"
            + "         <!--0 to 1 occurrence-->\n"
            + "         <xs:name xmlns:xs=\"http://axis2.apache.org\">"
            + studentName
            + "</xs:name>\n"
            + "         <!--0 or more occurrences-->\n"
            + "         <xs:subjects xmlns:xs=\"http://axis2.apache.org\">testAutomation</xs:subjects>\n"
            + "      </ns:student>\n"
            + "   </p:addStudent>";

    String securedRestURL = getSecuredServiceEndpoint(SERVICE_NAME) + "/students";
    HttpsResponse response =
        HttpsURLConnectionClient.postWithBasicAuth(
            securedRestURL, addStudentData, "application/xml", "InvalidUser", "InvalidPassword");

    assertEquals(response.getResponseCode(), 202, "Expected response code doesn't found");
    assertTrue(
        !response.getData().contains(studentName), "response doesn't contain the expected output");

    // check whether the student is added.
    String studentGetUri = getSecuredServiceEndpoint(SERVICE_NAME) + "/student/" + studentName;
    HttpsResponse getResponse =
        HttpsURLConnectionClient.getWithBasicAuth(
            studentGetUri, null, userInfo.getPassword(), userInfo.getPassword());
    assertTrue(
        getResponse
            .getData()
            .contains(
                "<ns:getStudentResponse xmlns:ns=\"http://axis2.apache.org\"><ns:return>"
                    + "<ns:age>100</ns:age>"
                    + "<ns:name>"
                    + studentName
                    + "</ns:name>"
                    + "<ns:subjects>testAutomation</ns:subjects>"
                    + "</ns:return></ns:getStudentResponse>"));
  }
Exemplo n.º 3
0
  @Test(
      groups = {"wso2.as"},
      description = "DELETE request by super admin",
      dependsOnMethods = "testUpdateStudent")
  public void testDeleteStudent()
      throws IOException, EndpointAdminEndpointAdminException,
          LoginAuthenticationExceptionException, XMLStreamException {

    String securedRestURL = getSecuredServiceEndpoint(SERVICE_NAME) + "/student/" + studentName;
    HttpsResponse response =
        HttpsURLConnectionClient.deleteWithBasicAuth(
            securedRestURL, null, userInfo.getPassword(), userInfo.getPassword());
    assertTrue(
        !response.getData().contains(studentName), "response doesn't contain the expected output");
  }
Exemplo n.º 4
0
  @Test(
      groups = {"wso2.as"},
      description = "GET resource after delete by admin",
      dependsOnMethods = "testDeleteStudent",
      expectedExceptions = IOException.class)
  public void testGetResourceAfterDelete()
      throws IOException, EndpointAdminEndpointAdminException,
          LoginAuthenticationExceptionException, XMLStreamException {

    // check whether the student is deleted
    String studentGetUri = getSecuredServiceEndpoint(SERVICE_NAME) + "/student/" + studentName;
    HttpsResponse getResponse =
        HttpsURLConnectionClient.getWithBasicAuth(
            studentGetUri, null, userInfo.getPassword(), userInfo.getPassword());
    assertTrue(getResponse.getData().equals(""), "student was not deleted");
  }
  @Test(
      groups = {"wso2.as"},
      description = "DELETE request  by invalid user",
      dependsOnMethods = "testUpdateStudent",
      enabled = false)
  public void testDeleteStudent()
      throws IOException, EndpointAdminEndpointAdminException,
          LoginAuthenticationExceptionException, XMLStreamException {
    boolean status = false;
    HttpsResponse response = null;

    String securedRestURL = getSecuredServiceEndpoint(SERVICE_NAME) + "/student/" + studentName;
    try {
      response =
          HttpsURLConnectionClient.deleteWithBasicAuth(
              securedRestURL, null, "InvalidUser", "InvalidPassword");
    } catch (IOException ignored) {
      status = true; // invalid users cannot get the resource
    }
    assertTrue(status, "Invalid user was able to get the resource");
    assertNull(response, "Response should be null");
  }
  @Test(
      groups = {"wso2.as"},
      description = "GET resource after delete  by invalid user",
      dependsOnMethods = "testDeleteStudent",
      enabled = false)
  public void testGetResourceAfterDelete()
      throws IOException, EndpointAdminEndpointAdminException,
          LoginAuthenticationExceptionException, XMLStreamException {

    // check whether the student is deleted
    String studentGetUri = getSecuredServiceEndpoint(SERVICE_NAME) + "/student/" + studentName;
    boolean getStatus = false;
    HttpsResponse getResponse = null;
    try {
      getResponse =
          HttpsURLConnectionClient.getWithBasicAuth(
              studentGetUri, null, userInfo.getPassword(), userInfo.getPassword());
    } catch (IOException ignored) {
      getStatus = true; // invalid users cannot get the resource
    }

    assertTrue(getStatus, "User belongs to invalid group was able to get the resource");
    assertNull(getResponse, "Response should be null");
  }