@Test public void testImportOnEmptyDb() throws Exception { FluentIterable<ComponentCSVRecord> compCSVRecords = getCompCSVRecordsFromTestFile(fileName); assertThat(componentClient.getComponentSummary(user), is(empty())); assertThat(componentClient.getReleaseSummary(user), is(empty())); ComponentImportUtils.writeToDatabase( compCSVRecords, componentClient, vendorClient, attachmentClient, user); assertExpectedComponentsInDb(); final String attachmentContentId = getCreatedAttachmentContentId(); final AttachmentContent overwriter = new AttachmentContent() .setId(OVERRIDING_ID) .setOnlyRemote(true) .setRemoteUrl(REMOTE_URL) .setType(TYPE_ATTACHMENT); final AttachmentContent addition = new AttachmentContent() .setId(ADDITIONAL_ID) .setOnlyRemote(true) .setRemoteUrl(REMOTE_URL) .setType(TYPE_ATTACHMENT); attachmentRepository.add(overwriter); attachmentRepository.add(addition); assertThat(attachmentRepository.getAll(), Matchers.hasSize(3)); FluentIterable<ComponentAttachmentCSVRecord> compAttachmentCSVRecords = getCompAttachmentCSVRecordsFromTestFile(attachmentsFilename); ComponentImportUtils.writeAttachmentsToDatabase( compAttachmentCSVRecords, user, componentClient, attachmentClient); try { attachmentClient.getAttachmentContent(attachmentContentId); fail("Expected exception not thrown"); } catch (Exception e) { assertThat(e, is(instanceOf(SW360Exception.class))); assertThat( ((SW360Exception) e).getWhy(), is("Cannot find " + attachmentContentId + " in database.")); } assertThat(attachmentRepository.getAll(), Matchers.hasSize(2)); final AttachmentContent attachmentContent = attachmentClient.getAttachmentContent(getCreatedAttachmentContentId()); assertThat(attachmentContent, is(overwriter)); }
@Test public void testImportTwiceWithOnlyAPart() throws Exception { FluentIterable<ComponentCSVRecord> compCSVRecords = getCompCSVRecordsFromTestFile(fileName); ComponentImportUtils.writeToDatabase( compCSVRecords.limit(1), componentClient, vendorClient, attachmentClient, user); assertThat(componentClient.getComponentSummary(user), hasSize(1)); List<Release> releaseSummary = componentClient.getReleaseSummary(user); assertThat(releaseSummary, hasSize(1)); assertThat(releaseSummary.get(0).getName(), is("7-Zip")); ComponentImportUtils.writeToDatabase( compCSVRecords, componentClient, vendorClient, attachmentClient, user); assertExpectedComponentsInDb(); }
@Test public void testImportTwiceIsANoOp() throws Exception { FluentIterable<ComponentCSVRecord> compCSVRecords = getCompCSVRecordsFromTestFile(fileName); assertThat(componentClient.getComponentSummary(user), hasSize(0)); assertThat(componentClient.getReleaseSummary(user), hasSize(0)); assertThat(attachmentRepository.getAll(), Matchers.hasSize(0)); ComponentImportUtils.writeToDatabase( compCSVRecords, componentClient, vendorClient, attachmentClient, user); assertThat(attachmentRepository.getAll(), Matchers.hasSize(1)); List<Component> componentSummaryAfterFirst = componentClient.getComponentSummary(user); List<Release> releaseSummaryAfterFirst = componentClient.getReleaseSummary(user); assertExpectedComponentsInDb(); ComponentImportUtils.writeToDatabase( compCSVRecords, componentClient, vendorClient, attachmentClient, user); assertExpectedComponentsInDb(); assertThat(attachmentRepository.getAll(), Matchers.hasSize(1)); assertThat(componentClient.getComponentSummary(user), is(componentSummaryAfterFirst)); assertThat(componentClient.getReleaseSummary(user), is(releaseSummaryAfterFirst)); }