RestartSnapshotTaskRunner extends AbstractSnapshotTaskRunner { protected String callBridge(RestHttpHelper restHelper, String bridgeURL) { log.info("Making bridge call to restart snapshot. URL: {}", bridgeURL); try { RestHttpHelper.HttpResponse response = restHelper.post(bridgeURL, null, null); int statusCode = response.getStatusCode(); if (statusCode != HttpStatus.SC_ACCEPTED) { throw new RuntimeException("Unexpected response code: " + statusCode); } return response.getResponseBody(); } catch (Exception e) { throw new TaskException("Exception encountered attempting to " + "restart snapshot. " + "Error reported: " + e.getMessage(), e); } } RestartSnapshotTaskRunner(String bridgeAppHost,
                                     String bridgeAppPort,
                                     String bridgeAppUser,
                                     String bridgeAppPass); @Override String getName(); @Override String performTask(String taskParameters);  }
@Test public void testCallBridgeSuccess() throws Exception { String bridgeURL = "bridge-url"; SnapshotStatus status = SnapshotStatus.INITIALIZED; String description = "description"; RestartSnapshotBridgeResult bridgeResult = new RestartSnapshotBridgeResult(); bridgeResult.setDescription(description); bridgeResult.setStatus(status); InputStream resultStream = IOUtil.writeStringToStream(bridgeResult.serialize()); RestHttpHelper.HttpResponse response = RestHttpHelper.HttpResponse.buildMock(HttpStatus.SC_ACCEPTED, null, resultStream); EasyMock.expect(restHelper.post(bridgeURL, null, null)) .andReturn(response); replayMocks(); String callResult = taskRunner.callBridge(restHelper, bridgeURL); GetSnapshotTaskResult taskResult = GetSnapshotTaskResult.deserialize(callResult); assertEquals(status, taskResult.getStatus()); assertEquals(description, taskResult.getDescription()); }
@Test public void testCallBridgeFailure() throws Exception { String bridgeURL = "bridge-url"; InputStream resultStream = IOUtil.writeStringToStream("Error"); RestHttpHelper.HttpResponse response = RestHttpHelper.HttpResponse.buildMock(500, null, resultStream); EasyMock.expect(restHelper.post(bridgeURL, null, null)) .andReturn(response); replayMocks(); try { taskRunner.callBridge(restHelper, bridgeURL); fail("Exception expected on 500 response"); } catch (TaskException e) { } }