@Test
 public void serializeCustomerError() throws JsonProcessingException {
   JsonService jsonService = new JsonService();
   CustomerError error = new CustomerError();
   int pos = jsonService.writeAsOuterString(error).indexOf("type");
   assertTrue(jsonService.writeAsOuterString(error).indexOf("type", pos + 1) == -1);
 }
 @Test
 public void sessionIdHide() throws JsonProcessingException {
   JsonService jsonService = new JsonService();
   AuthRequest authRequest = new AuthRequest();
   assertTrue(!jsonService.writeAsOuterString(authRequest).contains("sessionId"));
   assertTrue(new String(jsonService.writeValueAsBytes(authRequest)).contains("sessionId"));
 }
 @Test
 public void serializeDateFormat() throws JsonProcessingException {
   JsonService jsonService = new JsonService();
   AuthResponse response = new AuthResponse();
   response.setData(new AuthResponseData());
   response.getData().setApiTokenExpirationDate(new DateTime(2016, 2, 14, 0, 0));
   assertTrue(
       jsonService
           .writeAsOuterString(response)
           .contains("\"api_token_expiration_date\":\"2016-02"));
 }
  @Test
  public void deserializeCommandFromClient() throws IOException {
    JsonService jsonService = new JsonService();

    boolean fail = false;
    try {
      String failCommand =
          "{\"type\":\"FAIL_COMMAND_ID\",\"data\":{\"email\":null,\"password\":null},\"sequence_id\":\"40af1120-6244-42cb-9650-ad860592f0ba\"}";
      jsonService.readValue(failCommand, SaturnMessage.class);
    } catch (JsonMappingException e) {
      fail = true;
    }
    assertTrue(fail);

    fail = false;
    try {
      String failCommand = "{\"type1\":\"FAIL_COMMAND_ID\"}";
      jsonService.readValue(failCommand, SaturnMessage.class);
    } catch (JsonMappingException e) {
      fail = true;
    }
    assertTrue(fail);

    fail = false;
    try {
      String failCommand = "FAIL_COMMAND_ID";
      jsonService.readValue(failCommand, SaturnMessage.class);
    } catch (JsonParseException e) {
      fail = true;
    }
    assertTrue(fail);

    String successCommand =
        "{\"type\":\"LOGIN_CUSTOMER\",\"data\":{\"email\":null,\"password\":null},\"sequence_id\":\"40af1120-6244-42cb-9650-ad860592f0ba\"}";
    SaturnMessage result = jsonService.readValue(successCommand, SaturnMessage.class);
    assertTrue(result.getClass() == AuthRequest.class);
  }
Esempio n. 5
0
  public SlackResponse sendSlackInvitation(String email, String project) {
    ResponseEntity<String> response =
        new RestTemplate()
            .exchange(
                "https://slack.com/api/users.admin.invite?token={token}&email={email}",
                HttpMethod.GET,
                null,
                String.class,
                integrationProperties.getSlackToken(project),
                email);

    return response.getStatusCode().is2xxSuccessful()
        ? jsonService.readValue(response.getBody(), SlackResponse.class)
        : new SlackResponse(false, response.getBody());
  }