コード例 #1
0
 @ExceptionHandler(Exception.class)
 public ResponseEntity<OpenLmisResponse> handleException(Exception ex) {
   logger.error("something broke with following exception... ", ex);
   if (ex instanceof AccessDeniedException) {
     return error(messageService.message(FORBIDDEN_EXCEPTION), HttpStatus.FORBIDDEN);
   }
   return error(messageService.message(UNEXPECTED_EXCEPTION), HttpStatus.INTERNAL_SERVER_ERROR);
 }
コード例 #2
0
 @Before
 public void setUp() {
   initMocks(this);
   request = new MockHttpServletRequest(USER, USER);
   request.getSession().setAttribute(USER_ID, 1L);
   when(messageService.message(anyString())).thenReturn("the message");
 }
コード例 #3
0
  @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"));
  }
コード例 #4
0
  @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"));
  }