use of org.finos.legend.sdlc.server.project.InMemoryProjectFileAccessProvider in project legend-sdlc by finos.
the class TestDefaultProjectStructureExtension method testCollectUpdateProjectConfigurationOperations_EmptyStart.
@Test
public void testCollectUpdateProjectConfigurationOperations_EmptyStart() {
String file1Path = "/file1.txt";
String file1Content = "the quick brown fox";
String file2Path = "/dir/file2.txt";
String file2Content = "jumped over the lazy dog";
DefaultProjectStructureExtension extension = newProjectStructureExtension(0, 0, file1Path, file1Content, file2Path, file2Content);
InMemoryProjectFileAccessProvider fileAccessProvider = new InMemoryProjectFileAccessProvider(AUTHOR, COMMITTER);
fileAccessProvider.createWorkspace(PROJECT_ID, WORKSPACE_ID);
ProjectFileAccessProvider.FileAccessContext fileAccessContext = fileAccessProvider.getFileAccessContext(PROJECT_ID, WORKSPACE_ID, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, null);
Assert.assertEquals(0L, fileAccessContext.getFiles().count());
List<ProjectFileOperation> operations = Lists.mutable.empty();
extension.collectUpdateProjectConfigurationOperations(null, null, fileAccessContext, operations::add);
Assert.assertEquals(2, operations.size());
ProjectFileAccessProvider.FileModificationContext modificationContext = fileAccessProvider.getFileModificationContext(PROJECT_ID, WORKSPACE_ID, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, null);
modificationContext.submit("message", operations);
Assert.assertEquals(2L, fileAccessContext.getFiles().count());
ProjectFileAccessProvider.ProjectFile file1 = fileAccessContext.getFile(file1Path);
Assert.assertNotNull(file1Path, file1);
Assert.assertEquals(file1Content, file1.getContentAsString());
ProjectFileAccessProvider.ProjectFile file2 = fileAccessContext.getFile(file2Path);
Assert.assertNotNull(file2Path, file2);
Assert.assertEquals(file2Content, file2.getContentAsString());
}
use of org.finos.legend.sdlc.server.project.InMemoryProjectFileAccessProvider in project legend-sdlc by finos.
the class TestDefaultProjectStructureExtension method testCollectUpdateProjectConfigurationOperations_Vacuous.
@Test
public void testCollectUpdateProjectConfigurationOperations_Vacuous() {
DefaultProjectStructureExtension extension = newProjectStructureExtension(0, 0);
InMemoryProjectFileAccessProvider fileAccessProvider = new InMemoryProjectFileAccessProvider(AUTHOR, COMMITTER);
fileAccessProvider.createWorkspace(PROJECT_ID, WORKSPACE_ID);
ProjectFileAccessProvider.FileAccessContext fileAccessContext = fileAccessProvider.getFileAccessContext(PROJECT_ID, WORKSPACE_ID, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, null);
Assert.assertEquals(0L, fileAccessContext.getFiles().count());
List<ProjectFileOperation> operations = Lists.mutable.empty();
extension.collectUpdateProjectConfigurationOperations(null, null, fileAccessContext, operations::add);
Assert.assertEquals(Collections.emptyList(), operations);
Assert.assertEquals(0L, fileAccessContext.getFiles().count());
}
use of org.finos.legend.sdlc.server.project.InMemoryProjectFileAccessProvider in project legend-sdlc by finos.
the class TestDefaultProjectStructureExtension method testFilePathCanonicalizationConflict.
@Test
public void testFilePathCanonicalizationConflict() {
String filePath = "file1.txt";
String canonicalFilePath = "/file1.txt";
String fileContent = "the quick brown fox jumped over the lazy dog";
InMemoryProjectFileAccessProvider fileAccessProvider = new InMemoryProjectFileAccessProvider(AUTHOR, COMMITTER);
fileAccessProvider.createWorkspace(PROJECT_ID, WORKSPACE_ID);
ProjectFileAccessProvider.FileAccessContext fileAccessContext = fileAccessProvider.getFileAccessContext(PROJECT_ID, WORKSPACE_ID, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, null);
Assert.assertEquals(0L, fileAccessContext.getFiles().count());
RuntimeException e = Assert.assertThrows(RuntimeException.class, () -> newProjectStructureExtension(0, 0, filePath, fileContent, canonicalFilePath, "other content"));
Assert.assertEquals("Multiple definitions for \"/file1.txt\" for project structure version 0, extension 0: one for \"/file1.txt\" and another for \"file1.txt\"", e.getMessage());
}
use of org.finos.legend.sdlc.server.project.InMemoryProjectFileAccessProvider in project legend-sdlc by finos.
the class TestDefaultProjectStructureExtension method testCollectUpdateProjectConfigurationOperations_NonEmptyStart.
@Test
public void testCollectUpdateProjectConfigurationOperations_NonEmptyStart() {
String file1Path = "/file1.txt";
String file1ContentBefore = "the quick brown fox jumped over the lazy dog";
String file1ContentAfter = "THE QUICK BROWN FOX";
String file2Path = "/dir/file2.txt";
String file2ContentAfter = "JUMPED OVER THE LAZY DOG";
DefaultProjectStructureExtension extension = newProjectStructureExtension(0, 0, file1Path, file1ContentAfter, file2Path, file2ContentAfter);
InMemoryProjectFileAccessProvider fileAccessProvider = new InMemoryProjectFileAccessProvider(AUTHOR, COMMITTER);
fileAccessProvider.createWorkspace(PROJECT_ID, WORKSPACE_ID);
ProjectFileAccessProvider.FileAccessContext fileAccessContext = fileAccessProvider.getFileAccessContext(PROJECT_ID, WORKSPACE_ID, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, null);
Assert.assertEquals(0L, fileAccessContext.getFiles().count());
ProjectFileAccessProvider.FileModificationContext modificationContext = fileAccessProvider.getFileModificationContext(PROJECT_ID, WORKSPACE_ID, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, null);
modificationContext.submit("initial state", Collections.singletonList(ProjectFileOperation.addFile(file1Path, file1ContentBefore)));
Assert.assertEquals(1L, fileAccessContext.getFiles().count());
Assert.assertNotNull(file1Path, fileAccessContext.getFile(file1Path));
Assert.assertEquals(file1ContentBefore, fileAccessContext.getFile(file1Path).getContentAsString());
Assert.assertNull(file2Path, fileAccessContext.getFile(file2Path));
List<ProjectFileOperation> operations = Lists.mutable.empty();
extension.collectUpdateProjectConfigurationOperations(null, null, fileAccessContext, operations::add);
Assert.assertEquals(2, operations.size());
modificationContext.submit("update", operations);
Assert.assertEquals(2L, fileAccessContext.getFiles().count());
Assert.assertNotNull(file1Path, fileAccessContext.getFile(file1Path));
Assert.assertEquals(file1ContentAfter, fileAccessContext.getFile(file1Path).getContentAsString());
Assert.assertNotNull(file2Path, fileAccessContext.getFile(file2Path));
Assert.assertEquals(file2ContentAfter, fileAccessContext.getFile(file2Path).getContentAsString());
}
use of org.finos.legend.sdlc.server.project.InMemoryProjectFileAccessProvider in project legend-sdlc by finos.
the class TestDefaultProjectStructureExtension method testFilePathCanonicalization.
@Test
public void testFilePathCanonicalization() {
String filePath = "file1.txt";
String canonicalFilePath = "/file1.txt";
String fileContent = "the quick brown fox jumped over the lazy dog";
InMemoryProjectFileAccessProvider fileAccessProvider = new InMemoryProjectFileAccessProvider(AUTHOR, COMMITTER);
fileAccessProvider.createWorkspace(PROJECT_ID, WORKSPACE_ID);
ProjectFileAccessProvider.FileAccessContext fileAccessContext = fileAccessProvider.getFileAccessContext(PROJECT_ID, WORKSPACE_ID, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, null);
Assert.assertEquals(0L, fileAccessContext.getFiles().count());
DefaultProjectStructureExtension extension = newProjectStructureExtension(0, 0, filePath, fileContent);
List<ProjectFileOperation> operations = Lists.mutable.empty();
extension.collectUpdateProjectConfigurationOperations(null, null, fileAccessContext, operations::add);
Assert.assertEquals(1, operations.size());
ProjectFileAccessProvider.FileModificationContext modificationContext = fileAccessProvider.getFileModificationContext(PROJECT_ID, WORKSPACE_ID, WorkspaceType.USER, ProjectFileAccessProvider.WorkspaceAccessType.WORKSPACE, null);
modificationContext.submit("update", operations);
Assert.assertNull(filePath, fileAccessContext.getFile(filePath));
Assert.assertNotNull(canonicalFilePath, fileAccessContext.getFile(canonicalFilePath));
Assert.assertEquals(fileContent, fileAccessContext.getFile(canonicalFilePath).getContentAsString());
}
Aggregations