@Override
  public ImportResult importItem(UUID jobId, IdempotentImportExecutor idempotentImportExecutor,
      TokensAndUrlAuthData authData, MediaContainerResource resource) throws Exception {
    // Ensure credential is populated
    getOrCreateCredential(authData);

    logDebugJobStatus("%s before transmogrification", jobId, resource);

    // Make the data onedrive compatible
    resource.transmogrify(transmogrificationConfig);

    logDebugJobStatus("%s after transmogrification", jobId, resource);

    for (MediaAlbum album : resource.getAlbums()) {
      // Create a OneDrive folder and then save the id with the mapping data
      idempotentImportExecutor.executeAndSwallowIOExceptions(
          album.getId(), album.getName(), () -> createOneDriveFolder(album));
    }

    executeIdempotentImport(jobId, idempotentImportExecutor, resource.getVideos());

    executeIdempotentImport(jobId, idempotentImportExecutor, resource.getPhotos());

    return ImportResult.OK;
  }
@Test
  public void testImportItemAllSuccess() throws Exception {
    List<MediaAlbum> albums =
        ImmutableList.of(new MediaAlbum("id1", "albumb1", "This is a fake albumb"));

    List<PhotoModel> photos = ImmutableList.of(
        new PhotoModel("Pic1", "http://fake.com/1.jpg", "A pic", "image/jpg", "p1", "id1", true),
        new PhotoModel(
            "Pic2", "https://fake.com/2.png", "fine art", "image/png", "p2", "id1", true));
    when(jobStore.getStream(uuid, "http://fake.com/1.jpg"))
        .thenReturn(new InputStreamWrapper(new ByteArrayInputStream(new byte[CHUNK_SIZE])));
    when(jobStore.getStream(uuid, "https://fake.com/2.png"))
        .thenReturn(new InputStreamWrapper(new ByteArrayInputStream(new byte[CHUNK_SIZE])));
    MediaContainerResource data = new MediaContainerResource(albums, photos, null /*videos*/);

    Call call = mock(Call.class);
    doReturn(call).when(client).newCall(
        argThat((Request r)
            -> r.url().toString().equals(
            "https://www.baseurl.com/v1.0/me/drive/special/photos/children")));
    Response response = mock(Response.class);
    ResponseBody body = mock(ResponseBody.class);
    when(body.bytes())
        .thenReturn(
            ResponseBody.create(MediaType.parse("application/json"), "{\"id\": \"id1\"}").bytes());
    when(body.string())
        .thenReturn(
            ResponseBody.create(MediaType.parse("application/json"), "{\"id\": \"id1\"}").string());
    when(response.code()).thenReturn(200);
    when(response.body()).thenReturn(body);
    when(call.execute()).thenReturn(response);

    Call call2 = mock(Call.class);
    doReturn(call2).when(client).newCall(
        argThat((Request r) -> r.url().toString().contains("createUploadSession")));
    Response response2 = mock(Response.class);
    ResponseBody body2 = mock(ResponseBody.class);
    when(body2.bytes())
        .thenReturn(ResponseBody
            .create(MediaType.parse("application/json"),
                "{\"uploadUrl\": \"https://scalia.com/link\"}")
            .bytes());
    when(body2.string())
        .thenReturn(ResponseBody
            .create(MediaType.parse("application/json"),
                "{\"uploadUrl\": \"https://scalia.com/link\"}")
            .string());
    when(response2.code()).thenReturn(200);
    when(response2.body()).thenReturn(body2);
    when(call2.execute()).thenReturn(response2);

    Call call3 = mock(Call.class);
    doReturn(call3).when(client).newCall(
        argThat((Request r) -> r.url().toString().contains("scalia.com/link")));
    Response response3 = mock(Response.class);
    ResponseBody body3 = mock(ResponseBody.class);
    when(body3.bytes())
        .thenReturn(ResponseBody.create(MediaType.parse("application/json"), "{\"id\": \"rand1\"}")
            .bytes());
    when(body3.string())
        .thenReturn(ResponseBody.create(MediaType.parse("application/json"), "{\"id\": \"rand1\"}")
            .string());
    when(response3.code()).thenReturn(200);
    when(response3.body()).thenReturn(body3);
    when(call3.execute()).thenReturn(response3);

    ImportResult result = importer.importItem(uuid, executor, authData, data);
    verify(client, times(5)).newCall(any());
    assertThat(result).isEqualTo(ImportResult.OK);
  }