/* (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());
  }
  /* (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.");
  }