if (continuationData.getContainerResources() != null && !continuationData.getContainerResources().isEmpty()) { for (ContainerResource resource : continuationData.getContainerResources()) { copyHelper(jobId, exportAuthData, importAuthData, Optional.of(new ExportInformation(null, resource)));
@Test public void exportSubsequentPage() throws IOException { setUpSinglePersonResponse(); // Looking at a subsequent page, with no pages after it PaginationData paginationData = new StringPaginationToken(NEXT_PAGE_TOKEN); ExportInformation exportInformation = new ExportInformation(paginationData, null); listConnectionsResponse.setNextPageToken(null); when(listConnectionsRequest.setPageToken(NEXT_PAGE_TOKEN)).thenReturn(listConnectionsRequest); // Run test ExportResult<ContactsModelWrapper> result = contactsService.export(UUID.randomUUID(), null, Optional.of(exportInformation)); // Verify correct calls were made - i.e., token was added before execution InOrder inOrder = Mockito.inOrder(listConnectionsRequest); inOrder.verify(listConnectionsRequest).setPageToken(NEXT_PAGE_TOKEN); inOrder.verify(listConnectionsRequest).execute(); // Check continuation data ContinuationData continuationData = (ContinuationData) result.getContinuationData(); assertThat(continuationData.getContainerResources()).isEmpty(); assertThat(continuationData.getPaginationData()).isNull(); }
@Test public void exportFirstPage() throws IOException { setUpSinglePersonResponse(); // Looking at first page, with at least one page after it listConnectionsResponse.setNextPageToken(NEXT_PAGE_TOKEN); ExportResult<ContactsModelWrapper> result = contactsService.export(UUID.randomUUID(), null, Optional.empty()); // Check that correct methods were called verify(connections).list(SELF_RESOURCE); InOrder inOrder = Mockito.inOrder(getBatchGet); inOrder.verify(getBatchGet).setResourceNames(Collections.singletonList(RESOURCE_NAME)); inOrder.verify(getBatchGet).setPersonFields(PERSON_FIELDS); inOrder.verify(getBatchGet).execute(); // Check continuation data ContinuationData continuationData = (ContinuationData) result.getContinuationData(); assertThat(continuationData.getContainerResources()).isEmpty(); StringPaginationToken paginationToken = (StringPaginationToken) ((ContinuationData) result.getContinuationData()).getPaginationData(); assertThat(paginationToken.getToken()).isEqualTo(NEXT_PAGE_TOKEN); // Check that the right number of VCards was returned JCardReader reader = new JCardReader(result.getExportedData().getVCards()); List<VCard> vCardList = reader.readAll(); assertThat(vCardList.size()).isEqualTo(connectionsList.size()); }
assertThat(actualPhotos).isEmpty(); List<ContainerResource> actualResources = continuationData.getContainerResources(); assertThat( actualResources
.isEqualTo(page + 1); Collection<? extends ContainerResource> subResources = continuationData.getContainerResources(); assertThat(subResources.size()).isEqualTo(1); assertThat(subResources).containsExactly(new IdOnlyContainerResource("photosetId"));
assertThat(actualEvents).isEmpty(); List<ContainerResource> actualResources = continuationData.getContainerResources(); assertThat( actualResources
assertThat(continuationData.getContainerResources()).isEmpty(); assertThat(((IntPaginationToken) continuationData.getPaginationData()).getStart()) .isEqualTo(page + 1);
@Test public void verifySerializeDeserialize() throws Exception { ObjectMapper objectMapper = new ObjectMapper(); objectMapper.registerSubtypes( ContinuationData.class, IntPaginationToken.class, IdOnlyContainerResource.class); ContinuationData continuationData = new ContinuationData(new IntPaginationToken(100)); continuationData.addContainerResource(new IdOnlyContainerResource("123")); String serialized = objectMapper.writeValueAsString(continuationData); ContinuationData deserialized = objectMapper.readValue(serialized, ContinuationData.class); Assert.assertNotNull(deserialized); Assert.assertEquals(100, ((IntPaginationToken) deserialized.getPaginationData()).getStart()); Assert.assertEquals( "123", ((IdOnlyContainerResource) deserialized.getContainerResources().get(0)).getId()); } }
@Test public void testExportAlbum() { ExportResult<PhotosContainerResource> result = facebookPhotosExporter.export( uuid, new TokensAndUrlAuthData("accessToken", null, null), Optional.empty()); assertEquals(ExportResult.ResultType.CONTINUE, result.getType()); PhotosContainerResource exportedData = result.getExportedData(); assertEquals(1, exportedData.getAlbums().size()); assertEquals( new PhotoAlbum(ALBUM_ID, ALBUM_NAME, ALBUM_DESCRIPTION), exportedData.getAlbums().toArray()[0]); assertNull(result.getContinuationData().getPaginationData()); assertThat(result.getContinuationData().getContainerResources()) .contains(new IdOnlyContainerResource(ALBUM_ID)); }
@Test public void testSpecifiedAlbums() { ExportResult<PhotosContainerResource> result = facebookPhotosExporter.export( uuid, new TokensAndUrlAuthData("accessToken", null, null), Optional.of( new ExportInformation( new StringPaginationToken(PHOTO_TOKEN_PREFIX), new PhotosContainerResource( Lists.newArrayList(new PhotoAlbum(ALBUM_ID, ALBUM_NAME, ALBUM_DESCRIPTION)), new ArrayList<>())))); assertEquals(ExportResult.ResultType.CONTINUE, result.getType()); PhotosContainerResource exportedData = result.getExportedData(); assertEquals(1, exportedData.getAlbums().size()); assertEquals( new PhotoAlbum(ALBUM_ID, ALBUM_NAME, ALBUM_DESCRIPTION), exportedData.getAlbums().toArray()[0]); assertNull((result.getContinuationData().getPaginationData())); assertThat(result.getContinuationData().getContainerResources()) .contains(new IdOnlyContainerResource(ALBUM_ID)); }