Пример #1
0
  /* (non-Javadoc)
   * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#deleteNonExistent(java.lang.String)
   */
  @Override
  //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
  //    dependsOnMethods = {"delete"})
  public void deleteNonExistent(String testName) throws Exception {
    // Perform setup.
    setupDeleteNonExistent();

    // Submit the request to the service and store the response.
    LoaninClient client = new LoaninClient();
    Response res = client.delete(NON_EXISTENT_ID);
    try {
      int statusCode = res.getStatus();

      // Check the status code of the response: does it match
      // the expected response(s)?
      if (logger.isDebugEnabled()) {
        logger.debug(testName + ": status = " + statusCode);
      }
      Assert.assertTrue(
          testRequestType.isValidStatusCode(statusCode),
          invalidStatusCodeMessage(testRequestType, statusCode));
      Assert.assertEquals(statusCode, testExpectedStatusCode);
    } finally {
      if (res != null) {
        res.close();
      }
    }
  }
Пример #2
0
  @Override
  //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
  //    dependsOnMethods = {"update", "testSubmitRequest"})
  public void updateNonExistent(String testName) throws Exception {
    // Perform setup.
    setupUpdateNonExistent();

    // Submit the request to the service and store the response.
    // Note: The ID used in this 'create' call may be arbitrary.
    // The only relevant ID may be the one used in update(), below.
    LoaninClient client = new LoaninClient();
    PoxPayloadOut multipart = createLoaninInstance(NON_EXISTENT_ID);
    Response res = client.update(NON_EXISTENT_ID, multipart);
    try {
      int statusCode = res.getStatus();

      // Check the status code of the response: does it match
      // the expected response(s)?
      if (logger.isDebugEnabled()) {
        logger.debug(testName + ": status = " + statusCode);
      }
      Assert.assertTrue(
          testRequestType.isValidStatusCode(statusCode),
          invalidStatusCodeMessage(testRequestType, statusCode));
      Assert.assertEquals(statusCode, testExpectedStatusCode);
    } finally {
      if (res != null) {
        res.close();
      }
    }
  }
Пример #3
0
  /* (non-Javadoc)
   * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#read(java.lang.String)
   */
  @Override
  //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
  //    dependsOnMethods = {"create"})
  public void read(String testName) throws Exception {
    // Perform setup.
    setupRead();

    // Submit the request to the service and store the response.
    LoaninClient client = new LoaninClient();
    Response res = client.read(knownResourceId);
    PoxPayloadIn input = null;
    try {
      assertStatusCode(res, testName);
      input = new PoxPayloadIn(res.readEntity(String.class));
    } finally {
      if (res != null) {
        res.close();
      }
    }

    // Get the common part of the response and verify that it is not null.
    PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
    LoansinCommon loaninCommon = null;
    if (payloadInputPart != null) {
      loaninCommon = (LoansinCommon) payloadInputPart.getBody();
    }
    Assert.assertNotNull(loaninCommon);

    // Check selected fields.
    LenderGroupList lenderGroupList = loaninCommon.getLenderGroupList();
    Assert.assertNotNull(lenderGroupList);
    List<LenderGroup> lenderGroups = lenderGroupList.getLenderGroup();
    Assert.assertNotNull(lenderGroups);
    Assert.assertTrue(lenderGroups.size() > 0);
    String lender = lenderGroups.get(0).getLender();
    Assert.assertEquals(lender, LENDER_REF_NAME);

    if (logger.isDebugEnabled()) {
      logger.debug(
          "UTF-8 data sent="
              + getUTF8DataFragment()
              + "\n"
              + "UTF-8 data received="
              + loaninCommon.getLoanInNote());
    }

    Assert.assertEquals(
        loaninCommon.getLoanInNote(),
        getUTF8DataFragment(),
        "UTF-8 data retrieved '"
            + loaninCommon.getLoanInNote()
            + "' does not match expected data '"
            + getUTF8DataFragment());
  }
Пример #4
0
  /* (non-Javadoc)
   * @see org.collectionspace.services.client.test.ServiceTest#create(java.lang.String)
   */
  @Override
  //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class)
  public void create(String testName) throws Exception {
    // Perform setup, such as initializing the type of service request
    // (e.g. CREATE, DELETE), its valid and expected status codes, and
    // its associated HTTP method name (e.g. POST, DELETE).
    setupCreate();

    // Submit the request to the service and store the response.
    LoaninClient client = new LoaninClient();
    String identifier = createIdentifier();
    PoxPayloadOut multipart = createLoaninInstance(identifier);
    String newID = null;
    Response res = client.create(multipart);
    try {
      int statusCode = res.getStatus();

      // Check the status code of the response: does it match
      // the expected response(s)?
      //
      // Specifically:
      // Does it fall within the set of valid status codes?
      // Does it exactly match the expected status code?
      if (logger.isDebugEnabled()) {
        logger.debug(testName + ": status = " + statusCode);
      }
      Assert.assertTrue(
          testRequestType.isValidStatusCode(statusCode),
          invalidStatusCodeMessage(testRequestType, statusCode));
      Assert.assertEquals(statusCode, testExpectedStatusCode);

      newID = extractId(res);
    } finally {
      if (res != null) {
        res.close();
      }
    }

    // Store the ID returned from the first resource created
    // for additional tests below.
    if (knownResourceId == null) {
      knownResourceId = newID;
      if (logger.isDebugEnabled()) {
        logger.debug(testName + ": knownResourceId=" + knownResourceId);
      }
    }

    // Store the IDs from every resource created by tests,
    // so they can be deleted after tests have been run.
    allResourceIdsCreated.add(newID);
  }
