SW360ProjectClientAdapterAsyncImpl implements SW360ProjectClientAdapterAsync { @Override public CompletableFuture<SW360Project> createProject(SW360Project project) { return validateProjectAndProcess(project, getProjectClient()::createProject); } SW360ProjectClientAdapterAsyncImpl(SW360ProjectClient client); @Override SW360ProjectClient getProjectClient(); @Override CompletableFuture<Optional<SW360Project>> getProjectByNameAndVersion(String projectName, String projectVersion); @Override CompletableFuture<List<SW360Project>> search(ProjectSearchParams params); @Override CompletableFuture<SW360Project> createProject(SW360Project project); @Override CompletableFuture<SW360Project> updateProject(SW360Project project); @Override CompletableFuture<Void> addSW360ReleasesToSW360Project(String id, Collection<SW360Release> releases); @Override CompletableFuture<List<SW360SparseRelease>> getLinkedReleases(String projectId, boolean transitive);  }
@Test public void testCreateProject() { SW360Project projectCreated = new SW360Project(); projectCreated.setName(PROJECT_NAME); projectCreated.setVersion(PROJECT_VERSION); projectCreated.setDescription("a newly created project"); when(projectClient.createProject(projectWithLink)) .thenReturn(CompletableFuture.completedFuture(projectCreated)); SW360Project result = block(projectClientAdapter.createProject(projectWithLink)); assertThat(result).isEqualTo(projectCreated); }
@Test public void testCreateProjectInvalidName() throws InterruptedException { SW360Project newProject = new SW360Project(); newProject.setVersion(PROJECT_VERSION); CompletableFuture<SW360Project> future = projectClientAdapter.createProject(newProject); try { future.get(); fail("Invalid project not detected!"); } catch (ExecutionException e) { assertThat(e.getCause()).isInstanceOf(SW360ClientException.class); assertThat(e.getCause().getMessage()).contains("invalid project"); } }