@Test(expected = MissingAuthorizationException.class) public void currentUser_noAccessToken() { FacebookTemplate facebook = new FacebookTemplate(); // use anonymous FacebookTemplate in this test MockRestServiceServer mockServer = MockRestServiceServer.createServer(facebook.getRestTemplate()); mockServer .expect(requestTo("https://graph.facebook.com/me")) .andExpect(method(GET)) .andRespond( withBadRequest() .body(jsonResource("testdata/error-current-user-no-token")) .contentType(MediaType.APPLICATION_JSON)); facebook.userOperations().getUserProfile(); }
@Test(expected = UncategorizedApiException.class) public void htmlErrorResponse() { try { FacebookTemplate facebook = new FacebookTemplate(); // use anonymous FacebookTemplate in this test MockRestServiceServer mockServer = MockRestServiceServer.createServer(facebook.getRestTemplate()); mockServer .expect(requestTo("https://graph.facebook.com/123456/picture?type=normal")) .andExpect(method(GET)) .andRespond( withBadRequest() .body(new ClassPathResource("testdata/error-not-json.html", getClass())) .contentType(MediaType.TEXT_HTML)); facebook.userOperations().getUserProfileImage("123456"); fail("Expected UncategorizedApiException"); } catch (UncategorizedApiException e) { assertTrue(e.getCause() instanceof HttpClientErrorException); throw e; } }