@Test public void shouldGetMasterColumnListForRnR() { List<RnrColumn> allColumns = new ArrayList<>(); when(rnrTemplateService.fetchAllRnRColumns(existingProgramId)).thenReturn(allColumns); RnrTemplateForm rnrColumns = rnrTemplateController.fetchAllProgramRnrColumnList(existingProgramId); verify(rnrTemplateService).fetchAllRnRColumns(existingProgramId); assertThat(rnrColumns.getRnrColumns(), is(allColumns)); }
@Test public void shouldCreateARnRTemplateForAGivenProgramWithSpecifiedColumns() throws Exception { final RnrColumnList rnrColumns = new RnrColumnList(); MockHttpServletRequest request = new MockHttpServletRequest(); when(rnrTemplateService.saveRnRTemplateForProgram((ProgramRnrTemplate) any())) .thenReturn(new HashMap<String, OpenLmisMessage>()); when(messageService.message("template.save.success")).thenReturn("dummy success"); ResponseEntity<OpenLmisResponse> responseEntity = rnrTemplateController.saveRnRTemplateForProgram(existingProgramId, rnrColumns, request); assertThat(responseEntity.getBody().getSuccessMsg(), is("dummy success")); }
@Test public void shouldReturnErrorMessagesForCorrespondingFields() throws Exception { RnrColumnList rnrColumns = new RnrColumnList(); MockHttpServletRequest request = new MockHttpServletRequest(); HashMap<String, OpenLmisMessage> errorMap = new HashMap<>(); OpenLmisMessage openLmisMessage = new OpenLmisMessage("code", "param1", "param2"); errorMap.put("key", openLmisMessage); when(rnrTemplateService.saveRnRTemplateForProgram((ProgramRnrTemplate) any())) .thenReturn(errorMap); when(messageService.message(openLmisMessage.getCode(), openLmisMessage.getParams())) .thenReturn("dummy message param1 param2"); ResponseEntity<OpenLmisResponse> responseEntity = rnrTemplateController.saveRnRTemplateForProgram(existingProgramId, rnrColumns, request); assertThat( (String) responseEntity.getBody().getData().get("key"), is("dummy message param1 param2")); }