Search in sources :

Example 16 with Revision

use of org.finos.legend.sdlc.domain.model.revision.Revision in project legend-sdlc by finos.

the class TestProjectStructure method testEntities.

protected void testEntities(ProjectType projectType) {
    buildProjectStructure(projectType);
    ProjectStructure projectStructure = ProjectStructure.getProjectStructure(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
    List<Entity> testEntities = getTestEntities();
    List<ProjectFileOperation> addEntityOperations = ListIterate.collectWith(testEntities, this::generateAddOperationForEntity, projectStructure);
    String message = "Add entities";
    Instant before = Instant.now();
    Revision revision = this.fileAccessProvider.getProjectFileModificationContext(PROJECT_ID).submit(message, addEntityOperations);
    Instant after = Instant.now();
    Assert.assertEquals(AUTHOR, revision.getAuthorName());
    Assert.assertEquals(COMMITTER, revision.getCommitterName());
    Assert.assertTrue(before.compareTo(revision.getAuthoredTimestamp()) <= 0);
    Assert.assertTrue(before.compareTo(revision.getCommittedTimestamp()) <= 0);
    Assert.assertTrue(after.compareTo(revision.getAuthoredTimestamp()) >= 0);
    Assert.assertTrue(after.compareTo(revision.getCommittedTimestamp()) >= 0);
    Assert.assertEquals(message, revision.getMessage());
    assertStateValid(PROJECT_ID, null, null);
    assertEntitiesEquivalent(testEntities, getActualEntities(PROJECT_ID));
// System.out.println("==========\nProject Structure version: " + this.projectStructureVersion + "\nProject Structure Extension version: " + this.projectStructureExtensionVersion + "\nProject type: " + projectType + "\n==========\n");
// this.fileAccessProvider.getProjectFileAccessContext(PROJECT_ID).getFiles().forEach(f -> System.out.println("==========\n" + f.getPath() + "\n==========\n" + f.getContentAsString() + "\n==========\n"));
}
Also used : Entity(org.finos.legend.sdlc.domain.model.entity.Entity) Revision(org.finos.legend.sdlc.domain.model.revision.Revision) Instant(java.time.Instant)

Example 17 with Revision

use of org.finos.legend.sdlc.domain.model.revision.Revision in project legend-sdlc by finos.

the class TestProjectStructure method testUpdateMetamodelDependencies.

protected void testUpdateMetamodelDependencies(ProjectType projectType) {
    List<MetamodelDependency> metamodelDependencies = Arrays.asList(MetamodelDependency.parseMetamodelDependency("pure:1"), MetamodelDependency.parseMetamodelDependency("tds:1"), MetamodelDependency.parseMetamodelDependency("service:1"));
    metamodelDependencies.sort(Comparator.naturalOrder());
    ProjectStructure projectStructure = buildProjectStructure(projectType);
    List<Entity> testEntities = getTestEntities();
    List<ProjectFileOperation> addEntityOperations = ListIterate.collectWith(testEntities, this::generateAddOperationForEntity, projectStructure);
    this.fileAccessProvider.getProjectFileModificationContext(PROJECT_ID).submit("Add entities", addEntityOperations);
    ProjectConfiguration beforeProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
    Assert.assertEquals(PROJECT_ID, beforeProjectConfig.getProjectId());
    Assert.assertEquals(GROUP_ID, beforeProjectConfig.getGroupId());
    Assert.assertEquals(ARTIFACT_ID, beforeProjectConfig.getArtifactId());
    Assert.assertEquals(this.projectStructureVersion, beforeProjectConfig.getProjectStructureVersion().getVersion());
    Assert.assertEquals(this.projectStructureExtensionVersion, beforeProjectConfig.getProjectStructureVersion().getExtensionVersion());
    Assert.assertEquals(Collections.emptyList(), beforeProjectConfig.getMetamodelDependencies());
    assertStateValid(PROJECT_ID, null, null);
    String addDependenciesWorkspaceId = "AddDependencies";
    this.fileAccessProvider.createWorkspace(PROJECT_ID, addDependenciesWorkspaceId);
    ProjectConfiguration beforeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
    Assert.assertEquals(PROJECT_ID, beforeWorkspaceConfig.getProjectId());
    Assert.assertEquals(GROUP_ID, beforeWorkspaceConfig.getGroupId());
    Assert.assertEquals(ARTIFACT_ID, beforeWorkspaceConfig.getArtifactId());
    Assert.assertEquals(this.projectStructureVersion, beforeWorkspaceConfig.getProjectStructureVersion().getVersion());
    Assert.assertEquals(this.projectStructureExtensionVersion, beforeWorkspaceConfig.getProjectStructureVersion().getExtensionVersion());
    Assert.assertEquals(Collections.emptyList(), beforeWorkspaceConfig.getMetamodelDependencies());
    Assert.assertEquals(Collections.emptyList(), beforeProjectConfig.getProjectDependencies());
    assertStateValid(PROJECT_ID, addDependenciesWorkspaceId, null);
    ProjectConfigurationUpdateBuilder.newBuilder(this.fileAccessProvider, projectType, PROJECT_ID).withWorkspace(addDependenciesWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE).withMessage("Add dependencies").withMetamodelDependenciesToAdd(metamodelDependencies).withProjectStructureExtensionProvider(this.projectStructureExtensionProvider).withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions).updateProjectConfiguration();
    ProjectConfiguration afterWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, addDependenciesWorkspaceId, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
    Assert.assertEquals(PROJECT_ID, afterWorkspaceConfig.getProjectId());
    Assert.assertEquals(GROUP_ID, afterWorkspaceConfig.getGroupId());
    Assert.assertEquals(ARTIFACT_ID, afterWorkspaceConfig.getArtifactId());
    Assert.assertEquals(this.projectStructureVersion, afterWorkspaceConfig.getProjectStructureVersion().getVersion());
    Assert.assertEquals(this.projectStructureExtensionVersion, afterWorkspaceConfig.getProjectStructureVersion().getExtensionVersion());
    Assert.assertEquals(metamodelDependencies, afterWorkspaceConfig.getMetamodelDependencies());
    Assert.assertEquals(Collections.emptyList(), afterWorkspaceConfig.getProjectDependencies());
    assertStateValid(PROJECT_ID, addDependenciesWorkspaceId, null);
    this.fileAccessProvider.commitWorkspace(PROJECT_ID, addDependenciesWorkspaceId);
    ProjectConfiguration afterProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
    Assert.assertEquals(PROJECT_ID, afterProjectConfig.getProjectId());
    Assert.assertEquals(GROUP_ID, afterProjectConfig.getGroupId());
    Assert.assertEquals(ARTIFACT_ID, afterProjectConfig.getArtifactId());
    Assert.assertEquals(this.projectStructureVersion, afterProjectConfig.getProjectStructureVersion().getVersion());
    Assert.assertEquals(this.projectStructureExtensionVersion, afterProjectConfig.getProjectStructureVersion().getExtensionVersion());
    Assert.assertEquals(metamodelDependencies, afterProjectConfig.getMetamodelDependencies());
    Assert.assertEquals(Collections.emptyList(), afterProjectConfig.getProjectDependencies());
    assertStateValid(PROJECT_ID, null, null);
    String noChangeWorkspaceId = "NoChangeToDependencies";
    this.fileAccessProvider.createWorkspace(PROJECT_ID, noChangeWorkspaceId);
    Revision newRevision = ProjectConfigurationUpdateBuilder.newBuilder(this.fileAccessProvider, projectType, PROJECT_ID).withWorkspace(noChangeWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE).withMessage("No change to dependencies").withGroupId("temp.group.id").withProjectStructureExtensionProvider(this.projectStructureExtensionProvider).withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions).updateProjectConfiguration();
    Assert.assertNotNull(newRevision);
    ProjectConfiguration noChangeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, noChangeWorkspaceId, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
    Assert.assertEquals(PROJECT_ID, noChangeWorkspaceConfig.getProjectId());
    Assert.assertEquals("temp.group.id", noChangeWorkspaceConfig.getGroupId());
    Assert.assertEquals(ARTIFACT_ID, noChangeWorkspaceConfig.getArtifactId());
    Assert.assertEquals(this.projectStructureVersion, noChangeWorkspaceConfig.getProjectStructureVersion().getVersion());
    Assert.assertEquals(this.projectStructureExtensionVersion, noChangeWorkspaceConfig.getProjectStructureVersion().getExtensionVersion());
    Assert.assertEquals(metamodelDependencies, noChangeWorkspaceConfig.getMetamodelDependencies());
    Assert.assertEquals(Collections.emptyList(), noChangeWorkspaceConfig.getProjectDependencies());
    assertStateValid(PROJECT_ID, noChangeWorkspaceId, null);
    this.fileAccessProvider.deleteWorkspace(PROJECT_ID, noChangeWorkspaceId);
    for (int i = 0; i < metamodelDependencies.size(); i++) {
        String removeDependencyWorkspaceId = "RemoveDependency" + 0;
        this.fileAccessProvider.createWorkspace(PROJECT_ID, removeDependencyWorkspaceId);
        ProjectConfiguration beforeRemovalConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
        Assert.assertEquals(PROJECT_ID, beforeRemovalConfig.getProjectId());
        Assert.assertEquals(GROUP_ID, beforeRemovalConfig.getGroupId());
        Assert.assertEquals(ARTIFACT_ID, beforeRemovalConfig.getArtifactId());
        Assert.assertEquals(this.projectStructureVersion, beforeRemovalConfig.getProjectStructureVersion().getVersion());
        Assert.assertEquals(this.projectStructureExtensionVersion, beforeRemovalConfig.getProjectStructureVersion().getExtensionVersion());
        Assert.assertEquals(metamodelDependencies.subList(i, metamodelDependencies.size()), beforeRemovalConfig.getMetamodelDependencies());
        Assert.assertEquals(Collections.emptyList(), beforeRemovalConfig.getProjectDependencies());
        assertStateValid(PROJECT_ID, removeDependencyWorkspaceId, null);
        ProjectConfigurationUpdateBuilder.newBuilder(this.fileAccessProvider, projectType, PROJECT_ID).withWorkspace(removeDependencyWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE).withMessage("Remove dependencies").withMetamodelDependenciesToRemove(Collections.singletonList(metamodelDependencies.get(i))).withProjectStructureExtensionProvider(this.projectStructureExtensionProvider).withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions).updateProjectConfiguration();
        ProjectConfiguration afterRemovalWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, removeDependencyWorkspaceId, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
        Assert.assertEquals(PROJECT_ID, afterRemovalWorkspaceConfig.getProjectId());
        Assert.assertEquals(GROUP_ID, afterRemovalWorkspaceConfig.getGroupId());
        Assert.assertEquals(ARTIFACT_ID, afterRemovalWorkspaceConfig.getArtifactId());
        Assert.assertEquals(this.projectStructureVersion, afterRemovalWorkspaceConfig.getProjectStructureVersion().getVersion());
        Assert.assertEquals(this.projectStructureExtensionVersion, afterRemovalWorkspaceConfig.getProjectStructureVersion().getExtensionVersion());
        Assert.assertEquals(metamodelDependencies.subList(i + 1, metamodelDependencies.size()), afterRemovalWorkspaceConfig.getMetamodelDependencies());
        Assert.assertEquals(Collections.emptyList(), afterRemovalWorkspaceConfig.getProjectDependencies());
        assertStateValid(PROJECT_ID, removeDependencyWorkspaceId, null);
        this.fileAccessProvider.commitWorkspace(PROJECT_ID, removeDependencyWorkspaceId);
        ProjectConfiguration afterRemovalProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
        Assert.assertEquals(PROJECT_ID, afterRemovalProjectConfig.getProjectId());
        Assert.assertEquals(GROUP_ID, afterRemovalProjectConfig.getGroupId());
        Assert.assertEquals(ARTIFACT_ID, afterRemovalProjectConfig.getArtifactId());
        Assert.assertEquals(this.projectStructureVersion, afterRemovalProjectConfig.getProjectStructureVersion().getVersion());
        Assert.assertEquals(this.projectStructureExtensionVersion, afterRemovalProjectConfig.getProjectStructureVersion().getExtensionVersion());
        Assert.assertEquals(metamodelDependencies.subList(i + 1, metamodelDependencies.size()), afterRemovalProjectConfig.getMetamodelDependencies());
        Assert.assertEquals(Collections.emptyList(), afterRemovalProjectConfig.getProjectDependencies());
        assertStateValid(PROJECT_ID, null, null);
    }
    ProjectConfiguration projectConfigUpdateRevisionConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
    Assert.assertEquals(PROJECT_ID, projectConfigUpdateRevisionConfig.getProjectId());
    Assert.assertEquals(GROUP_ID, projectConfigUpdateRevisionConfig.getGroupId());
    Assert.assertEquals(ARTIFACT_ID, projectConfigUpdateRevisionConfig.getArtifactId());
    Assert.assertEquals(this.projectStructureVersion, projectConfigUpdateRevisionConfig.getProjectStructureVersion().getVersion());
    Assert.assertEquals(this.projectStructureExtensionVersion, projectConfigUpdateRevisionConfig.getProjectStructureVersion().getExtensionVersion());
    Assert.assertEquals(Collections.emptyList(), projectConfigUpdateRevisionConfig.getMetamodelDependencies());
    Assert.assertEquals(Collections.emptyList(), projectConfigUpdateRevisionConfig.getProjectDependencies());
    assertEntitiesEquivalent(testEntities, getActualEntities(PROJECT_ID));
}
Also used : Entity(org.finos.legend.sdlc.domain.model.entity.Entity) Revision(org.finos.legend.sdlc.domain.model.revision.Revision) MetamodelDependency(org.finos.legend.sdlc.domain.model.project.configuration.MetamodelDependency) ProjectConfiguration(org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration)

