use of org.finos.legend.sdlc.domain.model.project.workspace.Workspace in project legend-sdlc by finos.
the class GitLabRevisionApiTestResource method runGroupWorkspaceRevisionTest.
public void runGroupWorkspaceRevisionTest() {
String projectName = "RevisionTestProjectTwo";
String description = "A test project.";
ProjectType projectType = ProjectType.PRODUCTION;
String groupId = "org.finos.sdlc.test";
String artifactId = "revisiontestprojtwo";
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);
Assert.assertNotNull(createdWorkspaceOne);
Assert.assertEquals(workspaceOneId, createdWorkspaceOne.getWorkspaceId());
Assert.assertEquals(projectId, createdWorkspaceOne.getProjectId());
Assert.assertNull(createdWorkspaceOne.getUserId());
List<Revision> workspaceRevisions = gitLabRevisionApi.getGroupWorkspaceRevisionContext(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.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);
List<Revision> updatedWorkspaceRevisions = gitLabRevisionApi.getGroupWorkspaceRevisionContext(projectId, workspaceOneId).getRevisions();
Revision currentRevision = gitLabRevisionApi.getGroupWorkspaceRevisionContext(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.getGroupWorkspaceEntityRevisionContext(projectId, workspaceOneId, entityPath).getRevisions();
Revision currentEntityRevision = gitLabRevisionApi.getGroupWorkspaceEntityRevisionContext(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.getGroupWorkspacePackageRevisionContext(projectId, workspaceOneId, entityPackagePath).getRevisions();
Revision currentPackageRevision = gitLabRevisionApi.getGroupWorkspacePackageRevisionContext(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());
}
use of org.finos.legend.sdlc.domain.model.project.workspace.Workspace in project legend-sdlc by finos.
the class GitLabWorkspaceApiTestResource method runUpdateGroupWorkspaceWithRebaseNoConflictTest.
public void runUpdateGroupWorkspaceWithRebaseNoConflictTest() throws GitLabApiException {
// Create new workspace from previous HEAD
String projectName = "WorkspaceTestProjectThree";
String description = "A test project.";
ProjectType projectType = ProjectType.PRODUCTION;
String groupId = "org.finos.sdlc.test";
String artifactId = "testworkprojthree";
List<String> tags = Lists.mutable.with("doe", "moffitt", AbstractGitLabServerApiTest.INTEGRATION_TEST_PROJECT_TAG);
String workspaceName = "workspaceone";
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);
// Create another workspace, commit, review, merge to move project HEAD forward -- use workspace two
String workspaceTwoName = "workspacetwo";
Workspace createdWorkspaceTwo = gitLabWorkspaceApi.newGroupWorkspace(projectId, workspaceTwoName);
String workspaceTwoId = createdWorkspaceTwo.getWorkspaceId();
List<Entity> initialWorkspaceTwoEntities = gitLabEntityApi.getGroupWorkspaceEntityAccessContext(projectId, workspaceTwoId).getEntities(null, null, null);
Assert.assertEquals(Collections.emptyList(), initialWorkspaceTwoEntities);
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, workspaceTwoId).createEntity(entityPath, classifierPath, entityContentMap, "initial entity");
List<Entity> modifiedWorkspaceEntities = gitLabEntityApi.getGroupWorkspaceEntityAccessContext(projectId, workspaceTwoId).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<String> labels = Collections.singletonList("default");
Review testReview = gitLabCommitterReviewApi.createReview(projectId, workspaceTwoId, WorkspaceType.GROUP, "Add Courses.", "add two math 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();
Integer parsedMergeRequestId = Integer.parseInt(reviewId);
Integer 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()), branches -> GitLabApiTestSetupUtil.hasOnlyBranchesWithNames(branches, Lists.mutable.of(workspaceName, "master")), 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", workspaceTwoName, callUntilBranchDeleted.getTryCount());
}
LOGGER.info("Waited {} times for branch {} to be deleted post merge", callUntilBranchDeleted.getTryCount(), workspaceTwoName);
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(), entityPath);
Assert.assertEquals(projectEntity.getClassifierPath(), classifierPath);
Assert.assertEquals(projectEntity.getContent(), entityContentMap);
// Create changes and make change in workspace branch -- use workspace
Map<String, String> currentEntityContentMap = Maps.mutable.with("package", "test", "name", "entity", "math-113", "abstract-algebra", "math-185", "complex-analysis");
gitLabEntityApi.getGroupWorkspaceEntityModificationContext(projectId, workspaceId).createEntity(entityPath, classifierPath, currentEntityContentMap, "initial entity");
List<Entity> modifiedWorkspaceEntitiesNew = gitLabEntityApi.getGroupWorkspaceEntityAccessContext(projectId, workspaceId).getEntities(null, null, null);
Assert.assertNotNull(modifiedWorkspaceEntitiesNew);
Assert.assertEquals(1, modifiedWorkspaceEntities.size());
Entity initalEntityNew = modifiedWorkspaceEntitiesNew.get(0);
Assert.assertEquals(initalEntityNew.getPath(), entityPath);
Assert.assertEquals(initalEntityNew.getClassifierPath(), classifierPath);
Assert.assertEquals(initalEntityNew.getContent(), currentEntityContentMap);
// Update workspace branch and trigger rebase
gitLabWorkspaceApi.updateGroupWorkspace(projectId, workspaceId);
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(), currentEntityContentMap);
}
use of org.finos.legend.sdlc.domain.model.project.workspace.Workspace in project legend-sdlc by finos.
the class GitLabWorkspaceApiTestResource method runUserAndGroupWorkspaceNormalWorkflowTest.
public void runUserAndGroupWorkspaceNormalWorkflowTest() {
String projectName = "WorkspaceTestProjectOne";
String description = "A test project.";
ProjectType projectType = ProjectType.PRODUCTION;
String groupId = "org.finos.sdlc.test";
String artifactId = "worktestprojone";
List<String> tags = Lists.mutable.with("doe", "moffitt", AbstractGitLabServerApiTest.INTEGRATION_TEST_PROJECT_TAG);
String workspaceOneId = "testworkspaceone";
String workspaceTwoId = "testworkspacetwo";
String workspaceThreeId = "testworkspacethree";
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());
Workspace createdWorkspaceTwo = gitLabWorkspaceApi.newUserWorkspace(projectId, workspaceTwoId);
Assert.assertNotNull(createdWorkspaceTwo);
Assert.assertEquals(workspaceTwoId, createdWorkspaceTwo.getWorkspaceId());
Assert.assertEquals(projectId, createdWorkspaceTwo.getProjectId());
Assert.assertNotNull(createdWorkspaceTwo.getUserId());
Workspace createdWorkspaceThree = gitLabWorkspaceApi.newGroupWorkspace(projectId, workspaceThreeId);
Assert.assertNotNull(createdWorkspaceThree);
Assert.assertEquals(workspaceThreeId, createdWorkspaceThree.getWorkspaceId());
Assert.assertEquals(projectId, createdWorkspaceThree.getProjectId());
Assert.assertNull(createdWorkspaceThree.getUserId());
List<Workspace> allWorkspaces = gitLabWorkspaceApi.getAllWorkspaces(projectId);
List<Workspace> allUserWorkspaces = gitLabWorkspaceApi.getAllUserWorkspaces(projectId);
List<Workspace> allGroupWorkspaces = gitLabWorkspaceApi.getGroupWorkspaces(projectId);
Assert.assertNotNull(allWorkspaces);
Assert.assertNotNull(allUserWorkspaces);
Assert.assertNotNull(allGroupWorkspaces);
Assert.assertEquals(3, allWorkspaces.size());
Assert.assertEquals(2, allUserWorkspaces.size());
Assert.assertEquals(1, allGroupWorkspaces.size());
Workspace retriedUserWorkspace = gitLabWorkspaceApi.getUserWorkspace(projectId, workspaceOneId);
Assert.assertNotNull(retriedUserWorkspace);
Assert.assertEquals(workspaceOneId, retriedUserWorkspace.getWorkspaceId());
Assert.assertEquals(projectId, retriedUserWorkspace.getProjectId());
Assert.assertNotNull(retriedUserWorkspace.getUserId());
Workspace retriedGroupWorkspace = gitLabWorkspaceApi.getGroupWorkspace(projectId, workspaceThreeId);
Assert.assertNotNull(retriedGroupWorkspace);
Assert.assertEquals(workspaceThreeId, retriedGroupWorkspace.getWorkspaceId());
Assert.assertEquals(projectId, retriedGroupWorkspace.getProjectId());
Assert.assertNull(retriedGroupWorkspace.getUserId());
boolean isUserWorkspaceInConflictResolution = gitLabWorkspaceApi.isUserWorkspaceInConflictResolutionMode(projectId, workspaceOneId);
boolean isGroupWorkspaceInConflictResolution = gitLabWorkspaceApi.isGroupWorkspaceInConflictResolutionMode(projectId, workspaceThreeId);
Assert.assertFalse(isUserWorkspaceInConflictResolution);
Assert.assertFalse(isGroupWorkspaceInConflictResolution);
boolean isUserWorkspaceOutdated = gitLabWorkspaceApi.isUserWorkspaceOutdated(projectId, workspaceOneId);
boolean isGroupWorkspaceOutdated = gitLabWorkspaceApi.isGroupWorkspaceOutdated(projectId, workspaceThreeId);
Assert.assertFalse(isUserWorkspaceOutdated);
Assert.assertFalse(isGroupWorkspaceOutdated);
}
use of org.finos.legend.sdlc.domain.model.project.workspace.Workspace in project legend-sdlc by finos.
the class TestWorkspaceEntitiesResource method testGetGroupWorkspaceEntities.
@Test
public void testGetGroupWorkspaceEntities() throws HttpResponseException {
String projectId = "A";
String workspaceOneId = "entityw2";
String entityOneName = "testentityone";
String entityTwoName = "testentitytwo";
String entityPackageName = "testpkg";
this.backend.project(projectId).addEntities(workspaceOneId, WorkspaceType.GROUP, InMemoryEntity.newEntity(entityOneName, entityPackageName), InMemoryEntity.newEntity(entityTwoName, entityPackageName));
Response responseOne = this.clientFor("/api/projects/A/groupWorkspaces/entityw2").request().get();
if (responseOne.getStatus() != 200) {
throw new HttpResponseException(responseOne.getStatus(), "Error during getting group workspace with status: " + responseOne.getStatus() + ", entity: " + responseOne.readEntity(String.class));
}
Workspace workspace = responseOne.readEntity(new GenericType<Workspace>() {
});
Assert.assertNotNull(workspace);
Assert.assertEquals(workspaceOneId, workspace.getWorkspaceId());
Assert.assertEquals(projectId, workspace.getProjectId());
Response responseTwo = this.clientFor("/api/projects/A/groupWorkspaces/entityw2/entities").request().get();
if (responseTwo.getStatus() != 200) {
throw new HttpResponseException(responseTwo.getStatus(), "Error during getting entities in group workspace with status: " + responseTwo.getStatus() + ", entity: " + responseTwo.readEntity(String.class));
}
List<Entity> entities = responseTwo.readEntity(new GenericType<List<Entity>>() {
});
Assert.assertNotNull(entities);
Assert.assertEquals(2, entities.size());
Entity entityOne = findEntity(entities, entityOneName, entityPackageName);
Entity entityTwo = findEntity(entities, entityTwoName, entityPackageName);
Assert.assertEquals(entityPackageName + "::" + entityOneName, entityOne.getPath());
Assert.assertEquals(entityPackageName + "::" + entityTwoName, entityTwo.getPath());
}
use of org.finos.legend.sdlc.domain.model.project.workspace.Workspace in project legend-sdlc by finos.
the class TestWorkspaceEntitiesResource method testGetAndUpdateGroupWorkspaceEntity.
@Test
public void testGetAndUpdateGroupWorkspaceEntity() throws HttpResponseException {
String projectId = "A";
String workspaceOneId = "entityw4";
String entityOneName = "testentityone";
String entityPackageName = "testpkg";
this.backend.project(projectId).addEntities(workspaceOneId, WorkspaceType.GROUP, InMemoryEntity.newEntity(entityOneName, entityPackageName));
Response responseOne = this.clientFor("/api/projects/A/groupWorkspaces/entityw4").request().get();
if (responseOne.getStatus() != 200) {
throw new HttpResponseException(responseOne.getStatus(), "Error during getting group workspace with status: " + responseOne.getStatus() + ", entity: " + responseOne.readEntity(String.class));
}
Workspace workspace = responseOne.readEntity(new GenericType<Workspace>() {
});
Assert.assertNotNull(workspace);
Assert.assertEquals(workspaceOneId, workspace.getWorkspaceId());
Assert.assertEquals(projectId, workspace.getProjectId());
Response responseTwo = this.clientFor("/api/projects/A/groupWorkspaces/entityw4/entities/testpkg::testentityone").request().get();
if (responseTwo.getStatus() != 200) {
throw new HttpResponseException(responseTwo.getStatus(), "Error during getting entity in group workspace with status: " + responseTwo.getStatus() + ", entity: " + responseTwo.readEntity(String.class));
}
Entity entity = responseTwo.readEntity(new GenericType<Entity>() {
});
Assert.assertNotNull(entity);
Assert.assertEquals(entityPackageName + "::" + entityOneName, entity.getPath());
Assert.assertEquals(entityPackageName, entity.getContent().get("package"));
Assert.assertEquals(entityOneName, entity.getContent().get("name"));
UpdateEntitiesCommand updateEntitiesCommand = new UpdateEntitiesCommand();
updateEntitiesCommand.setReplace(true);
Response responseThree = this.clientFor("/api/projects/A/groupWorkspaces/entityw4/entities").request().post(javax.ws.rs.client.Entity.entity(updateEntitiesCommand, MediaType.APPLICATION_JSON));
if (responseThree.getStatus() != 200) {
throw new HttpResponseException(responseThree.getStatus(), "Error during updating entity in group workspace with status: " + responseThree.getStatus() + ", entity: " + responseThree.readEntity(String.class));
}
Revision revision = responseThree.readEntity(new GenericType<Revision>() {
});
Assert.assertNotNull(revision);
Assert.assertNotNull(revision.getId());
}
Aggregations