use of org.finos.legend.sdlc.domain.model.project.workspace.Workspace in project legend-sdlc by finos.
the class InMemoryWorkspaceApi method getWorkspaces.
@Override
public List<Workspace> getWorkspaces(String projectId, Set<WorkspaceType> workspaceTypes) {
InMemoryProject inMemoryProject = this.backend.getProject(projectId);
List<Workspace> result = Lists.mutable.empty();
if (workspaceTypes.contains(WorkspaceType.GROUP)) {
result.addAll(Lists.mutable.withAll(inMemoryProject.getGroupWorkspaces()));
}
if (workspaceTypes.contains(WorkspaceType.USER)) {
result.addAll(Lists.mutable.withAll(inMemoryProject.getUserWorkspaces()));
}
return result;
}
use of org.finos.legend.sdlc.domain.model.project.workspace.Workspace in project legend-sdlc by finos.
the class GitLabComparisonApiTestResource method runGroupWorkspaceComparisonTest.
public void runGroupWorkspaceComparisonTest() {
String projectName = "ComparisonTestProjectTwo";
String description = "A test project.";
ProjectType projectType = ProjectType.PRODUCTION;
String groupId = "org.finos.sdlc.test";
String artifactId = "comptestprojtwo";
List<String> tags = Lists.mutable.with("doe", "moffitt", AbstractGitLabServerApiTest.INTEGRATION_TEST_PROJECT_TAG);
String workspaceOneId = "testworkspaceone";
Project createdProject = gitLabProjectApi.createProject(projectName, description, projectType, groupId, artifactId, tags);
Assert.assertNotNull(createdProject);
Assert.assertEquals(projectName, createdProject.getName());
Assert.assertEquals(description, createdProject.getDescription());
Assert.assertEquals(projectType, createdProject.getProjectType());
Assert.assertEquals(Sets.mutable.withAll(tags), Sets.mutable.withAll(createdProject.getTags()));
String projectId = createdProject.getProjectId();
Workspace createdWorkspaceOne = gitLabWorkspaceApi.newGroupWorkspace(projectId, workspaceOneId);
Revision fromRevision = gitLabRevisionApi.getGroupWorkspaceRevisionContext(projectId, workspaceOneId).getCurrentRevision();
Assert.assertNotNull(createdWorkspaceOne);
Assert.assertEquals(workspaceOneId, createdWorkspaceOne.getWorkspaceId());
Assert.assertEquals(projectId, createdWorkspaceOne.getProjectId());
Assert.assertNull(createdWorkspaceOne.getUserId());
String entityPath = "test::entity";
String classifierPath = "meta::test::mathematicsDepartment";
Map<String, String> entityContentMap = Maps.mutable.with("package", "test", "name", "entity", "math-113", "abstract-algebra", "math-185", "complex-analysis");
gitLabEntityApi.getGroupWorkspaceEntityModificationContext(projectId, workspaceOneId).createEntity(entityPath, classifierPath, entityContentMap, "initial entity");
List<Entity> modifiedWorkspaceEntities = gitLabEntityApi.getGroupWorkspaceEntityAccessContext(projectId, workspaceOneId).getEntities(null, null, null);
Assert.assertNotNull(modifiedWorkspaceEntities);
Assert.assertEquals(1, modifiedWorkspaceEntities.size());
Entity initalEntity = modifiedWorkspaceEntities.get(0);
Assert.assertEquals(initalEntity.getPath(), entityPath);
Assert.assertEquals(initalEntity.getClassifierPath(), classifierPath);
Assert.assertEquals(initalEntity.getContent(), entityContentMap);
Revision toRevision = gitLabRevisionApi.getGroupWorkspaceRevisionContext(projectId, workspaceOneId).getCurrentRevision();
List<EntityDiff> entityDiffs = gitLabComparisonApi.getGroupWorkspaceCreationComparison(projectId, workspaceOneId).getEntityDiffs();
String fromRevisionId = gitLabComparisonApi.getGroupWorkspaceCreationComparison(projectId, workspaceOneId).getFromRevisionId();
String toRevisionId = gitLabComparisonApi.getGroupWorkspaceCreationComparison(projectId, workspaceOneId).getToRevisionId();
Assert.assertNotNull(fromRevision);
Assert.assertNotNull(toRevision);
Assert.assertEquals(fromRevision.getId(), fromRevisionId);
Assert.assertEquals(toRevision.getId(), toRevisionId);
Assert.assertNotNull(entityDiffs);
Assert.assertEquals(1, entityDiffs.size());
Assert.assertEquals(EntityChangeType.CREATE, entityDiffs.get(0).getEntityChangeType());
Revision projectFromRevision = gitLabRevisionApi.getProjectRevisionContext(projectId).getCurrentRevision();
Revision projectToRevision = gitLabRevisionApi.getGroupWorkspaceRevisionContext(projectId, workspaceOneId).getCurrentRevision();
List<EntityDiff> projectEntityDiffs = gitLabComparisonApi.getGroupWorkspaceProjectComparison(projectId, workspaceOneId).getEntityDiffs();
String projectFromRevisionId = gitLabComparisonApi.getGroupWorkspaceProjectComparison(projectId, workspaceOneId).getFromRevisionId();
String projectToRevisionId = gitLabComparisonApi.getGroupWorkspaceProjectComparison(projectId, workspaceOneId).getToRevisionId();
Assert.assertNotNull(projectFromRevision);
Assert.assertEquals(projectFromRevision.getId(), projectFromRevisionId);
Assert.assertEquals(projectToRevision.getId(), projectToRevisionId);
Assert.assertNotNull(projectEntityDiffs);
Assert.assertEquals(1, projectEntityDiffs.size());
Assert.assertEquals(EntityChangeType.CREATE, projectEntityDiffs.get(0).getEntityChangeType());
}
use of org.finos.legend.sdlc.domain.model.project.workspace.Workspace in project legend-sdlc by finos.
the class GitLabEntityApiTestResource method runEntitiesInNormalGroupWorkspaceWorkflowTest.
public void runEntitiesInNormalGroupWorkspaceWorkflowTest() throws GitLabApiException {
String projectName = "CommitFlowTestProjectTwo";
String description = "A test project.";
ProjectType projectType = ProjectType.PRODUCTION;
String groupId = "org.finos.sdlc.test";
String artifactId = "entitytestprojtwo";
List<String> tags = Lists.mutable.with("doe", "moffitt", AbstractGitLabServerApiTest.INTEGRATION_TEST_PROJECT_TAG);
String workspaceName = "entitytestworkspace";
Project createdProject = gitLabProjectApi.createProject(projectName, description, projectType, groupId, artifactId, tags);
String projectId = createdProject.getProjectId();
Workspace createdWorkspace = gitLabWorkspaceApi.newGroupWorkspace(projectId, workspaceName);
String workspaceId = createdWorkspace.getWorkspaceId();
List<Entity> initialWorkspaceEntities = gitLabEntityApi.getGroupWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null);
List<Entity> initialProjectEntities = gitLabEntityApi.getProjectEntityAccessContext(projectId).getEntities(null, null, null);
Assert.assertEquals(Collections.emptyList(), initialWorkspaceEntities);
Assert.assertEquals(Collections.emptyList(), initialProjectEntities);
String entityPath = "test::entity";
String classifierPath = "meta::test::mathematicsDepartment";
Map<String, String> entityContentMap = Maps.mutable.with("package", "test", "name", "entity", "math-113", "abstract-algebra", "math-185", "complex-analysis");
gitLabEntityApi.getGroupWorkspaceEntityModificationContext(projectId, workspaceId).createEntity(entityPath, classifierPath, entityContentMap, "initial entity");
List<Entity> modifiedWorkspaceEntities = gitLabEntityApi.getGroupWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null);
List<Entity> modifiedProjectEntities = gitLabEntityApi.getProjectEntityAccessContext(projectId).getEntities(null, null, null);
Assert.assertNotNull(modifiedWorkspaceEntities);
Assert.assertEquals(Collections.emptyList(), modifiedProjectEntities);
Assert.assertEquals(1, modifiedWorkspaceEntities.size());
Entity initalEntity = modifiedWorkspaceEntities.get(0);
Assert.assertEquals(initalEntity.getPath(), entityPath);
Assert.assertEquals(initalEntity.getClassifierPath(), classifierPath);
Assert.assertEquals(initalEntity.getContent(), entityContentMap);
Map<String, String> newEntityContentMap = Maps.mutable.with("package", "test", "name", "entity", "math-128", "numerical-analysis", "math-110", "linear-algebra");
gitLabEntityApi.getGroupWorkspaceEntityModificationContext(projectId, workspaceId).updateEntity(entityPath, classifierPath, newEntityContentMap, "update entity");
List<Entity> updatedWorkspaceEntities = gitLabEntityApi.getGroupWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null);
Assert.assertNotNull(updatedWorkspaceEntities);
Assert.assertEquals(1, updatedWorkspaceEntities.size());
Entity updatedEntity = updatedWorkspaceEntities.get(0);
Assert.assertEquals(updatedEntity.getPath(), entityPath);
Assert.assertEquals(updatedEntity.getClassifierPath(), classifierPath);
Assert.assertEquals(updatedEntity.getContent(), newEntityContentMap);
String entityPathTwo = "testtwo::entitytwo";
String classifierPathTwo = "meta::test::csDepartment";
Map<String, String> newEntityContentMapTwo = Maps.mutable.with("package", "testtwo", "name", "entitytwo", "cs-194", "computational-imaging", "cs-189", "machine-learning");
gitLabEntityApi.getGroupWorkspaceEntityModificationContext(projectId, workspaceId).createEntity(entityPathTwo, classifierPathTwo, newEntityContentMapTwo, "second entity");
List<Entity> postAddWorkspaceEntities = gitLabEntityApi.getGroupWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null);
Assert.assertNotNull(postAddWorkspaceEntities);
Assert.assertEquals(2, postAddWorkspaceEntities.size());
gitLabEntityApi.getGroupWorkspaceEntityModificationContext(projectId, workspaceId).deleteEntity(entityPath, classifierPath);
List<Entity> postDeleteWorkspaceEntities = gitLabEntityApi.getGroupWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null);
Assert.assertNotNull(postDeleteWorkspaceEntities);
Assert.assertEquals(1, postDeleteWorkspaceEntities.size());
Entity remainedEntity = postDeleteWorkspaceEntities.get(0);
Assert.assertEquals(remainedEntity.getPath(), entityPathTwo);
Assert.assertEquals(remainedEntity.getClassifierPath(), classifierPathTwo);
Assert.assertEquals(remainedEntity.getContent(), newEntityContentMapTwo);
List<String> paths = gitLabEntityApi.getGroupWorkspaceEntityAccessContext(projectId, workspaceId).getEntityPaths(null, null, null);
Assert.assertNotNull(paths);
Assert.assertEquals(1, paths.size());
Assert.assertEquals(entityPathTwo, paths.get(0));
List<String> labels = Collections.singletonList("default");
Review testReview = gitLabCommitterReviewApi.createReview(projectId, workspaceId, WorkspaceType.GROUP, "Add Courses.", "add two courses", labels);
String reviewId = testReview.getId();
Review approvedReview = gitLabApproverReviewApi.approveReview(projectId, reviewId);
Assert.assertNotNull(approvedReview);
Assert.assertEquals(reviewId, approvedReview.getId());
Assert.assertEquals(ReviewState.OPEN, approvedReview.getState());
GitLabProjectId sdlcGitLabProjectId = GitLabProjectId.parseProjectId(projectId);
MergeRequestApi mergeRequestApi = gitLabMemberUserContext.getGitLabAPI(sdlcGitLabProjectId.getGitLabMode()).getMergeRequestApi();
int parsedMergeRequestId = Integer.parseInt(reviewId);
int gitlabProjectId = sdlcGitLabProjectId.getGitLabId();
String requiredStatus = "can_be_merged";
CallUntil<MergeRequest, GitLabApiException> callUntil = CallUntil.callUntil(() -> mergeRequestApi.getMergeRequest(gitlabProjectId, parsedMergeRequestId), mr -> requiredStatus.equals(mr.getMergeStatus()), 20, 1000);
if (!callUntil.succeeded()) {
throw new RuntimeException("Merge request " + approvedReview.getId() + " still does not have status \"" + requiredStatus + "\" after " + callUntil.getTryCount() + " tries");
}
LOGGER.info("Waited {} times for merge to have status \"{}\"", callUntil.getTryCount(), requiredStatus);
gitLabCommitterReviewApi.commitReview(projectId, reviewId, "add two math courses");
String requiredMergedStatus = "merged";
CallUntil<MergeRequest, GitLabApiException> callUntilMerged = CallUntil.callUntil(() -> mergeRequestApi.getMergeRequest(gitlabProjectId, parsedMergeRequestId), mr -> requiredMergedStatus.equals(mr.getState()), 10, 500);
if (!callUntilMerged.succeeded()) {
throw new RuntimeException("Merge request " + reviewId + " still does not have state \"" + requiredMergedStatus + "\" after " + callUntilMerged.getTryCount() + " tries");
}
LOGGER.info("Waited {} times for merge request to have state \"{}\"", callUntilMerged.getTryCount(), requiredMergedStatus);
RepositoryApi repositoryApi = gitLabMemberUserContext.getGitLabAPI(sdlcGitLabProjectId.getGitLabMode()).getRepositoryApi();
CallUntil<List<Branch>, GitLabApiException> callUntilBranchDeleted = CallUntil.callUntil(() -> repositoryApi.getBranches(sdlcGitLabProjectId.getGitLabId()), GitLabEntityApiTestResource::hasOnlyMasterBranch, 15, 1000);
if (!callUntilBranchDeleted.succeeded()) {
// Warn instead of throwing exception since we cannot manage time expectation on GitLab to reflect branch deletion.
LOGGER.warn("Branch is still not deleted post merge after {} tries", callUntilBranchDeleted.getTryCount());
}
LOGGER.info("Waited {} times for branch to be deleted post merge", callUntilBranchDeleted.getTryCount());
List<Entity> postCommitProjectEntities = gitLabEntityApi.getProjectEntityAccessContext(projectId).getEntities(null, null, null);
Assert.assertNotNull(postCommitProjectEntities);
Assert.assertEquals(1, postCommitProjectEntities.size());
Entity projectEntity = postCommitProjectEntities.get(0);
Assert.assertEquals(projectEntity.getPath(), entityPathTwo);
Assert.assertEquals(projectEntity.getClassifierPath(), classifierPathTwo);
Assert.assertEquals(projectEntity.getContent(), newEntityContentMapTwo);
}
use of org.finos.legend.sdlc.domain.model.project.workspace.Workspace in project legend-sdlc by finos.
the class GitLabProjectConfigurationApiTestResource method runUserAndGroupWorkspaceProjectConfigurationTest.
public void runUserAndGroupWorkspaceProjectConfigurationTest() {
String projectName = "PCTestProjectOne";
String description = "A test project.";
ProjectType projectType = ProjectType.PRODUCTION;
String groupId = "org.finos.sdlc.test";
String artifactId = "pctestprojone";
List<String> tags = Lists.mutable.with("doe", "moffitt", AbstractGitLabServerApiTest.INTEGRATION_TEST_PROJECT_TAG);
String workspaceOneId = "testworkspaceone";
String workspaceTwoId = "testworkspacetwo";
Project createdProject = gitLabProjectApi.createProject(projectName, description, projectType, groupId, artifactId, tags);
Assert.assertNotNull(createdProject);
Assert.assertEquals(projectName, createdProject.getName());
Assert.assertEquals(description, createdProject.getDescription());
Assert.assertEquals(projectType, createdProject.getProjectType());
Assert.assertEquals(Sets.mutable.withAll(tags), Sets.mutable.withAll(createdProject.getTags()));
String projectId = createdProject.getProjectId();
Workspace createdWorkspaceOne = gitLabWorkspaceApi.newUserWorkspace(projectId, workspaceOneId);
Assert.assertNotNull(createdWorkspaceOne);
Assert.assertEquals(workspaceOneId, createdWorkspaceOne.getWorkspaceId());
Assert.assertEquals(projectId, createdWorkspaceOne.getProjectId());
Assert.assertNotNull(createdWorkspaceOne.getUserId());
ProjectConfiguration projectConfiguration = gitLabProjectConfigurationApi.getUserWorkspaceProjectConfiguration(projectId, workspaceOneId);
Assert.assertNotNull(projectConfiguration);
Assert.assertTrue(projectConfiguration.getProjectId().startsWith("PROD-"));
Assert.assertEquals(projectConfiguration.getProjectType(), projectType);
Assert.assertEquals(projectConfiguration.getArtifactId(), artifactId);
Assert.assertEquals(projectConfiguration.getGroupId(), groupId);
Workspace createdWorkspaceTwo = gitLabWorkspaceApi.newGroupWorkspace(projectId, workspaceTwoId);
Assert.assertNotNull(createdWorkspaceTwo);
Assert.assertEquals(workspaceTwoId, createdWorkspaceTwo.getWorkspaceId());
Assert.assertEquals(projectId, createdWorkspaceTwo.getProjectId());
Assert.assertNull(createdWorkspaceTwo.getUserId());
ProjectConfiguration projectConfigurationTwo = gitLabProjectConfigurationApi.getGroupWorkspaceProjectConfiguration(projectId, workspaceTwoId);
Assert.assertNotNull(projectConfigurationTwo);
Assert.assertTrue(projectConfigurationTwo.getProjectId().startsWith("PROD-"));
Assert.assertEquals(projectConfigurationTwo.getProjectType(), projectType);
Assert.assertEquals(projectConfigurationTwo.getArtifactId(), artifactId);
Assert.assertEquals(projectConfigurationTwo.getGroupId(), groupId);
}
use of org.finos.legend.sdlc.domain.model.project.workspace.Workspace in project legend-sdlc by finos.
the class GitLabRevisionApiTestResource method runUserWorkspaceRevisionTest.
public void runUserWorkspaceRevisionTest() {
String projectName = "RevisionTestProjectOne";
String description = "A test project.";
ProjectType projectType = ProjectType.PRODUCTION;
String groupId = "org.finos.sdlc.test";
String artifactId = "revisiontestprojone";
List<String> tags = Lists.mutable.with("doe", "moffitt", AbstractGitLabServerApiTest.INTEGRATION_TEST_PROJECT_TAG);
String workspaceOneId = "testworkspaceone";
Project createdProject = gitLabProjectApi.createProject(projectName, description, projectType, groupId, artifactId, tags);
Assert.assertNotNull(createdProject);
Assert.assertEquals(projectName, createdProject.getName());
Assert.assertEquals(description, createdProject.getDescription());
Assert.assertEquals(projectType, createdProject.getProjectType());
Assert.assertEquals(Sets.mutable.withAll(tags), Sets.mutable.withAll(createdProject.getTags()));
String projectId = createdProject.getProjectId();
Workspace createdWorkspaceOne = gitLabWorkspaceApi.newUserWorkspace(projectId, workspaceOneId);
Assert.assertNotNull(createdWorkspaceOne);
Assert.assertEquals(workspaceOneId, createdWorkspaceOne.getWorkspaceId());
Assert.assertEquals(projectId, createdWorkspaceOne.getProjectId());
Assert.assertNotNull(createdWorkspaceOne.getUserId());
List<Revision> workspaceRevisions = gitLabRevisionApi.getUserWorkspaceRevisionContext(projectId, workspaceOneId).getRevisions();
Assert.assertNotNull(workspaceRevisions);
Assert.assertEquals(1, workspaceRevisions.size());
Revision createProjectStructureRevision = workspaceRevisions.get(0);
Assert.assertEquals("Build project structure", createProjectStructureRevision.getMessage());
Assert.assertNotNull(createProjectStructureRevision.getId());
Assert.assertNotNull(createProjectStructureRevision.getAuthorName());
Assert.assertNotNull(createProjectStructureRevision.getCommitterName());
Assert.assertNotNull(createProjectStructureRevision.getAuthoredTimestamp());
Assert.assertNotNull(createProjectStructureRevision.getCommittedTimestamp());
String entityPath = "test::entity";
String entityPackagePath = "test";
String classifierPath = "meta::test::mathematicsDepartment";
Map<String, String> entityContentMap = Maps.mutable.with("package", "test", "name", "entity", "math-113", "abstract-algebra", "math-185", "complex-analysis");
gitLabEntityApi.getUserWorkspaceEntityModificationContext(projectId, workspaceOneId).createEntity(entityPath, classifierPath, entityContentMap, "initial entity");
List<Entity> modifiedWorkspaceEntities = gitLabEntityApi.getUserWorkspaceEntityAccessContext(projectId, workspaceOneId).getEntities(null, null, null);
Assert.assertNotNull(modifiedWorkspaceEntities);
Assert.assertEquals(1, modifiedWorkspaceEntities.size());
Entity initalEntity = modifiedWorkspaceEntities.get(0);
Assert.assertEquals(initalEntity.getPath(), entityPath);
Assert.assertEquals(initalEntity.getClassifierPath(), classifierPath);
Assert.assertEquals(initalEntity.getContent(), entityContentMap);
List<Revision> updatedWorkspaceRevisions = gitLabRevisionApi.getUserWorkspaceRevisionContext(projectId, workspaceOneId).getRevisions();
Revision currentRevision = gitLabRevisionApi.getUserWorkspaceRevisionContext(projectId, workspaceOneId).getCurrentRevision();
Assert.assertNotNull(updatedWorkspaceRevisions);
Assert.assertEquals(2, updatedWorkspaceRevisions.size());
Assert.assertEquals("initial entity", currentRevision.getMessage());
Assert.assertNotNull(currentRevision.getId());
Assert.assertNotNull(currentRevision.getAuthorName());
Assert.assertNotNull(currentRevision.getCommitterName());
Assert.assertNotNull(currentRevision.getAuthoredTimestamp());
Assert.assertNotNull(currentRevision.getCommittedTimestamp());
List<Revision> entityRevisions = gitLabRevisionApi.getUserWorkspaceEntityRevisionContext(projectId, workspaceOneId, entityPath).getRevisions();
Revision currentEntityRevision = gitLabRevisionApi.getUserWorkspaceEntityRevisionContext(projectId, workspaceOneId, entityPath).getCurrentRevision();
Assert.assertNotNull(entityRevisions);
Assert.assertEquals(1, entityRevisions.size());
Assert.assertEquals("initial entity", currentEntityRevision.getMessage());
Assert.assertNotNull(currentEntityRevision.getId());
Assert.assertNotNull(currentEntityRevision.getAuthorName());
Assert.assertNotNull(currentEntityRevision.getCommitterName());
Assert.assertNotNull(currentEntityRevision.getAuthoredTimestamp());
Assert.assertNotNull(currentEntityRevision.getCommittedTimestamp());
List<Revision> packageRevisions = gitLabRevisionApi.getUserWorkspacePackageRevisionContext(projectId, workspaceOneId, entityPackagePath).getRevisions();
Revision currentPackageRevision = gitLabRevisionApi.getUserWorkspacePackageRevisionContext(projectId, workspaceOneId, entityPackagePath).getCurrentRevision();
Assert.assertNotNull(packageRevisions);
Assert.assertEquals(1, packageRevisions.size());
Assert.assertEquals("initial entity", currentPackageRevision.getMessage());
Assert.assertNotNull(currentPackageRevision.getId());
Assert.assertNotNull(currentPackageRevision.getAuthorName());
Assert.assertNotNull(currentPackageRevision.getCommitterName());
Assert.assertNotNull(currentPackageRevision.getAuthoredTimestamp());
Assert.assertNotNull(currentPackageRevision.getCommittedTimestamp());
}
Aggregations