use of org.finos.legend.sdlc.domain.model.project.ProjectType 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.ProjectType 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.ProjectType 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.ProjectType in project legend-sdlc by finos.
the class ProjectCreationConfiguration method toString.
@Override
public String toString() {
StringBuilder builder = new StringBuilder("<ProjectCreationConfiguration defaultProjectStructureVersion=").append(this.defaultProjectStructureVersion).append(" groupIdPattern=").append(this.groupIdPattern).append(" artifactIdPattern=").append(this.artifactIdPattern).append(" disallowedTypes=[");
boolean first = true;
for (ProjectType type : this.disallowedTypes) {
if (first) {
first = false;
} else {
builder.append(", ");
}
builder.append(type);
String message = this.disallowedTypeMessages.get(type);
if (message != null) {
builder.append(" (\"").append(message).append("\")");
}
}
builder.append("]>");
return builder.toString();
}
use of org.finos.legend.sdlc.domain.model.project.ProjectType in project legend-sdlc by finos.
the class GitLabApiWithFileAccess method getProjectConfiguration.
protected ProjectConfiguration getProjectConfiguration(String projectId, String workspaceId, String revisionId, WorkspaceType workspaceType, ProjectFileAccessProvider.WorkspaceAccessType workspaceAccessType) {
ProjectConfiguration config = ProjectStructure.getProjectConfiguration(projectId, workspaceId, revisionId, getProjectFileAccessProvider(), workspaceType, workspaceAccessType);
if (config == null) {
ProjectType projectType = getProjectTypeFromMode(GitLabProjectId.getGitLabMode(projectId));
config = ProjectStructure.getDefaultProjectConfiguration(projectId, projectType);
}
return config;
}
Aggregations