Example 18 with Revision

use of org.finos.legend.sdlc.domain.model.revision.Revision in project legend-sdlc by finos.

the class TestProjectStructure method testUpdateFullProjectConfig.

protected void testUpdateFullProjectConfig(ProjectType projectType) {
    // TODO add some dependencies
    List<Entity> testEntities = getTestEntities();
    for (int i = 0; i < this.projectStructureVersion; i++) {
        if (unpublishedVersion.contains(i)) {
            continue;
        }
        if (i > 0) {
            this.fileAccessProvider = newProjectFileAccessProvider();
        }
        ProjectStructure otherProjectStructure = buildProjectStructure(i, null, projectType, null, null);
        List<ProjectFileOperation> addEntityOperations = ListIterate.collectWith(testEntities, this::generateAddOperationForEntity, otherProjectStructure);
        Revision revision = this.fileAccessProvider.getProjectFileModificationContext(PROJECT_ID).submit("Add entities", addEntityOperations);
        ProjectConfiguration beforeConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
        Assert.assertEquals(PROJECT_ID, beforeConfig.getProjectId());
        Assert.assertEquals(GROUP_ID, beforeConfig.getGroupId());
        Assert.assertEquals(ARTIFACT_ID, beforeConfig.getArtifactId());
        Assert.assertEquals(i, beforeConfig.getProjectStructureVersion().getVersion());
        String workspaceId = "ConvertProjectToVersion" + i;
        this.fileAccessProvider.createWorkspace(PROJECT_ID, workspaceId);
        ProjectConfigurationUpdateBuilder.newBuilder(this.fileAccessProvider, projectType, PROJECT_ID).withWorkspace(workspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE).withRevisionId(revision.getId()).withMessage("Update project configuration").withProjectStructureVersion(this.projectStructureVersion).withProjectStructureExtensionVersion(this.projectStructureExtensionVersion).withGroupId(GROUP_ID_2).withArtifactId(ARTIFACT_ID_2).withProjectStructureExtensionProvider(this.projectStructureExtensionProvider).withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions).updateProjectConfiguration();
        assertStateValid(PROJECT_ID, workspaceId, null);
        this.fileAccessProvider.commitWorkspace(PROJECT_ID, workspaceId);
        assertStateValid(PROJECT_ID, null, null);
        ProjectConfiguration afterConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
        Assert.assertEquals(PROJECT_ID, afterConfig.getProjectId());
        Assert.assertEquals(GROUP_ID_2, afterConfig.getGroupId());
        Assert.assertEquals(ARTIFACT_ID_2, afterConfig.getArtifactId());
        Assert.assertEquals(this.projectStructureVersion, afterConfig.getProjectStructureVersion().getVersion());
        Assert.assertEquals(this.projectStructureExtensionVersion, afterConfig.getProjectStructureVersion().getExtensionVersion());
        assertEntitiesEquivalent("convert version " + i + " to " + this.projectStructureVersion, testEntities, getActualEntities(PROJECT_ID));
    }
}
Also used : Entity(org.finos.legend.sdlc.domain.model.entity.Entity) Revision(org.finos.legend.sdlc.domain.model.revision.Revision) ProjectConfiguration(org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration)

