@Test public void getImplementationId_shouldReturnNullIfNoImplementationIdIsDefinedYet() { executeDataSet(ADMIN_INITIAL_DATA_XML); assertNull(adminService.getImplementationId()); }
@Test public void setImplementationId_shouldNotFailIfGivenImplementationIdIsNull() { // save a null impl id. no exception thrown adminService.setImplementationId(null); ImplementationId afterNull = adminService.getImplementationId(); assertNull("There shouldn't be an impl id defined after setting a null impl id", afterNull); }
/** * This uses a try/catch so that we can make sure no blank id is saved to the database. * * @see AdministrationService#setImplementationId(ImplementationId) */ @Test() public void setImplementationId_shouldThrowAPIExceptionIfGivenEmptyImplementationIdObject() { // save a blank impl id. exception thrown try { adminService.setImplementationId(new ImplementationId()); fail("An exception should be thrown on a blank impl id save"); } catch (APIException e) { // expected exception } ImplementationId afterBlank = adminService.getImplementationId(); assertNull("There shouldn't be an impl id defined after setting a blank impl id", afterBlank); }
@Test @Ignore public void setImplementationId_shouldOverwriteImplementationIdInDatabaseIfExists() { executeDataSet("org/openmrs/api/include/AdministrationServiceTest-general.xml"); // sanity check to make sure we have an implementation id assertNotNull(adminService.getImplementationId()); Context.clearSession(); // so a NonUniqueObjectException doesn't occur on the global property later // save a second valid id ImplementationId validId2 = new ImplementationId(); validId2.setImplementationId("JUNIT-TEST 2"); validId2.setName("JUNIT-TEST (#2) implementation id"); validId2.setPassphrase("This is the junit test passphrase 2"); validId2.setDescription("This is the junit impl id (2) used for testing of the openmrs API only."); adminService.setImplementationId(validId2); assertEquals(validId2, adminService.getImplementationId()); }
@Test @Ignore public void setImplementationId_shouldCreateImplementationIdInDatabase() { // save a valid impl id ImplementationId validId = new ImplementationId(); validId.setImplementationId("JUNIT-TEST"); validId.setName("JUNIT-TEST implementation id"); validId.setPassphrase("This is the junit test passphrase"); validId.setDescription("This is the junit impl id used for testing of the openmrs API only."); adminService.setImplementationId(validId); assertEquals(validId, adminService.getImplementationId()); }
@Test public void setImplementationId_shouldThrowAPIExceptionIfGivenAPipeInTheImplementationIdCode() { // save an impl id with an invalid hl7 code ImplementationId invalidId2 = new ImplementationId(); invalidId2.setImplementationId("pipe|pipe"); invalidId2.setName("an invalid impl id for a unit test"); invalidId2.setPassphrase("some valid passphrase"); invalidId2.setDescription("Some valid description"); try { adminService.setImplementationId(invalidId2); fail("An exception should be thrown on an invalid impl id save"); } catch (APIException e) { // expected exception } ImplementationId afterInvalid2 = adminService.getImplementationId(); assertNull("There shouldn't be an impl id defined after setting an invalid impl id", afterInvalid2); }
/** * This uses a try/catch so that we can make sure no blank id is saved to the database. */ @Test public void setImplementationId_shouldThrowAPIExceptionIfGivenACaretInTheImplementationIdCode() { // save an impl id with an invalid hl7 code ImplementationId invalidId = new ImplementationId(); invalidId.setImplementationId("caret^caret"); invalidId.setName("an invalid impl id for a unit test"); invalidId.setPassphrase("some valid passphrase"); invalidId.setDescription("Some valid description"); try { adminService.setImplementationId(invalidId); fail("An exception should be thrown on an invalid impl id save"); } catch (APIException e) { // expected exception } ImplementationId afterInvalid = adminService.getImplementationId(); assertNull("There shouldn't be an impl id defined after setting an invalid impl id", afterInvalid); }