List of usage examples for org.springframework.web.client RestClientException RestClientException
public RestClientException(String msg)
From source file:access.test.PiazzaEnvironmentTests.java
@Test public void testResourcesCauseRestException() { Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/workspaces/piazza.json"), Mockito.eq(HttpMethod.GET), Mockito.any(), Mockito.eq(String.class))) .thenThrow(new RestClientException("Error with the REST.")); Mockito.when(this.restTemplate.exchange(Mockito.endsWith("/datastores/piazza.json"), Mockito.eq(HttpMethod.GET), Mockito.any(), Mockito.eq(String.class))) .thenThrow(new RestClientException("Error with the REST.")); piazzaEnvironment.initializeEnvironment(); assertTrue(true); // no error occurred }
From source file:gateway.test.AlertTriggerTests.java
/** * Test GET /alert//from w ww . j a v a 2 s . c o m */ @Test public void testGetAlerts() { // Mock Response when(restTemplate.getForObject(anyString(), eq(String.class))).thenReturn("Alert"); // Test ResponseEntity<?> response = alertTriggerController.getAlerts(0, 10, null, "test", null, false, user); // Verify assertTrue(response.getBody().toString().equals("Alert")); assertTrue(response.getStatusCode().equals(HttpStatus.OK)); // Test Exception when(restTemplate.getForObject(anyString(), eq(String.class))) .thenThrow(new RestClientException("Alert Error")); response = alertTriggerController.getAlerts(0, 10, null, "test", null, false, user); assertTrue(response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); assertTrue(response.getBody() instanceof ErrorResponse); assertTrue(((ErrorResponse) response.getBody()).message.contains("Alert Error")); }
From source file:com.sastix.cms.server.services.content.impl.singlenode.SingleResourceServiceImpl.java
@Override public void unlockResource(LockedResourceDTO lockedResourceDTO) throws ResourceNotFound, ResourceNotOwned { final Revision latestRevision = crs.getLatestRevision(lockedResourceDTO.getResourceUID()); if (latestRevision == null) { throw new ResourceNotFound( "The supplied resource UID[" + lockedResourceDTO.getResourceUID() + "] does not exist."); }/*from ww w . j a v a 2 s .c o m*/ if (lockStatus.containsKey(lockedResourceDTO.getResourceUID())) { //UID already Locked final LockedResourceDTO cachedLockedResourceDTO = lockStatus.get(lockedResourceDTO.getResourceUID()); //Check author if (!cachedLockedResourceDTO.getAuthor().equals(lockedResourceDTO.getAuthor())) { throw new ResourceNotOwned( "The supplied resource UID cannot be unlocked, the lock is held by someone else already." + " Author: " + cachedLockedResourceDTO.getAuthor() + " ExpirationTime: " + lockedResourceDTO.getLockExpirationDate()); } } else { throw new RestClientException("Lock does not exist"); } lockStatus.remove(lockedResourceDTO.getResourceUID()); }
From source file:de.zib.gndms.gndmc.dspace.test.MockRestTemplate.java
@Override public final <T> ResponseEntity<T> exchange(final String url, final HttpMethod method, final HttpEntity<?> requestEntity, final Class<T> responseType, final Object... uriVariables) { if (!validUrlMethod(url, method)) { throw new RestClientException("Invalid http request for this url"); }//from w w w . j ava2 s . c om return new ResponseEntity<T>(HttpStatus.OK); }
From source file:gateway.test.EventTests.java
/** * Test GET /event/{eventId}/*from w w w . ja va2s . co m*/ */ @Test public void testGetEvent() { // Mock Response when(restTemplate.getForObject(anyString(), eq(String.class))).thenReturn("event"); // Test ResponseEntity<?> response = eventController.getEventInformation("eventId", user); // Verify assertTrue(response.getBody().toString().equals("event")); assertTrue(response.getStatusCode().equals(HttpStatus.OK)); // Test REST Exception when(restTemplate.getForObject(anyString(), eq(String.class))) .thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, WORKFLOW_ERROR)); response = eventController.getEventInformation("eventId", user); assertTrue(response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); // Test Exception when(restTemplate.getForObject(anyString(), eq(String.class))) .thenThrow(new RestClientException("event error")); response = eventController.getEventInformation("eventId", user); assertTrue(response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); assertTrue(response.getBody() instanceof ErrorResponse); assertTrue(((ErrorResponse) response.getBody()).message.contains("event error")); }
From source file:de.codecentric.boot.admin.services.ApplicationRegistratorTest.java
@Test public void register_multiple_all_failures() { adminProps.setRegisterOnce(false);/* w ww . ja v a 2s . c o m*/ when(restTemplate.postForEntity(isA(String.class), isA(HttpEntity.class), eq(Map.class))) .thenThrow(new RestClientException("Error")).thenThrow(new RestClientException("Error")); assertFalse(registrator.register()); }
From source file:gateway.test.AlertTriggerTests.java
/** * Test GET /alert/{alertId}//from www .ja v a 2s.co m */ @Test public void testGetAlert() { // Mock Response when(restTemplate.getForObject(anyString(), eq(String.class))).thenReturn("Alert"); // Test ResponseEntity<?> response = alertTriggerController.getAlert("AlertID", user); // Verify assertTrue(response.getBody().toString().equals("Alert")); assertTrue(response.getStatusCode().equals(HttpStatus.OK)); // Test Exception when(restTemplate.getForObject(anyString(), eq(String.class))) .thenThrow(new RestClientException("Alert Error")); response = alertTriggerController.getAlert("AlertID", user); assertTrue(response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); assertTrue(response.getBody() instanceof ErrorResponse); assertTrue(((ErrorResponse) response.getBody()).message.contains("Alert Error")); }
From source file:com.sastix.cms.server.services.content.impl.singlenode.SingleResourceServiceImpl.java
@Override public LockedResourceDTO renewResourceLock(LockedResourceDTO lockedResourceDTO) throws ResourceNotFound, ResourceNotOwned { final Revision latestRevision = crs.getLatestRevision(lockedResourceDTO.getResourceUID()); if (latestRevision == null) { throw new ResourceNotFound( "The supplied resource UID[" + lockedResourceDTO.getResourceUID() + "] does not exist."); }/*from w w w.ja v a 2s. c o m*/ if (lockStatus.containsKey(lockedResourceDTO.getResourceUID())) { //UID already Locked final LockedResourceDTO cachedLockedResourceDTO = lockStatus.get(lockedResourceDTO.getResourceUID()); //Check author if (!cachedLockedResourceDTO.getAuthor().equals(lockedResourceDTO.getAuthor())) { throw new ResourceNotOwned( "The supplied resource UID cannot be unlocked, the lock is held by someone else already." + " Author: " + cachedLockedResourceDTO.getAuthor() + " ExpirationTime: " + lockedResourceDTO.getLockExpirationDate()); } } else { throw new RestClientException("Lock does not exist"); } LockedResourceDTO savedLockedResourceDTO = lockStatus.get(lockedResourceDTO.getResourceUID()); savedLockedResourceDTO.setLockExpirationDate(DateTime.now().plusMinutes(30)); return savedLockedResourceDTO; }
From source file:org.openmrs.module.webservices.rest.resource.BillResource.java
private void loadBillCashPoint(Bill bill) { ITimesheetService service = Context.getService(ITimesheetService.class); Timesheet timesheet = service.getCurrentTimesheet(bill.getCashier()); if (timesheet == null) { AdministrationService adminService = Context.getAdministrationService(); boolean timesheetRequired; try {/*from ww w. ja v a 2 s . c om*/ timesheetRequired = Boolean .parseBoolean(adminService.getGlobalProperty(ModuleSettings.TIMESHEET_REQUIRED_PROPERTY)); } catch (Exception e) { timesheetRequired = false; } if (timesheetRequired) { throw new RestClientException( "A current timesheet does not exist for cashier " + bill.getCashier()); } else if (bill.getBillAdjusted() != null) { // If this is an adjusting bill, copy cash point from billAdjusted bill.setCashPoint(bill.getBillAdjusted().getCashPoint()); } else { throw new RestClientException("Cash point cannot be null!"); } } else { CashPoint cashPoint = timesheet.getCashPoint(); if (cashPoint == null) { throw new RestClientException("No cash points defined for the current timesheet!"); } bill.setCashPoint(cashPoint); } }
From source file:gateway.test.EventTests.java
/** * Test GET /eventType/* w ww . jav a 2 s . c o m*/ */ @Test public void testEventTypes() { // Mock Response when(restTemplate.getForObject(anyString(), eq(String.class))).thenReturn("eventTypes"); // Test ResponseEntity<?> response = eventController.getEventTypes(null, null, null, 0, 10, user); // Verify assertTrue(response.getBody().toString().equals("eventTypes")); assertTrue(response.getStatusCode().equals(HttpStatus.OK)); // Test REST Exception when(restTemplate.getForObject(anyString(), eq(String.class))) .thenThrow(new HttpServerErrorException(HttpStatus.INTERNAL_SERVER_ERROR, WORKFLOW_ERROR, WORKFLOW_ERROR.getBytes(), Charset.defaultCharset())); response = eventController.getEventTypes(null, null, null, 0, 10, user); assertTrue(response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); // Test Exception when(restTemplate.getForObject(anyString(), eq(String.class))) .thenThrow(new RestClientException("event error")); response = eventController.getEventTypes(null, null, null, 0, 10, user); assertTrue(response.getStatusCode().equals(HttpStatus.INTERNAL_SERVER_ERROR)); assertTrue(response.getBody() instanceof ErrorResponse); assertTrue(((ErrorResponse) response.getBody()).message.contains("event error")); }