use of com.synopsys.integration.blackduck.service.model.ProjectSyncModel in project blackduck-common by blackducksoftware.
the class UserServiceTestIT method createProjectView.
private ProjectView createProjectView() throws IntegrationException {
String projectName = "user-group-project" + System.currentTimeMillis();
ProjectSyncModel projectSyncModel = ProjectSyncModel.createWithDefaults(projectName, "test");
projectService.syncProjectAndVersion(projectSyncModel);
return projectService.getProjectByName(projectName).orElse(null);
}
use of com.synopsys.integration.blackduck.service.model.ProjectSyncModel in project blackduck-common by blackducksoftware.
the class NotificationsTestIT method testProjectNotifications.
@Test
public void testProjectNotifications() throws IntegrationException, InterruptedException {
BlackDuckServicesFactory blackDuckServicesFactory = intHttpClientTestHelper.createBlackDuckServicesFactory();
String projectName = "notifications_test_" + System.currentTimeMillis();
String projectVersionName = "notifications_test_version_" + System.currentTimeMillis();
String projectVersion2Name = "notifications_test_version2_" + System.currentTimeMillis();
BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
ProjectService projectService = blackDuckServicesFactory.createProjectService();
NotificationService notificationService = blackDuckServicesFactory.createNotificationService();
UserService userService = blackDuckServicesFactory.createUserService();
ProjectSyncModel projectSyncModel = ProjectSyncModel.createWithDefaults(projectName, projectVersionName);
ProjectSyncModel projectSyncModel2 = ProjectSyncModel.createWithDefaults(projectName, projectVersion2Name);
UserView currentUser = userService.findCurrentUser();
Date startDate = notificationService.getLatestUserNotificationDate(currentUser);
Date endDate = Date.from(startDate.toInstant().plus(1, ChronoUnit.DAYS));
List<String> notificationTypes = new ArrayList<>();
notificationTypes.add(NotificationType.PROJECT.name());
notificationTypes.add(NotificationType.PROJECT_VERSION.name());
// CREATE
ProjectVersionWrapper projectVersionWrapper = projectService.syncProjectAndVersion(projectSyncModel);
ProjectVersionWrapper projectVersionWrapper2 = projectService.syncProjectAndVersion(projectSyncModel2, true);
// DELETE
blackDuckApiClient.delete(projectVersionWrapper2.getProjectVersionView());
blackDuckApiClient.delete(projectVersionWrapper.getProjectView());
// two project version create
// one project version delete, one project delete
Set<String> expectedKeys = new HashSet(Arrays.asList("CREATE" + projectVersionName, "CREATE" + projectVersion2Name, "DELETE" + projectName, "DELETE" + projectVersion2Name));
Set<String> foundKeys = new HashSet<>();
long start = System.currentTimeMillis();
long duration = 0;
while ((foundKeys.size() < expectedKeys.size()) && duration < FIVE_MINUTES) {
NotificationEditor notificationEditor = new NotificationEditor(startDate, endDate, notificationTypes);
List<NotificationUserView> notifications = notificationService.getAllUserNotifications(currentUser, notificationEditor);
for (NotificationUserView notificationUserView : notifications) {
if (notificationUserView instanceof ProjectNotificationUserView) {
ProjectNotificationContent content = ((ProjectNotificationUserView) notificationUserView).getContent();
if (projectName.equals(content.getProjectName())) {
foundKeys.add(content.getOperationType() + content.getProjectName());
}
} else if (notificationUserView instanceof ProjectVersionNotificationUserView) {
ProjectVersionNotificationContent content = ((ProjectVersionNotificationUserView) notificationUserView).getContent();
if (projectName.equals(content.getProjectName())) {
foundKeys.add(content.getOperationType() + content.getProjectVersionName());
}
}
}
Thread.sleep(2000);
duration = System.currentTimeMillis() - start;
}
assertEquals(expectedKeys, foundKeys);
}
use of com.synopsys.integration.blackduck.service.model.ProjectSyncModel in project blackduck-common by blackducksoftware.
the class ProjectBomServiceTestIT method testAddingProjectVersionToBom.
@Test
public void testAddingProjectVersionToBom() throws Exception {
String projectName = "adding_project_version_test";
String projectVersionName = "1.0.0";
String projectNameToAdd = "to_add_project";
String projectVersionNameToAdd = "to_add_project_version";
BlackDuckServicesFactory blackDuckServicesFactory = intHttpClientTestHelper.createBlackDuckServicesFactory();
BlackDuckApiClient blackDuckApiClient = blackDuckServicesFactory.getBlackDuckApiClient();
ProjectService projectService = blackDuckServicesFactory.createProjectService();
ProjectBomService projectBomService = blackDuckServicesFactory.createProjectBomService();
IntLogger logger = blackDuckServicesFactory.getLogger();
// delete the projects, if they exist
intHttpClientTestHelper.deleteIfProjectExists(logger, projectService, blackDuckApiClient, projectName);
// as this might have been previously added to a bom, it might still register as in use - try a few times
int count = 0;
boolean succeeded = false;
while (count < 10 && !succeeded) {
try {
intHttpClientTestHelper.deleteIfProjectExists(logger, projectService, blackDuckApiClient, projectNameToAdd);
succeeded = true;
} catch (Exception ignored) {
// ignored
}
count++;
}
// create the projects
ProjectSyncModel projectSyncModel = ProjectSyncModel.createWithDefaults(projectName, projectVersionName);
ProjectVersionWrapper projectVersionWrapper = projectService.syncProjectAndVersion(projectSyncModel);
ProjectSyncModel projectSyncModelToAdd = ProjectSyncModel.createWithDefaults(projectNameToAdd, projectVersionNameToAdd);
ProjectVersionWrapper projectVersionWrapperToAdd = projectService.syncProjectAndVersion(projectSyncModelToAdd);
// verify the boms
List<ProjectVersionComponentVersionView> bomComponents = projectBomService.getComponentsForProjectVersion(projectVersionWrapper.getProjectVersionView());
assertEquals(0, bomComponents.size());
projectBomService.addProjectVersionToProjectVersion(projectVersionWrapperToAdd.getProjectVersionView(), projectVersionWrapper.getProjectVersionView());
bomComponents = projectBomService.getComponentsForProjectVersion(projectVersionWrapper.getProjectVersionView());
assertEquals(1, bomComponents.size());
}
use of com.synopsys.integration.blackduck.service.model.ProjectSyncModel in project blackduck-common by blackducksoftware.
the class BdioUploadRecipeTest method testBdioUploadAndMapToVersion.
@Test
public void testBdioUploadAndMapToVersion() throws InterruptedException, IntegrationException {
assertCodeLocationDoesNotExist();
File file = BasicRecipe.restConnectionTestHelper.getFile("bdio/hub_common_bdio_without_project_section.jsonld");
// in this case we upload the bdio but we have to map it to a project and version ourselves since the Project information is missing in the bdio file
IntLogger logger = new BufferedIntLogger();
UploadBatchRunner uploadBatchRunner = new UploadBatchRunner(logger, blackDuckApiClient, apiDiscovery, BlackDuckServicesFactory.NO_THREAD_EXECUTOR_SERVICE);
UploadBatch uploadBatch = new UploadBatch();
uploadBatch.addUploadTarget(UploadTarget.createDefault(projectAndVersion, codeLocationName, file));
BdioUploadCodeLocationCreationRequest scanRequest = new BdioUploadCodeLocationCreationRequest(uploadBatchRunner, uploadBatch);
codeLocationCreationService.createCodeLocations(scanRequest);
// now that the file is uploaded, we want to lookup the code location that was created by the upload. in this case we know the name of the code location that was specified in the bdio file
Optional<CodeLocationView> optionalCodeLocationView = codeLocationService.getCodeLocationByName(codeLocationName);
int maxAttempts = 6;
int attempt = 0;
while (!optionalCodeLocationView.isPresent() && attempt < maxAttempts) {
// creating the code location can take a few seconds
attempt++;
Thread.sleep(5000);
optionalCodeLocationView = codeLocationService.getCodeLocationByName(codeLocationName);
}
CodeLocationView codeLocationView = optionalCodeLocationView.get();
// then we map the code location to a version
String versionName = "27.0.0-SNAPSHOT";
ProjectSyncModel projectSyncModel = ProjectSyncModel.createWithDefaults(projectAndVersion);
projectService.createProject(projectSyncModel.createProjectRequest());
projectVersionWrapper = projectService.getProjectVersion(projectAndVersion);
List<CodeLocationView> versionCodeLocations = blackDuckApiClient.getAllResponses(projectVersionWrapper.get().getProjectVersionView().metaCodelocationsLink());
assertTrue(versionCodeLocations.isEmpty());
NotificationTaskRange notificationTaskRange = codeLocationCreationService.calculateCodeLocationRange();
System.out.println(RestConstants.formatDate(notificationTaskRange.getStartDate()));
System.out.println(RestConstants.formatDate(notificationTaskRange.getEndDate()));
codeLocationService.mapCodeLocation(codeLocationView, projectVersionWrapper.get().getProjectVersionView());
CodeLocationWaitResult waitResult = codeLocationCreationService.waitForCodeLocations(notificationTaskRange, projectAndVersion, new HashSet<>(Arrays.asList(codeLocationView.getName())), 1, 3 * 60);
System.out.println("wait status: " + waitResult.getStatus());
if (waitResult.getErrorMessage().isPresent()) {
System.out.println(waitResult.getErrorMessage().get());
}
waitResult.getCodeLocationNames().stream().forEach(System.out::println);
assertEquals(CodeLocationWaitResult.Status.COMPLETE, waitResult.getStatus());
assertEquals(1, waitResult.getCodeLocationNames().size());
assertTrue(waitResult.getCodeLocationNames().contains(codeLocationName));
versionCodeLocations = blackDuckApiClient.getAllResponses(projectVersionWrapper.get().getProjectVersionView().metaCodelocationsLink());
CodeLocationView versionCodeLocation = versionCodeLocations.get(0);
assertEquals(codeLocationName, versionCodeLocation.getName());
}
use of com.synopsys.integration.blackduck.service.model.ProjectSyncModel in project synopsys-detect by blackducksoftware.
the class BlackDuckAssertions method emptyOnBlackDuck.
public ProjectVersionWrapper emptyOnBlackDuck() throws IntegrationException {
Optional<ProjectVersionWrapper> optionalProjectVersionWrapper = projectService.getProjectVersion(projectNameVersion);
if (optionalProjectVersionWrapper.isPresent()) {
blackDuckApiClient.delete(optionalProjectVersionWrapper.get().getProjectView());
}
ProjectSyncModel projectSyncModel = ProjectSyncModel.createWithDefaults(projectNameVersion);
projectService.syncProjectAndVersion(projectSyncModel);
optionalProjectVersionWrapper = projectService.getProjectVersion(projectNameVersion);
assertTrue(optionalProjectVersionWrapper.isPresent());
List<CodeLocationView> codeLocations = blackDuckApiClient.getAllResponses(optionalProjectVersionWrapper.get().getProjectVersionView().metaCodelocationsLink());
assertEquals(0, codeLocations.size());
List<ProjectVersionComponentVersionView> bomComponents = projectBomService.getComponentsForProjectVersion(optionalProjectVersionWrapper.get().getProjectVersionView());
assertEquals(0, bomComponents.size());
return optionalProjectVersionWrapper.get();
}
Aggregations