@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 testBuildSnapshotURL() {
    replayMocks();

    // With all valid parameters
    GetSnapshotHistoryTaskParameters taskParams = new GetSnapshotHistoryTaskParameters();
    taskParams.setSnapshotId(snapshotId);
    taskParams.setPageNumber(pageNumber);
    taskParams.setPageSize(pageSize);

    String url = taskRunner.buildBridgeURL(taskParams);
    String expectedUrl =
        "http://"
            + bridgeHost
            + ":"
            + bridgePort
            + "/bridge/snapshot/"
            + snapshotId
            + "/history?page="
            + pageNumber
            + "&pageSize="
            + pageSize;
    assertEquals(expectedUrl, url);

    // With some unusual parameters
    taskParams = new GetSnapshotHistoryTaskParameters();
    taskParams.setSnapshotId(snapshotId);
    taskParams.setPageNumber(-500);
    taskParams.setPageSize(100000000);

    url = taskRunner.buildBridgeURL(taskParams);
    expectedUrl =
        "http://"
            + bridgeHost
            + ":"
            + bridgePort
            + "/bridge/snapshot/"
            + snapshotId
            + "/history?page=0&pageSize=1000";
    assertEquals(expectedUrl, url);
  }
  @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) {
    }
  }