Пример #5
0
  /* (non-Javadoc)
   * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#readList(java.lang.String)
   */
  @Override
  //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
  //    dependsOnMethods = {"createList", "read"})
  public void readList(String testName) throws Exception {
    // Perform setup.
    setupReadList();

    // Submit the request to the service and store the response.
    AbstractCommonList list = null;
    LoaninClient client = new LoaninClient();
    Response res = client.readList();
    assertStatusCode(res, testName);
    try {
      int statusCode = res.getStatus();

      // Check the status code of the response: does it match
      // the expected response(s)?
      if (logger.isDebugEnabled()) {
        logger.debug(testName + ": status = " + statusCode);
      }
      Assert.assertTrue(
          testRequestType.isValidStatusCode(statusCode),
          invalidStatusCodeMessage(testRequestType, statusCode));
      Assert.assertEquals(statusCode, testExpectedStatusCode);

      list = res.readEntity(getCommonListType());
    } finally {
      if (res != null) {
        res.close();
      }
    }

    // Optionally output additional data about list members for debugging.
    boolean iterateThroughList = true;
    if (iterateThroughList && logger.isDebugEnabled()) {
      AbstractCommonListUtils.ListItemsInAbstractCommonList(list, logger, testName);
    }
  }
Пример #6
0
  /* (non-Javadoc)
   * @see org.collectionspace.services.client.test.AbstractServiceTestImpl#update(java.lang.String)
   */
  @Override
  //    @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class,
  //    dependsOnMethods = {"read"})
  public void update(String testName) throws Exception {
    // Perform setup.
    setupRead();

    // Retrieve the contents of a resource to update.
    LoaninClient client = new LoaninClient();
    Response res = client.read(knownResourceId);
    PoxPayloadIn input = null;
    try {
      assertStatusCode(res, testName);
      input = new PoxPayloadIn(res.readEntity(String.class));
      if (logger.isDebugEnabled()) {
        logger.debug("got object to update with ID: " + knownResourceId);
      }
    } finally {
      if (res != null) {
        res.close();
      }
    }

    // Extract the common part from the response.
    PayloadInputPart payloadInputPart = input.getPart(client.getCommonPartName());
    LoansinCommon loaninCommon = null;
    if (payloadInputPart != null) {
      loaninCommon = (LoansinCommon) payloadInputPart.getBody();
    }
    Assert.assertNotNull(loaninCommon);

    // Update the content of this resource.
    loaninCommon.setLoanInNumber("updated-" + loaninCommon.getLoanInNumber());
    loaninCommon.setLoanInNote("updated-" + loaninCommon.getLoanInNote());
    if (logger.isDebugEnabled()) {
      logger.debug("to be updated object");
      logger.debug(objectAsXmlString(loaninCommon, LoansinCommon.class));
    }

    setupUpdate();

    // Submit the updated common part in an update request to the service
    // and store the response.
    PoxPayloadOut output = new PoxPayloadOut(this.getServicePathComponent());
    PayloadOutputPart commonPart = output.addPart(client.getCommonPartName(), loaninCommon);
    res = client.update(knownResourceId, output);
    try {
      assertStatusCode(res, testName);
      int statusCode = res.getStatus();
      // Check the status code of the response: does it match the expected response(s)?
      if (logger.isDebugEnabled()) {
        logger.debug(testName + ": status = " + statusCode);
      }
      Assert.assertTrue(
          testRequestType.isValidStatusCode(statusCode),
          invalidStatusCodeMessage(testRequestType, statusCode));
      Assert.assertEquals(statusCode, testExpectedStatusCode);
      input = new PoxPayloadIn(res.readEntity(String.class));
    } finally {
      if (res != null) {
        res.close();
      }
    }

    // Extract the updated common part from the response.
    payloadInputPart = input.getPart(client.getCommonPartName());
    LoansinCommon updatedLoaninCommon = null;
    if (payloadInputPart != null) {
      updatedLoaninCommon = (LoansinCommon) payloadInputPart.getBody();
    }
    Assert.assertNotNull(updatedLoaninCommon);

    // Check selected fields in the updated common part.
    Assert.assertEquals(
        updatedLoaninCommon.getLoanInNumber(),
        loaninCommon.getLoanInNumber(),
        "Data in updated object did not match submitted data.");

    if (logger.isDebugEnabled()) {
      logger.debug(
          "UTF-8 data sent="
              + loaninCommon.getLoanInNote()
              + "\n"
              + "UTF-8 data received="
              + updatedLoaninCommon.getLoanInNote());
    }
    Assert.assertTrue(
        updatedLoaninCommon.getLoanInNote().contains(getUTF8DataFragment()),
        "UTF-8 data retrieved '"
            + updatedLoaninCommon.getLoanInNote()
            + "' does not contain expected data '"
            + getUTF8DataFragment());
    Assert.assertEquals(
        updatedLoaninCommon.getLoanInNote(),
        loaninCommon.getLoanInNote(),
        "Data in updated object did not match submitted data.");
  }