RSEndpoint implements IRSEndpoint { @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Override public String getMessageToClient(@FormParam(Constants.Message.MFC) String json) { HttpSession httpSession = getHttpSession(); setContext(httpSession); MessageFromClient message = MessageFromClient.createFromJson(json); MessageToClient mtc = getMessageToClientService().createMessageToClient(message, httpSession); return mtc.toJson(); }  @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Override String getMessageToClient(@FormParam(Constants.Message.MFC) String json); @Override HttpSession getHttpSession();  }
@Test public void testGetMessageToClient() { System.out.println("getMessageToClient"); MessageToClient mtc = mock(MessageToClient.class); HttpSession session = mock(HttpSession.class); when(request.getSession()).thenReturn(session); doNothing().when(instance).setContext(any(HttpSession.class)); String json = String.format("{\"%s\":\"%s\",\"%s\":\"%s\",\"%s\":\"%s\",\"%s\":%s}", Constants.Message.ID, UUID.randomUUID().toString(), Constants.Message.DATASERVICE, "DataServiceClassName", Constants.Message.OPERATION, "methodName", Constants.Message.ARGUMENTS, "[\"arg\"]"); when(messageToClientService.createMessageToClient(any(MessageFromClient.class), any(HttpSession.class))).thenReturn(mtc); when(mtc.toJson()).thenReturn("RESULT"); String result = instance.getMessageToClient(json); assertThat(result).isEqualTo("RESULT"); verify(messageToClientService).createMessageToClient(any(MessageFromClient.class), any(HttpSession.class)); }