List of usage examples for org.springframework.web.client HttpClientErrorException HttpClientErrorException
public HttpClientErrorException(HttpStatus statusCode)
From source file:com.jaspersoft.android.jaspermobile.test.acceptance.profile.ServersManagerPageTest.java
public void testPageShouldProperlyHandleUnAuthorized() { registerTestModule(new CommonTestModule() { @Override/*from w ww .j a va2s . co m*/ protected void semanticConfigure() { bind(JsSpiceManager.class).toInstance(new JsSpiceManager() { @Override public <T> void execute(CachedSpiceRequest<T> cachedSpiceRequest, final RequestListener<T> requestListener) { HttpClientErrorException httpClientErrorException = new HttpClientErrorException( HttpStatus.UNAUTHORIZED); requestListener.onRequestFailure(new NetworkException( "Exception occurred during invocation of web service.", httpClientErrorException)); } }); } }); startActivityUnderTest(); onView(withId(R.id.addProfile)).perform(click()); onView(withId(R.id.aliasEdit)).perform(typeText(TEST_ALIAS)); onView(withId(R.id.serverUrlEdit)).perform(typeText(TEST_SERVER_URL)); onView(withId(R.id.organizationEdit)).perform(typeText("some invalid organization")); onView(withId(R.id.usernameEdit)).perform(typeText("some invalid username")); onView(withId(R.id.passwordEdit)).perform(typeText("some invalid password")); onView(withId(R.id.saveAction)).perform(click()); FakeHttpLayerManager.clearHttpResponseRules(); FakeHttpLayerManager.addHttpResponseRule(ApiMatcher.SERVER_INFO, TestResponses.get().notAuthorized()); onView(withText(TEST_ALIAS)).perform(click()); onOverflowView(getActivity(), withId(R.id.sdl__title)).check(matches(withText(R.string.error_msg))); onOverflowView(getActivity(), withId(R.id.sdl__message)) .check(matches(withText(ExceptionRule.UNAUTHORIZED.getMessage()))); onOverflowView(getActivity(), withId(R.id.sdl__negative_button)).perform(click()); }
From source file:com.netflix.genie.web.controllers.JobRestControllerUnitTests.java
/** * Make sure directory forwarding happens when all conditions are met. * * @throws IOException on error// w w w .ja v a 2 s .c o m * @throws ServletException on error * @throws GenieException on error */ @Test public void canHandleForwardJobOutputRequestWithError() throws IOException, ServletException, GenieException { this.jobsProperties.getForwarding().setEnabled(true); final String jobId = UUID.randomUUID().toString(); final String forwardedFrom = null; final HttpServletRequest request = Mockito.mock(HttpServletRequest.class); final HttpServletResponse response = Mockito.mock(HttpServletResponse.class); Mockito.doNothing().when(this.genieResourceHttpRequestHandler).handleRequest(request, response); final String jobHostName = UUID.randomUUID().toString(); Mockito.when(this.jobSearchService.getJobHost(jobId)).thenReturn(jobHostName); //Mock parts of the http request final String http = "http"; Mockito.when(request.getScheme()).thenReturn(http); final int port = 8080; Mockito.when(request.getServerPort()).thenReturn(port); final String requestURI = "/" + jobId + "/" + UUID.randomUUID().toString(); Mockito.when(request.getRequestURI()).thenReturn(requestURI); Mockito.when(request.getHeaderNames()).thenReturn(null); final String requestUrl = UUID.randomUUID().toString(); Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer(requestUrl)); final int errorCode = 404; Mockito.when(this.restTemplate.execute(Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString())) .thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND)); this.controller.getJobOutput(jobId, forwardedFrom, request, response); Mockito.verify(this.jobSearchService, Mockito.times(1)).getJobHost(Mockito.eq(jobId)); Mockito.verify(this.restTemplate, Mockito.times(1)).execute(Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.anyString(), Mockito.anyString()); Mockito.verify(response, Mockito.times(1)).sendError(Mockito.eq(errorCode), Mockito.anyString()); Mockito.verify(this.genieResourceHttpRequestHandler, Mockito.never()).handleRequest(request, response); }
From source file:org.venice.beachfront.bfapi.services.OAuthServiceTests.java
@Test public void testRequestAccessTokenUserError() { String mockAuthCode = "mock-auth-code-123"; Mockito.when(this.restTemplate.exchange(Mockito.eq(this.oauthTokenUrl), Mockito.eq(HttpMethod.POST), Mockito.any(), Mockito.eq(AccessTokenResponseBody.class))) .then(new Answer<ResponseEntity<AccessTokenResponseBody>>() { @Override//from www .j a v a2s. com public ResponseEntity<AccessTokenResponseBody> answer(InvocationOnMock invocation) { throw new HttpClientErrorException(HttpStatus.UNAUTHORIZED); } }); try { oauthService.requestAccessToken(mockAuthCode); fail("request should not have succeeded"); } catch (UserException ex) { assertEquals(HttpStatus.UNAUTHORIZED, ex.getRecommendedStatusCode()); } }
From source file:org.venice.beachfront.bfapi.services.OAuthServiceTests.java
@Test public void testRequestOAuthProfileUserError() { String mockAccessToken = "mock-access-token-321"; Mockito.when(this.restTemplate.exchange(Mockito.eq(this.oauthProfileUrl), Mockito.eq(HttpMethod.GET), Mockito.any(), Mockito.eq(String.class))).then(new Answer<ResponseEntity<String>>() { @Override//from w w w .ja v a2 s .c o m public ResponseEntity<String> answer(InvocationOnMock invocation) { throw new HttpClientErrorException(HttpStatus.UNAUTHORIZED); } }); try { oauthService.requestOAuthProfile(mockAccessToken); fail("request should not have succeeded"); } catch (UserException ex) { assertEquals(HttpStatus.UNAUTHORIZED, ex.getRecommendedStatusCode()); } }
From source file:tds.itemrenderer.repository.impl.RemoteContentRepositoryTest.java
@Test(expected = IOException.class) public void shouldThrowIOExceptionFor404() throws IOException { final String resourcePath = "/path/to/resource"; when(mockRestTemplate.exchange(isA(URI.class), isA(HttpMethod.class), isA(HttpEntity.class), isA(ParameterizedTypeReference.class))) .thenThrow(new HttpClientErrorException(HttpStatus.NOT_FOUND)); remoteContentRepository.findResource(resourcePath); }