@Test public void testCallBridgeSuccess() throws Exception { String bridgeURL = "bridge-url"; String history = "history"; Date historyDate = new Date(); SnapshotHistoryItem historyItem = new SnapshotHistoryItem(); historyItem.setHistory(history); historyItem.setHistoryDate(historyDate); List<SnapshotHistoryItem> historyItems = new ArrayList<>(); historyItems.add(historyItem); GetSnapshotHistoryBridgeResult bridgeResult = new GetSnapshotHistoryBridgeResult(); bridgeResult.setHistoryItems(historyItems); InputStream resultStream = IOUtil.writeStringToStream(bridgeResult.serialize()); RestHttpHelper.HttpResponse response = RestHttpHelper.HttpResponse.buildMock(200, null, resultStream); EasyMock.expect(restHelper.get(bridgeURL)).andReturn(response); replayMocks(); String callResult = taskRunner.callBridge(restHelper, bridgeURL); GetSnapshotHistoryBridgeResult taskResult = GetSnapshotHistoryBridgeResult.deserialize(callResult); SnapshotHistoryItem item = taskResult.getHistoryItems().get(0); assertEquals(history, item.getHistory()); assertEquals(historyDate, item.getHistoryDate()); }
@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); replayMocks(); try { taskRunner.callBridge(restHelper, bridgeURL); fail("Exception expected on 500 response"); } catch (TaskException e) { } }