/** * 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. * * @throws Exception */ @AfterClass(alwaysRun = true) public void cleanUp() throws Exception { 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 ..."); } PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); // Delete Person resource(s) (before PersonAuthority resources). for (String resourceId : personIdsCreated) { // Note: Any non-success responses are ignored and not reported. personAuthClient.deleteItem(personAuthCSID, resourceId).close(); } // Delete PersonAuthority resource(s). // Note: Any non-success response is ignored and not reported. if (personAuthCSID != null) { personAuthClient.delete(personAuthCSID); // Delete Condition Checks resource(s). ConditioncheckClient conditioncheckClient = new ConditioncheckClient(); for (String resourceId : conditioncheckIdsCreated) { // Note: Any non-success responses are ignored and not reported. conditioncheckClient.delete(resourceId).close(); } } }
protected void createPersonRefs() throws Exception { PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); // Create a temporary PersonAuthority resource, and its corresponding // refName by which it can be identified. PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonAuthorityInstance( PERSON_AUTHORITY_NAME, PERSON_AUTHORITY_NAME, personAuthClient.getCommonPartName()); Response res = personAuthClient.create(multipart); try { int statusCode = res.getStatus(); Assert.assertTrue( testRequestType.isValidStatusCode(statusCode), invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); personAuthCSID = extractId(res); } finally { res.close(); } String authRefName = PersonAuthorityClientUtils.getAuthorityRefName(personAuthCSID, null); // Create temporary Person resources, and their corresponding refNames // by which they can be identified. String csid = createPerson("Carrie", "ConditionChecker1", "carrieConditionChecker", authRefName); personIdsCreated.add(csid); conditionCheckerRefName = PersonAuthorityClientUtils.getPersonRefName(personAuthCSID, csid, null); }
protected String createPerson( String firstName, String surName, String shortId, String authRefName) throws Exception { String result = null; PersonAuthorityClient personAuthClient = new PersonAuthorityClient(); Map<String, String> personInfo = new HashMap<String, String>(); personInfo.put(PersonJAXBSchema.FORE_NAME, firstName); personInfo.put(PersonJAXBSchema.SUR_NAME, surName); personInfo.put(PersonJAXBSchema.SHORT_IDENTIFIER, shortId); List<PersonTermGroup> personTerms = new ArrayList<PersonTermGroup>(); PersonTermGroup term = new PersonTermGroup(); String termName = firstName + " " + surName; term.setTermDisplayName(termName); term.setTermName(termName); personTerms.add(term); PoxPayloadOut multipart = PersonAuthorityClientUtils.createPersonInstance( personAuthCSID, authRefName, personInfo, personTerms, personAuthClient.getItemCommonPartName()); Response res = personAuthClient.createItem(personAuthCSID, multipart); try { int statusCode = res.getStatus(); Assert.assertTrue( testRequestType.isValidStatusCode(statusCode), invalidStatusCodeMessage(testRequestType, statusCode)); Assert.assertEquals(statusCode, STATUS_CREATED); result = extractId(res); } finally { res.close(); } return result; }