GetSnapshotsTaskRunner extends AbstractSnapshotTaskRunner { protected String callBridge(RestHttpHelper restHelper, String bridgeURL) { log.info("Making bridge call to get snapshot list. URL: {}", bridgeURL); try { RestHttpHelper.HttpResponse response = restHelper.get(bridgeURL); int statusCode = response.getStatusCode(); if (statusCode != 200) { throw new RuntimeException("Unexpected response code: " + statusCode); } return response.getResponseBody(); } catch (Exception e) { throw new TaskException("Exception encountered attempting to " + "get list of snapshots. " + "Error reported: " + e.getMessage(), e); } } GetSnapshotsTaskRunner(String dcHost,
                                  String dcStoreId,
                                  String bridgeAppHost,
                                  String bridgeAppPort,
                                  String bridgeAppUser,
                                  String bridgeAppPass,
                                  StorageProvider storageProvider); @Override String getName(); @Override String performTask(String taskParameters);  }
@Test public void testCallBridgeSuccess() throws Exception { String bridgeURL = "bridge-url"; String storeId = "store-id"; String spaceId = "space-id"; SnapshotSummary summary1 = new SnapshotSummary("id-1", SnapshotStatus.SNAPSHOT_COMPLETE, "desc-1", storeId, spaceId); List<SnapshotSummary> summaries = new ArrayList<>(); summaries.add(summary1); GetSnapshotListBridgeResult bridgeResult = new GetSnapshotListBridgeResult(summaries); InputStream resultStream = IOUtil.writeStringToStream(bridgeResult.serialize()); RestHttpHelper.HttpResponse response = RestHttpHelper.HttpResponse.buildMock(200, null, resultStream); EasyMock.expect(restHelper.get(bridgeURL)) .andReturn(response); replayAll(); String callResult = taskRunner.callBridge(restHelper, bridgeURL); GetSnapshotListTaskResult taskResult = GetSnapshotListTaskResult.deserialize(callResult); List<SnapshotSummary> summaryResults = taskResult.getSnapshots(); assertEquals(1, summaryResults.size()); SnapshotSummary result = summaryResults.get(0); assertEquals(summary1.getSnapshotId(), result.getSnapshotId()); assertEquals(summary1.getStatus(), result.getStatus()); assertEquals(summary1.getDescription(), result.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.get(bridgeURL)) .andReturn(response); replayAll(); try { taskRunner.callBridge(restHelper, bridgeURL); fail("Exception expected on 500 response"); } catch (TaskException e) { } }