SW360MetaDataUpdater { public void createProject(String projectName, String projectVersion, Collection<SW360Release> releases) { Optional<String> projectId = projectClientAdapter.getProjectByNameAndVersion(projectName, projectVersion) .map(SW360HalResource::getId); String id = projectId.orElseGet(() -> projectClientAdapter.createProject(prepareNewProject(projectName, projectVersion)).getId()); projectClientAdapter.addSW360ReleasesToSW360Project(id, releases); } SW360MetaDataUpdater(SW360Connection connection); Set<SW360License> getLicenses(Collection<License> licenses); SW360Release getOrCreateRelease(SW360Release sw360ReleaseFromArtifact, boolean updateExisting); void createProject(String projectName, String projectVersion, Collection<SW360Release> releases); AttachmentUploadResult<SW360Release> uploadAttachments(SW360Release sw360Release,
                                                                  Map<Path, SW360AttachmentType> attachments,
                                                                  boolean force); SW360Release deleteSourceAttachments(SW360Release release); SW360Release deleteAttachments(SW360Release release, Predicate<SW360SparseAttachment> filter);  }
@Test public void testCreateProjectWithProjectPresent() { final String projectName = "projectName"; final String projectVersion = "projectVersion"; final String projectId = "12345"; SW360Project project = new SW360Project(); project.getLinks().setSelf(new Self("https: when(projectClientAdapter.getProjectByNameAndVersion(projectName, projectVersion)) .thenReturn(Optional.of(project)); metaDataUpdater.createProject(projectName, projectVersion, Collections.emptySet()); verify(projectClientAdapter, never()).createProject(any()); verify(projectClientAdapter, times(1)).addSW360ReleasesToSW360Project(projectId, Collections.emptySet()); }
@Test public void testCreateProjectWithProjectNotPresent() { final String projectName = "projectName"; final String projectVersion = "projectVersion"; final String projectId = "12345"; final SW360Project newProject = new SW360Project(); newProject.setName(projectName); newProject.setVersion(projectVersion); newProject.getLinks().setSelf(new Self("http: when(projectClientAdapter.getProjectByNameAndVersion(projectName, projectVersion)) .thenReturn(Optional.empty()); when(projectClientAdapter.createProject(any())) .thenReturn(newProject); metaDataUpdater.createProject(projectName, projectVersion, Collections.emptySet()); ArgumentCaptor<SW360Project> captor = ArgumentCaptor.forClass(SW360Project.class); verify(projectClientAdapter, times(1)).createProject(captor.capture()); verify(projectClientAdapter, times(1)).addSW360ReleasesToSW360Project(projectId, Collections.emptySet()); SW360Project sampleProject = captor.getValue(); assertThat(sampleProject.getName()).isEqualTo(projectName); assertThat(sampleProject.getVersion()).isEqualTo(projectVersion); assertThat(sampleProject.getDescription()).isEqualTo(projectName + " " + projectVersion); assertThat(sampleProject.getProjectType()).isEqualTo(SW360ProjectType.PRODUCT); assertThat(sampleProject.getVisibility()).isEqualTo(SW360Visibility.BUISNESSUNIT_AND_MODERATORS); }