Example 19 with Revision

use of org.finos.legend.sdlc.domain.model.revision.Revision in project legend-sdlc by finos.

the class TestProjectStructure method testUpdateProjectDependencies.

protected void testUpdateProjectDependencies(ProjectType projectType) {
    List<ProjectDependency> projectDependencies = Arrays.asList(ProjectDependency.parseProjectDependency(GROUP_ID + ":testproject0:0.0.1"), ProjectDependency.parseProjectDependency(GROUP_ID + ":testproject1:1.0.0"), ProjectDependency.parseProjectDependency(GROUP_ID + ":testproject3:2.0.1"));
    projectDependencies.sort(Comparator.naturalOrder());
    for (ProjectDependency projectDependency : projectDependencies) {
        String artifactId = projectDependency.getProjectId().substring(GROUP_ID.length() + 1);
        createProjectWithVersions(artifactId, GROUP_ID, artifactId, projectDependency.getVersionId());
    }
    ProjectStructure projectStructure = buildProjectStructure(projectType);
    List<Entity> testEntities = getTestEntities();
    List<ProjectFileOperation> addEntityOperations = ListIterate.collectWith(testEntities, this::generateAddOperationForEntity, projectStructure);
    this.fileAccessProvider.getProjectFileModificationContext(PROJECT_ID).submit("Add entities", addEntityOperations);
    ProjectConfiguration beforeProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
    Assert.assertEquals(PROJECT_ID, beforeProjectConfig.getProjectId());
    Assert.assertEquals(GROUP_ID, beforeProjectConfig.getGroupId());
    Assert.assertEquals(ARTIFACT_ID, beforeProjectConfig.getArtifactId());
    Assert.assertEquals(this.projectStructureVersion, beforeProjectConfig.getProjectStructureVersion().getVersion());
    Assert.assertEquals(this.projectStructureExtensionVersion, beforeProjectConfig.getProjectStructureVersion().getExtensionVersion());
    Assert.assertEquals(Collections.emptyList(), beforeProjectConfig.getMetamodelDependencies());
    Assert.assertEquals(Collections.emptyList(), beforeProjectConfig.getProjectDependencies());
    assertStateValid(PROJECT_ID, null, null);
    String addDependenciesWorkspaceId = "AddDependencies";
    this.fileAccessProvider.createWorkspace(PROJECT_ID, addDependenciesWorkspaceId);
    ProjectConfiguration beforeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
    Assert.assertEquals(PROJECT_ID, beforeWorkspaceConfig.getProjectId());
    Assert.assertEquals(GROUP_ID, beforeWorkspaceConfig.getGroupId());
    Assert.assertEquals(ARTIFACT_ID, beforeWorkspaceConfig.getArtifactId());
    Assert.assertEquals(this.projectStructureVersion, beforeWorkspaceConfig.getProjectStructureVersion().getVersion());
    Assert.assertEquals(this.projectStructureExtensionVersion, beforeWorkspaceConfig.getProjectStructureVersion().getExtensionVersion());
    Assert.assertEquals(Collections.emptyList(), beforeWorkspaceConfig.getMetamodelDependencies());
    Assert.assertEquals(Collections.emptyList(), beforeWorkspaceConfig.getProjectDependencies());
    assertStateValid(PROJECT_ID, addDependenciesWorkspaceId, null);
    ProjectConfigurationUpdateBuilder.newBuilder(this.fileAccessProvider, projectType, PROJECT_ID).withWorkspace(addDependenciesWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE).withMessage("Add dependencies").withProjectDependenciesToAdd(projectDependencies).withProjectStructureExtensionProvider(this.projectStructureExtensionProvider).withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions).updateProjectConfiguration();
    ProjectConfiguration afterWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, addDependenciesWorkspaceId, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
    Assert.assertEquals(PROJECT_ID, afterWorkspaceConfig.getProjectId());
    Assert.assertEquals(GROUP_ID, afterWorkspaceConfig.getGroupId());
    Assert.assertEquals(ARTIFACT_ID, afterWorkspaceConfig.getArtifactId());
    Assert.assertEquals(this.projectStructureVersion, afterWorkspaceConfig.getProjectStructureVersion().getVersion());
    Assert.assertEquals(this.projectStructureExtensionVersion, afterWorkspaceConfig.getProjectStructureVersion().getExtensionVersion());
    Assert.assertEquals(Collections.emptyList(), afterWorkspaceConfig.getMetamodelDependencies());
    Assert.assertEquals(projectDependencies, afterWorkspaceConfig.getProjectDependencies());
    assertStateValid(PROJECT_ID, addDependenciesWorkspaceId, null);
    this.fileAccessProvider.commitWorkspace(PROJECT_ID, addDependenciesWorkspaceId);
    ProjectConfiguration afterProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
    Assert.assertEquals(PROJECT_ID, afterProjectConfig.getProjectId());
    Assert.assertEquals(GROUP_ID, afterProjectConfig.getGroupId());
    Assert.assertEquals(ARTIFACT_ID, afterProjectConfig.getArtifactId());
    Assert.assertEquals(this.projectStructureVersion, afterProjectConfig.getProjectStructureVersion().getVersion());
    Assert.assertEquals(this.projectStructureExtensionVersion, afterProjectConfig.getProjectStructureVersion().getExtensionVersion());
    Assert.assertEquals(Collections.emptyList(), afterProjectConfig.getMetamodelDependencies());
    Assert.assertEquals(projectDependencies, afterProjectConfig.getProjectDependencies());
    assertStateValid(PROJECT_ID, null, null);
    String noChangeWorkspaceId = "NoChangeToDependencies";
    this.fileAccessProvider.createWorkspace(PROJECT_ID, noChangeWorkspaceId);
    Revision newRevision = ProjectConfigurationUpdateBuilder.newBuilder(this.fileAccessProvider, projectType, PROJECT_ID).withWorkspace(noChangeWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE).withMessage("No change to dependencies").withGroupId("temp.group.id").withProjectStructureExtensionProvider(this.projectStructureExtensionProvider).withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions).updateProjectConfiguration();
    Assert.assertNotNull(newRevision);
    ProjectConfiguration noChangeWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, noChangeWorkspaceId, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
    Assert.assertEquals(PROJECT_ID, noChangeWorkspaceConfig.getProjectId());
    Assert.assertEquals("temp.group.id", noChangeWorkspaceConfig.getGroupId());
    Assert.assertEquals(ARTIFACT_ID, noChangeWorkspaceConfig.getArtifactId());
    Assert.assertEquals(this.projectStructureVersion, noChangeWorkspaceConfig.getProjectStructureVersion().getVersion());
    Assert.assertEquals(this.projectStructureExtensionVersion, noChangeWorkspaceConfig.getProjectStructureVersion().getExtensionVersion());
    Assert.assertEquals(Collections.emptyList(), noChangeWorkspaceConfig.getMetamodelDependencies());
    Assert.assertEquals(projectDependencies, noChangeWorkspaceConfig.getProjectDependencies());
    assertStateValid(PROJECT_ID, noChangeWorkspaceId, null);
    this.fileAccessProvider.deleteWorkspace(PROJECT_ID, noChangeWorkspaceId);
    for (int i = 0; i < projectDependencies.size(); i++) {
        String removeDependencyWorkspaceId = "RemoveDependency" + 0;
        this.fileAccessProvider.createWorkspace(PROJECT_ID, removeDependencyWorkspaceId);
        ProjectConfiguration beforeRemovalConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
        Assert.assertEquals(PROJECT_ID, beforeRemovalConfig.getProjectId());
        Assert.assertEquals(GROUP_ID, beforeRemovalConfig.getGroupId());
        Assert.assertEquals(ARTIFACT_ID, beforeRemovalConfig.getArtifactId());
        Assert.assertEquals(this.projectStructureVersion, beforeRemovalConfig.getProjectStructureVersion().getVersion());
        Assert.assertEquals(this.projectStructureExtensionVersion, beforeRemovalConfig.getProjectStructureVersion().getExtensionVersion());
        Assert.assertEquals(Collections.emptyList(), beforeRemovalConfig.getMetamodelDependencies());
        Assert.assertEquals(projectDependencies.subList(i, projectDependencies.size()), beforeRemovalConfig.getProjectDependencies());
        assertStateValid(PROJECT_ID, removeDependencyWorkspaceId, null);
        ProjectConfigurationUpdateBuilder.newBuilder(this.fileAccessProvider, projectType, PROJECT_ID).withWorkspace(removeDependencyWorkspaceId, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE).withMessage("Remove dependencies").withProjectDependenciesToRemove(Collections.singletonList(projectDependencies.get(i))).withProjectStructureExtensionProvider(this.projectStructureExtensionProvider).withProjectStructurePlatformExtensions(this.projectStructurePlatformExtensions).updateProjectConfiguration();
        ProjectConfiguration afterRemovalWorkspaceConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, removeDependencyWorkspaceId, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
        Assert.assertEquals(PROJECT_ID, afterRemovalWorkspaceConfig.getProjectId());
        Assert.assertEquals(GROUP_ID, afterRemovalWorkspaceConfig.getGroupId());
        Assert.assertEquals(ARTIFACT_ID, afterRemovalWorkspaceConfig.getArtifactId());
        Assert.assertEquals(this.projectStructureVersion, afterRemovalWorkspaceConfig.getProjectStructureVersion().getVersion());
        Assert.assertEquals(this.projectStructureExtensionVersion, afterRemovalWorkspaceConfig.getProjectStructureVersion().getExtensionVersion());
        Assert.assertEquals(Collections.emptyList(), afterRemovalWorkspaceConfig.getMetamodelDependencies());
        Assert.assertEquals(projectDependencies.subList(i + 1, projectDependencies.size()), afterRemovalWorkspaceConfig.getProjectDependencies());
        assertStateValid(PROJECT_ID, removeDependencyWorkspaceId, null);
        this.fileAccessProvider.commitWorkspace(PROJECT_ID, removeDependencyWorkspaceId);
        ProjectConfiguration afterRemovalProjectConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
        Assert.assertEquals(PROJECT_ID, afterRemovalProjectConfig.getProjectId());
        Assert.assertEquals(GROUP_ID, afterRemovalProjectConfig.getGroupId());
        Assert.assertEquals(ARTIFACT_ID, afterRemovalProjectConfig.getArtifactId());
        Assert.assertEquals(this.projectStructureVersion, afterRemovalProjectConfig.getProjectStructureVersion().getVersion());
        Assert.assertEquals(this.projectStructureExtensionVersion, afterRemovalProjectConfig.getProjectStructureVersion().getExtensionVersion());
        Assert.assertEquals(Collections.emptyList(), afterRemovalProjectConfig.getMetamodelDependencies());
        Assert.assertEquals(projectDependencies.subList(i + 1, projectDependencies.size()), afterRemovalProjectConfig.getProjectDependencies());
        assertStateValid(PROJECT_ID, null, null);
    }
    ProjectConfiguration projectConfigUpdateRevisionConfig = ProjectStructure.getProjectConfiguration(PROJECT_ID, null, null, this.fileAccessProvider, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE);
    Assert.assertEquals(PROJECT_ID, projectConfigUpdateRevisionConfig.getProjectId());
    Assert.assertEquals(GROUP_ID, projectConfigUpdateRevisionConfig.getGroupId());
    Assert.assertEquals(ARTIFACT_ID, projectConfigUpdateRevisionConfig.getArtifactId());
    Assert.assertEquals(this.projectStructureVersion, projectConfigUpdateRevisionConfig.getProjectStructureVersion().getVersion());
    Assert.assertEquals(this.projectStructureExtensionVersion, projectConfigUpdateRevisionConfig.getProjectStructureVersion().getExtensionVersion());
    Assert.assertEquals(Collections.emptyList(), projectConfigUpdateRevisionConfig.getMetamodelDependencies());
    Assert.assertEquals(Collections.emptyList(), projectConfigUpdateRevisionConfig.getProjectDependencies());
    assertEntitiesEquivalent(testEntities, getActualEntities(PROJECT_ID));
}
Also used : Entity(org.finos.legend.sdlc.domain.model.entity.Entity) Revision(org.finos.legend.sdlc.domain.model.revision.Revision) ProjectDependency(org.finos.legend.sdlc.domain.model.project.configuration.ProjectDependency) ProjectConfiguration(org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration)

