1 package de.juplo.facebook.exceptions;
3 import com.fasterxml.jackson.core.JsonProcessingException;
4 import com.fasterxml.jackson.databind.DeserializationFeature;
5 import com.fasterxml.jackson.databind.ObjectMapper;
6 import com.fasterxml.jackson.databind.SerializationFeature;
7 import de.juplo.facebook.exceptions.GraphApiException.FacebookErrorMessage;
8 import java.io.IOException;
9 import org.junit.Before;
10 import org.junit.Test;
11 import static org.junit.Assert.assertEquals;
16 public class FacebookErrorMessageMappingTest
18 final String example =
21 "\"message\":\"Message describing the error\"," +
22 "\"type\":\"OAuthException\"," +
24 "\"error_subcode\":460," +
25 "\"error_user_title\":\"A title\"," +
26 "\"error_user_msg\":\"A message\"," +
27 "\"fbtrace_id\":\"EJplcsCHuLu\"" +
37 mapper = new ObjectMapper();
38 mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
39 mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
44 public void testSerialize() throws JsonProcessingException
46 FacebookErrorMessage error = new FacebookErrorMessage();
47 error.message = "Message describing the error";
48 error.type = "OAuthException";
51 error.userTitle = "A title";
52 error.userMessage = "A message";
53 error.traceId = "EJplcsCHuLu";
55 assertEquals(example, mapper.writeValueAsString(error));
59 public void testDeserialize() throws IOException
61 FacebookErrorMessage error =
62 mapper.readValue(example, FacebookErrorMessage.class);
64 assertEquals("Message describing the error", error.message);
65 assertEquals("OAuthException", error.type);
66 assertEquals(new Integer(190), error.code);
67 assertEquals(new Integer(460), error.subCode);
68 assertEquals("A title", error.userTitle);
69 assertEquals("A message", error.userMessage);
70 assertEquals("EJplcsCHuLu", error.traceId);