package de.juplo.facebook.exceptions;
import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.SerializationFeature;
import de.juplo.facebook.exceptions.GraphApiException.FacebookErrorMessage;
+import static de.juplo.facebook.exceptions.GraphApiException.OBJECT_MAPPER;
+import de.juplo.facebook.exceptions.GraphApiException.Type;
import java.io.IOException;
-import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
/**
* @author Kai Moritz
"}" +
"}";
- ObjectMapper mapper;
-
-
- @Before
- public void setUp()
- {
- mapper = new ObjectMapper();
- mapper.configure(DeserializationFeature.UNWRAP_ROOT_VALUE, true);
- mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, true);
- }
+ final String error_100 = "{\"error\":{\"message\":\"Unsupported get request. Please read the Graph API documentation at https:\\/\\/developers.facebook.com\\/docs\\/graph-api\",\"type\":\"GraphMethodException\",\"code\":100,\"fbtrace_id\":\"Bs\\/0p3CiVld\"}}";
@Test
{
FacebookErrorMessage error = new FacebookErrorMessage();
error.message = "Message describing the error";
- error.type = "OAuthException";
+ error.type = Type.OAuthException.name();
error.code = 190;
error.subCode = 460;
error.userTitle = "A title";
error.userMessage = "A message";
error.traceId = "EJplcsCHuLu";
- assertEquals(example, mapper.writeValueAsString(error));
+ assertEquals(example, OBJECT_MAPPER.writeValueAsString(error));
+ }
+
+ @Test
+ public void testSerialize100() throws JsonProcessingException
+ {
+ FacebookErrorMessage error = new FacebookErrorMessage();
+ error.message = "Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api";
+ error.type = "GraphMethodException";
+ error.code = 100;
+ error.traceId = "Bs/0p3CiVld";
+
+ assertEquals(error_100, OBJECT_MAPPER.writeValueAsString(error));
}
@Test
public void testDeserialize() throws IOException
{
FacebookErrorMessage error =
- mapper.readValue(example, FacebookErrorMessage.class);
+ OBJECT_MAPPER.readValue(example, FacebookErrorMessage.class);
assertEquals("Message describing the error", error.message);
- assertEquals("OAuthException", error.type);
+ assertEquals(Type.OAuthException.name(), error.type);
assertEquals(new Integer(190), error.code);
assertEquals(new Integer(460), error.subCode);
assertEquals("A title", error.userTitle);
assertEquals("A message", error.userMessage);
assertEquals("EJplcsCHuLu", error.traceId);
}
+
+ @Test
+ public void testDeserialize100() throws IOException
+ {
+ FacebookErrorMessage error =
+ OBJECT_MAPPER.readValue(error_100, FacebookErrorMessage.class);
+
+ assertEquals("Unsupported get request. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api", error.message);
+ assertEquals("GraphMethodException", error.type);
+ assertEquals(new Integer(100), error.code);
+ assertNull(error.subCode);
+ assertNull(error.userTitle);
+ assertNull(error.userMessage);
+ assertEquals("Bs/0p3CiVld", error.traceId);
+ }
}