@Test
public void testPutImageIndex() throws IOException {

    ElasticSearchImageService spyService = _initializeSpyService(elasticSearchImageService, createSucessReply, createSucessReply);
    String byteString = "Test string";
    String imageId = ImageUtils.convertBytesToMd5Hash(byteString.getBytes());
    spyService.putImage(imageId,byteString.getBytes(),true);
    ArgumentCaptor<Request> requestCaptor = ArgumentCaptor.forClass(Request.class);
    verify(restClient, times(1)).performRequest(requestCaptor.capture());
    Request capturedRequest = requestCaptor.getValue();
    String indexJson = EntityUtils.toString(capturedRequest.getEntity());
    String expectedURL = "_bulk";
    assertEquals(expectedURL, capturedRequest.getEndpoint());
    String[] lines = indexJson.split("\\r?\\n");
    ImageRecord.IndexSerializer imageIndexSerializer= new ImageRecord.IndexSerializer();
    String id = ImageUtils.convertBytesToMd5Hash(byteString.getBytes());
    ImageRecord imageRecord = new ImageRecord(id,byteString.getBytes());
    String expectedIndexName=imageIndexSerializer.getImageIndex(System.currentTimeMillis());
    String expectedDocumentId = ImageUtils.convertBytesToMd5Hash(imageRecord.getImageBytes());
    String expectedImageBlob = ImageUtils.encodeBytesToBase64(imageRecord.getImageBytes());
    JsonNode line1 = mapper.readTree(lines[0]);
    String actualIndexName = line1.get("index").get("_index").asText();
    String actualDocumentId = line1.get("index").get("_id").asText();
    assertEquals(expectedIndexName, actualIndexName);
    assertEquals(expectedDocumentId, actualDocumentId);
    JsonNode line2 = mapper.readTree(lines[1]);
    String actualImageBlob = line2.get("imageblob").asText();
    assertEquals(expectedImageBlob, actualImageBlob);
}