/** * @see org.openmrs.customdatatype.SerializingCustomDatatype#deserialize(java.lang.String) * @should return the object by given uuid string * @override */ @Override public Program deserialize(String uuid) { if (StringUtils.isBlank(uuid)) { return null; } return Context.getProgramWorkflowService().getProgramByUuid(uuid); } }
p = Context.getProgramWorkflowService().getProgramByName(c.getName().getName()); } else { p = Context.getProgramWorkflowService().getProgramByUuid(text);
/** * @see ProgramWorkflowService#getProgramByUuid(String) */ @Test public void getProgramByUuid_shouldReturnNullIfNoObjectFoundWithGivenUuid() { Assert.assertNull(Context.getProgramWorkflowService().getProgramByUuid("some invalid uuid")); }
/** * @see ProgramWorkflowService#getProgramByUuid(String) */ @Test public void getProgramByUuid_shouldFindObjectGivenValidUuid() { String uuid = "eae98b4c-e195-403b-b34a-82d94103b2c0"; Program program = Context.getProgramWorkflowService().getProgramByUuid(uuid); Assert.assertEquals(1, (int) program.getProgramId()); }
/** * @see ProgramWorkflowService#saveProgram(Program) */ @Test public void saveProgram_shouldUpdateDetachedProgram() { Program program = Context.getProgramWorkflowService().getProgramByUuid("eae98b4c-e195-403b-b34a-82d94103b2c0"); program.setDescription("new description"); Context.evictFromSession(program); program = Context.getProgramWorkflowService().saveProgram(program); Assert.assertEquals("new description", program.getDescription()); }
@Test public void retireProgram_shouldSaveTheRetiredProgramWithReason() throws APIException { String reason = "Feeling well."; String uuid = "eae98b4c-e195-403b-b34a-82d94103b2c0"; Program program = Context.getProgramWorkflowService().getProgramByUuid(uuid); Program retireProgram = pws.retireProgram(program, reason); assertTrue(retireProgram.getRetired()); assertEquals(reason, retireProgram.getRetireReason()); for (ProgramWorkflow programWorkflow : program.getAllWorkflows()) { assertTrue(programWorkflow.getRetired()); for (ProgramWorkflowState programWorkflowState : programWorkflow.getStates()) { assertTrue(programWorkflowState.getRetired()); } } }
@Override public Program getByUniqueId(String uniqueId) { Program programByUuid = Context.getProgramWorkflowService().getProgramByUuid(uniqueId); //We assume the caller was fetching by name if (programByUuid == null) { programByUuid = Context.getProgramWorkflowService().getProgramByName(uniqueId); } return programByUuid; }
@Override public Program newObject() { return Context.getProgramWorkflowService().getProgramByUuid(getUuidProperty()); }
if(prog != null && prog.trim().length() > 0) Program personProgram = Context.getProgramWorkflowService().getProgramByUuid(prog); if(personProgram == null)
program = Context.getProgramWorkflowService().getProgramByUuid(id);
@Test public void shouldGetAProgramByUuid() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI() + "/" + getUuid()); SimpleObject result = deserialize(handle(req)); Program program = service.getProgramByUuid(getUuid()); Assert.assertNotNull(result); Assert.assertEquals(program.getUuid(), PropertyUtils.getProperty(result, "uuid")); Assert.assertEquals(program.getName(), PropertyUtils.getProperty(result, "name")); Assert.assertEquals(program.getOutcomesConcept(), PropertyUtils.getProperty(result, "outcomesConcept")); }
Assert.assertTrue(dependencies.contains(Context.getProgramWorkflowService().getProgramByUuid( "da4a0391-ba62-4fad-ad66-1e3722d16380"))); Assert.assertTrue(dependencies.contains(Context.getProgramWorkflowService().getProgramByUuid( "71779c39-d289-4dfe-91b5-e7cfaa27c78b")));
@Test public void shouldEditAProgram() throws Exception { final String editedName = "Malaria Program Edited"; String json = "{ \"name\":\"" + editedName + "\" }"; MockHttpServletRequest req = request(RequestMethod.POST, getURI() + "/" + getUuid()); req.setContent(json.getBytes()); handle(req); Program editedProgram = service.getProgramByUuid(getUuid()); Assert.assertNotNull(editedProgram); Assert.assertEquals(editedName, editedProgram.getName()); }
Assert.assertFalse(dependencies.contains(Context.getProgramWorkflowService().getProgramByUuid( "da4a0391-ba62-4fad-ad66-1e3722d16380"))); Assert.assertFalse(dependencies.contains(Context.getProgramWorkflowService().getProgramByUuid( "71779c39-d289-4dfe-91b5-e7cfaa27c78b")));
@Test public void shouldGetAProgramByUuid() throws Exception { MockHttpServletRequest req = request(RequestMethod.GET, getURI() + "/" + getUuid()); SimpleObject result = deserialize(handle(req)); Program program = service.getProgramByUuid(getUuid()); Assert.assertNotNull(result); Assert.assertEquals(program.getUuid(), PropertyUtils.getProperty(result, "uuid")); Assert.assertEquals(program.getName(), PropertyUtils.getProperty(result, "name")); }
Assert.assertTrue(dependencies.contains(Context.getProgramWorkflowService().getProgramByUuid( "da4a0391-ba62-4fad-ad66-1e3722d16380"))); Assert.assertTrue(dependencies.contains(Context.getProgramWorkflowService().getProgramByUuid( "71779c39-d289-4dfe-91b5-e7cfaa27c78b")));