/** * Deletes all resources created by tests, after all tests have been run. * * <p>This cleanup method will always be run, even if one or more tests fail. For this reason, it * attempts to remove all resources created at any point during testing, even if some of those * resources may be expected to be deleted by certain tests. */ @AfterClass(alwaysRun = true) public void cleanUp() { String noTest = System.getProperty("noTestCleanup"); if (Boolean.TRUE.toString().equalsIgnoreCase(noTest)) { if (logger.isDebugEnabled()) { logger.debug("Skipping Cleanup phase ..."); } return; } if (logger.isDebugEnabled()) { logger.debug("Cleaning up temporary resources created for testing ..."); } IntakeClient intakeClient = new IntakeClient(); // Note: Any non-success responses are ignored and not reported. for (String resourceId : intakeIdsCreated) { ClientResponse<Response> res = intakeClient.delete(resourceId); res.releaseConnection(); } // Delete persons before PersonAuth OrgAuthorityClient personAuthClient = new OrgAuthorityClient(); for (String resourceId : orgIdsCreated) { ClientResponse<Response> res = personAuthClient.deleteItem(orgAuthCSID, resourceId); res.releaseConnection(); } if (orgAuthCSID != null) { personAuthClient.delete(orgAuthCSID).releaseConnection(); } }
// --------------------------------------------------------------- // CRUD tests : CREATE tests // --------------------------------------------------------------- // Success outcomes @Test(dataProvider = "testName", dataProviderClass = AbstractServiceTestImpl.class) public void createIntakeWithAuthRefs(String testName) throws Exception { testSetup(STATUS_CREATED, ServiceRequestType.CREATE); // Submit the request to the service and store the response. String identifier = createIdentifier(); // Create all the organization refs and entities createOrgRefs(); IntakeClient intakeClient = new IntakeClient(); PoxPayloadOut multipart = createIntakeInstance( "entryNumber-" + identifier, CURRENT_DATE_UTC, currentOwnerRefName, // Use currentOwnerRefName twice to test fix for CSPACE-2863 currentOwnerRefName, // depositorRefName, conditionCheckerAssessorRefName, insurerRefName, valuerRefName); ClientResponse<Response> res = intakeClient.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); } finally { res.releaseConnection(); } // Store the ID returned from the first resource created // for additional tests below. if (knownIntakeId == null) { knownIntakeId = extractId(res); if (logger.isDebugEnabled()) { logger.debug(testName + ": knownIntakeId=" + knownIntakeId); } } // Store the IDs from every resource created by tests, // so they can be deleted after tests have been run. intakeIdsCreated.add(extractId(res)); }