Example 20 with Revision

use of org.finos.legend.sdlc.domain.model.revision.Revision 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());
}
Also used : Response(javax.ws.rs.core.Response) Entity(org.finos.legend.sdlc.domain.model.entity.Entity) InMemoryEntity(org.finos.legend.sdlc.server.inmemory.domain.api.InMemoryEntity) UpdateEntitiesCommand(org.finos.legend.sdlc.server.application.entity.UpdateEntitiesCommand) Revision(org.finos.legend.sdlc.domain.model.revision.Revision) HttpResponseException(org.apache.http.client.HttpResponseException) Workspace(org.finos.legend.sdlc.domain.model.project.workspace.Workspace) Test(org.junit.Test)

Aggregations

Revision (org.finos.legend.sdlc.domain.model.revision.Revision)26 Entity (org.finos.legend.sdlc.domain.model.entity.Entity)15 ProjectConfiguration (org.finos.legend.sdlc.domain.model.project.configuration.ProjectConfiguration)10 Workspace (org.finos.legend.sdlc.domain.model.project.workspace.Workspace)9 LegendSDLCServerException (org.finos.legend.sdlc.server.error.LegendSDLCServerException)7 Project (org.finos.legend.sdlc.domain.model.project.Project)6 ProjectType (org.finos.legend.sdlc.domain.model.project.ProjectType)6 Instant (java.time.Instant)5 List (java.util.List)5 Test (org.junit.Test)5 Response (javax.ws.rs.core.Response)4 HttpResponseException (org.apache.http.client.HttpResponseException)4 Collections (java.util.Collections)3 Comparator (java.util.Comparator)3 Function (java.util.function.Function)3 Collectors (java.util.stream.Collectors)3 Lists (org.eclipse.collections.api.factory.Lists)3 Iterate (org.eclipse.collections.impl.utility.Iterate)3 ArtifactGeneration (org.finos.legend.sdlc.domain.model.project.configuration.ArtifactGeneration)3 MetamodelDependency (org.finos.legend.sdlc.domain.model.project.configuration.MetamodelDependency)3