List of usage examples for org.springframework.web.client RestClientException RestClientException
public RestClientException(String msg)
From source file:gateway.test.AlertTriggerTests.java
/** * Test POST /alert/query/*from w w w .jav a 2 s .c o m*/ */ @Test public void testQueryAlerts() { // Mock Alert alert = new Alert(); alert.alertId = "123456"; AlertListResponse mockResponse = new AlertListResponse(); mockResponse.data = new ArrayList<Alert>(); mockResponse.getData().add(alert); mockResponse.pagination = new Pagination(1, 0, 10, "test", "asc"); when(restTemplate.postForObject(anyString(), any(), eq(AlertListResponse.class))).thenReturn(mockResponse); // Test ResponseEntity<PiazzaResponse> entity = alertTriggerController.searchAlerts(null, 0, 10, null, null, false, user); AlertListResponse response = (AlertListResponse) entity.getBody(); // Verify assertTrue(entity.getStatusCode().equals(HttpStatus.OK)); assertTrue(response.getData().get(0).alertId.equalsIgnoreCase(alert.alertId)); assertTrue(response.getPagination().getCount().equals(1)); // Test an Exception when(restTemplate.postForObject(anyString(), any(), eq(AlertListResponse.class))) .thenThrow(new RestClientException("")); entity = alertTriggerController.searchAlerts(null, 0, 10, null, null, false, user); assertTrue(entity.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); assertTrue(entity.getBody() instanceof ErrorResponse); }
From source file:gateway.test.EventTests.java
/** * Test POST /eventType/* ww w . j a v a2 s . com*/ */ @Test public void testCreateEventType() { // Mock Response when(restTemplate.postForObject(anyString(), any(), eq(String.class))).thenReturn("OK"); // Test ResponseEntity<?> response = eventController.createEventType(new EventType(), user); // Verify assertTrue(response.getBody().toString().equals("OK")); assertTrue(response.getStatusCode().equals(HttpStatus.CREATED)); // Test Exception when(restTemplate.postForObject(anyString(), any(), eq(String.class))) .thenThrow(new RestClientException("event type error")); response = eventController.createEventType(new EventType(), user); assertTrue(response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); assertTrue(response.getBody() instanceof ErrorResponse); assertTrue(((ErrorResponse) response.getBody()).message.contains("event type error")); }
From source file:com.oneops.controller.cms.CMSClientTest.java
@SuppressWarnings("unchecked") @Test/*from w ww .j a v a 2s. c om*/ public void checkDeploymentTestWithRestTemplateThrowExceptionShouldSucced() throws Exception { DelegateExecution delegateExecution = mock(DelegateExecution.class); CmsDeployment cmsDeployment = new CmsDeployment(); cmsDeployment.setCreatedBy("created-by-mock"); when(delegateExecution.getVariable("dpmt")).thenReturn(cmsDeployment); RestTemplate restTemplate = mock(RestTemplate.class); //when(restTemplate.getForObject(anyString(), any(Class.class) , anyLong())).thenThrow(new RestClientException("test")).thenReturn(cmsDeployment); when(restTemplate.getForObject(anyString(), any(Class.class), anyLong())) .thenThrow(new RestClientException("test")).thenThrow(new RestClientException("test")) .thenReturn(cmsDeployment); cc.setRestTemplate(restTemplate); try { cc.setRetryTemplate(cc.getRetryTemplate(3, 2000, 1000)); cc.checkDpmt(delegateExecution); CmsDeployment cmsDeploymentPost = (CmsDeployment) delegateExecution.getVariable("dpmt"); assertEquals(cmsDeploymentPost.getCreatedBy(), "created-by-mock", "object mutated unexpectedly"); } catch (GeneralSecurityException e) { logger.warn("unexpected to catch here", e); throw e; } }
From source file:gateway.test.AlertTriggerTests.java
/** * Test POST /trigger/query// www .j a v a 2 s.co m */ @Test public void testQueryTriggers() { // Mock Trigger trigger = new Trigger(); trigger.triggerId = "123456"; TriggerListResponse mockResponse = new TriggerListResponse(); mockResponse.data = new ArrayList<Trigger>(); mockResponse.getData().add(trigger); mockResponse.pagination = new Pagination(1, 0, 10, "test", "asc"); when(restTemplate.postForObject(anyString(), any(), eq(TriggerListResponse.class))) .thenReturn(mockResponse); // Test ResponseEntity<PiazzaResponse> entity = alertTriggerController.searchTriggers(null, 0, 10, null, null, user); TriggerListResponse response = (TriggerListResponse) entity.getBody(); // Verify assertTrue(entity.getStatusCode().equals(HttpStatus.OK)); assertTrue(response.getData().get(0).triggerId.equalsIgnoreCase(trigger.triggerId)); assertTrue(response.getPagination().getCount().equals(1)); // Test an Exception when(restTemplate.postForObject(anyString(), any(), eq(TriggerListResponse.class))) .thenThrow(new RestClientException("")); entity = alertTriggerController.searchTriggers(null, 0, 10, null, null, user); assertTrue(entity.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); assertTrue(entity.getBody() instanceof ErrorResponse); }
From source file:gateway.test.EventTests.java
/** * Test GET /eventType/{eventTypeId}/*from ww w . j ava 2 s .com*/ */ @Test public void testGetEventType() { // Mock Response when(restTemplate.getForObject(anyString(), eq(String.class))).thenReturn("eventType"); // Test ResponseEntity<?> response = eventController.getEventType("eventTypeId", user); // Verify assertTrue(response.getBody().toString().equals("eventType")); assertTrue(response.getStatusCode().equals(HttpStatus.OK)); // Test Exception when(restTemplate.getForObject(anyString(), eq(String.class))) .thenThrow(new RestClientException("event type error")); response = eventController.getEventType("eventTypeId", user); assertTrue(response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); assertTrue(response.getBody() instanceof ErrorResponse); assertTrue(((ErrorResponse) response.getBody()).message.contains("event type error")); }
From source file:org.venice.piazza.servicecontroller.async.AsyncServiceWorkerTest.java
/** * Tests cancelling an instance/* ww w . j a v a 2s . c o m*/ */ @Test public void testCancellationStatus() { // Mock Mockito.doReturn(mockService).when(accessor).getServiceById(Mockito.eq(mockService.getServiceId())); // Test worker.sendCancellationStatus(mockInstance); // Test when an error is encountered from the service Mockito.doThrow(new RestClientException("Error")).when(restTemplate).delete(Mockito.any()); worker.sendCancellationStatus(mockInstance); }
From source file:gateway.test.ServiceTests.java
/** * Test service/query//w w w .j ava 2 s. com */ @Test public void testQuery() { // Mock ServiceListResponse mockResponse = new ServiceListResponse(); mockResponse.data = new ArrayList<Service>(); mockResponse.getData().add(mockService); mockResponse.pagination = new Pagination(1, 0, 10, "test", "asc"); when(restTemplate.postForObject(anyString(), any(), eq(ServiceListResponse.class))) .thenReturn(mockResponse); // Test ResponseEntity<PiazzaResponse> entity = serviceController.searchServices(null, 0, 10, null, null, user); ServiceListResponse response = (ServiceListResponse) entity.getBody(); // Verify assertTrue(entity.getStatusCode().equals(HttpStatus.OK)); assertTrue(response.getData().get(0).getServiceId().equalsIgnoreCase(mockService.getServiceId())); assertTrue(response.getPagination().getCount().equals(1)); // Test Exception when(restTemplate.postForObject(anyString(), any(), eq(ServiceListResponse.class))) .thenThrow(new RestClientException("Error")); entity = serviceController.searchServices(null, 0, 10, null, null, user); assertTrue(entity.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); assertTrue(entity.getBody() instanceof ErrorResponse); }
From source file:gateway.test.EventTests.java
/** * Test POST /event/query// w w w . j a v a 2 s.c o m */ @Test public void testQueryEvents() { // Mock Event event = new Event(); event.eventId = "123456"; EventListResponse mockResponse = new EventListResponse(); mockResponse.data = new ArrayList<Event>(); mockResponse.getData().add(event); mockResponse.pagination = new Pagination(1, 0, 10, "test", "asc"); when(restTemplate.postForObject(anyString(), any(), eq(EventListResponse.class))).thenReturn(mockResponse); // Test ResponseEntity<PiazzaResponse> entity = eventController.searchEvents(null, 0, 10, null, null, user); EventListResponse response = (EventListResponse) entity.getBody(); // Verify assertTrue(entity.getStatusCode().equals(HttpStatus.OK)); assertTrue(response.getData().get(0).eventId.equalsIgnoreCase(event.eventId)); assertTrue(response.getPagination().getCount().equals(1)); // Test an Exception when(restTemplate.postForObject(anyString(), any(), eq(EventListResponse.class))) .thenThrow(new RestClientException("")); entity = eventController.searchEvents(null, 0, 10, null, null, user); assertTrue(entity.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); assertTrue(entity.getBody() instanceof ErrorResponse); }
From source file:com.capitalone.dashboard.collector.DefaultNexusIQClientTest.java
@Test public void getDetailedReport404() throws Exception { String reportDataUrl = "http://nexus.com/api/v2/applications/Innovation-Challenge-picket/reports/967635a9cdc54d2cb30cf6f87f3a8943"; settings.setSelectStricterLicense(true); doThrow(new RestClientException("404")).when(rest).exchange(eq(reportDataUrl), eq(HttpMethod.GET), Matchers.any(HttpEntity.class), eq(String.class)); LibraryPolicyResult result = defaultNexusIQClient.getDetailedReport(reportDataUrl); assertNull(result);//w ww . j a va 2s.c o m }
From source file:gateway.test.EventTests.java
/** * Test POST /eventType/query//from ww w . ja v a2 s .c om */ @Test public void testQueryEventTypes() { // Mock EventType eventType = new EventType(); eventType.eventTypeId = "123456"; EventTypeListResponse mockResponse = new EventTypeListResponse(); mockResponse.data = new ArrayList<EventType>(); mockResponse.getData().add(eventType); mockResponse.pagination = new Pagination(1, 0, 10, "test", "asc"); when(restTemplate.postForObject(anyString(), any(), eq(EventTypeListResponse.class))) .thenReturn(mockResponse); // Test ResponseEntity<PiazzaResponse> entity = eventController.searchEventTypes(null, 0, 10, null, null, user); EventTypeListResponse response = (EventTypeListResponse) entity.getBody(); // Verify assertTrue(entity.getStatusCode().equals(HttpStatus.OK)); assertTrue(response.getData().get(0).eventTypeId.equalsIgnoreCase(eventType.eventTypeId)); assertTrue(response.getPagination().getCount().equals(1)); // Test an Exception when(restTemplate.postForObject(anyString(), any(), eq(EventTypeListResponse.class))) .thenThrow(new RestClientException("")); entity = eventController.searchEventTypes(null, 0, 10, null, null, user); assertTrue(entity.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); assertTrue(entity.getBody() instanceof ErrorResponse); }