Search in sources :

Example 21 with JGitRepoManager

use of de.catma.repository.git.managers.JGitRepoManager in project catma by forTEXT.

the class GitTagsetHandlerTest method create.

@Test
public void create() throws Exception {
    try (ILocalGitRepositoryManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(RepositoryPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
        this.directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
        GitProjectManager gitProjectHandler = new GitProjectManager(RepositoryPropertyKey.GitBasedRepositoryBasePath.getValue(), UserIdentification.userToMap(this.catmaUser.getIdentifier()));
        String projectId = gitProjectHandler.create("Test CATMA Project for Tagset", "This is a test CATMA project");
        this.projectsToDeleteOnTearDown.add(projectId);
        // the JGitRepoManager instance should always be in a detached state after GitProjectHandler
        // calls return
        assertFalse(jGitRepoManager.isAttached());
        GitTagsetHandler gitTagsetHandler = new GitTagsetHandler(jGitRepoManager, this.gitLabServerManager);
        String name = "Test Tagset";
        String description = "Test Tagset Description";
        String tagsetId = gitTagsetHandler.create(projectId, null, name, description);
        // we don't add the tagsetId to this.tagsetReposToDeleteOnTearDown as deletion of the
        // project will take care of that for us
        assertNotNull(tagsetId);
        assert tagsetId.startsWith("CATMA_");
        File expectedRepoPath = new File(jGitRepoManager.getRepositoryBasePath(), GitTagsetHandler.getTagsetRepositoryName(tagsetId));
        assert expectedRepoPath.exists();
        assert expectedRepoPath.isDirectory();
        assert Arrays.asList(expectedRepoPath.list()).contains("header.json");
        GitTagsetHeader expectedHeader = new GitTagsetHeader(name, description);
        String serialized = FileUtils.readFileToString(new File(expectedRepoPath, "header.json"), StandardCharsets.UTF_8);
        GitTagsetHeader actualHeader = new SerializationHelper<GitTagsetHeader>().deserialize(serialized, GitTagsetHeader.class);
        assertEquals(expectedHeader.getName(), actualHeader.getName());
        assertEquals(expectedHeader.getDescription(), actualHeader.getDescription());
    }
}
Also used : ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) GitTagsetHeader(de.catma.repository.git.serialization.models.GitTagsetHeader) JGitRepoManager(de.catma.repository.git.managers.JGitRepoManager) File(java.io.File) GitLabServerManagerTest(de.catma.repository.git.managers.GitLabServerManagerTest) Test(org.junit.Test) JsonLdWebAnnotationTest(de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotationTest)

Example 22 with JGitRepoManager

use of de.catma.repository.git.managers.JGitRepoManager in project catma by forTEXT.

the class GitMarkupCollectionHandlerTest method delete.

@Test
public void delete() throws Exception {
    try (ILocalGitRepositoryManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(RepositoryPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
        GitMarkupCollectionHandler gitMarkupCollectionHandler = new GitMarkupCollectionHandler(jGitRepoManager, this.gitLabServerManager);
        thrown.expect(IOException.class);
        thrown.expectMessage("Not implemented");
        gitMarkupCollectionHandler.delete("fakeProjectId", "fakeMarkupCollectionId");
    }
}
Also used : ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) JGitRepoManager(de.catma.repository.git.managers.JGitRepoManager) GitLabServerManagerTest(de.catma.repository.git.managers.GitLabServerManagerTest) Test(org.junit.Test) JsonLdWebAnnotationTest(de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotationTest)

Example 23 with JGitRepoManager

use of de.catma.repository.git.managers.JGitRepoManager in project catma by forTEXT.

the class GitMarkupCollectionHandlerTest method addTagset.

@Test
public void addTagset() throws Exception {
    try (ILocalGitRepositoryManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(RepositoryPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
        this.directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
        // create a project
        GitProjectManager gitProjectManager = new GitProjectManager(RepositoryPropertyKey.GitBasedRepositoryBasePath.getValue(), UserIdentification.userToMap(this.catmaUser.getIdentifier()));
        String projectId = gitProjectManager.create("Test CATMA Project", "This is a test CATMA project");
        this.projectsToDeleteOnTearDown.add(projectId);
        GitProjectHandler gitProjectHandler = new GitProjectHandler(null, projectId, jGitRepoManager, gitLabServerManager);
        // create a tagset
        String tagsetId = gitProjectHandler.createTagset(null, "Test Tagset", null);
        // we don't add the tagsetId to this.tagsetReposToDeleteOnTearDown as deletion of the project will take
        // care of that for us
        // create a markup collection
        String markupCollectionId = gitProjectHandler.createMarkupCollection(null, "Test Markup Collection", null, "fakeSourceDocumentId", "fakeSourceDocumentVersion");
        // we don't add the markupCollectionId to this.markupCollectionReposToDeleteOnTearDown as deletion of the
        // project will take care of that for us
        // add the tagset to the markup collection
        GitMarkupCollectionHandler gitMarkupCollectionHandler = new GitMarkupCollectionHandler(jGitRepoManager, this.gitLabServerManager);
        gitMarkupCollectionHandler.addTagset(projectId, markupCollectionId, tagsetId, "fakeTagsetVersion");
        // the JGitRepoManager instance should always be in a detached state after GitMarkupCollectionHandler
        // calls return
        assertFalse(jGitRepoManager.isAttached());
        // assert that the markup collection header file was updated as expected
        String expectedSerializedHeader = "" + "{\n" + "\t\"author\":null,\n" + "\t\"description\":null,\n" + "\t\"name\":\"Test Markup Collection\",\n" + "\t\"publisher\":null,\n" + "\t\"sourceDocumentId\":\"fakeSourceDocumentId\",\n" + "\t\"sourceDocumentVersion\":\"fakeSourceDocumentVersion\",\n" + "\t\"tagsets\":{\n" + "\t\t\"%s\":\"fakeTagsetVersion\"\n" + "\t}\n" + "}";
        expectedSerializedHeader = String.format(expectedSerializedHeader, tagsetId);
        File markupCollectionHeaderFilePath = Paths.get(jGitRepoManager.getRepositoryBasePath().toString(), GitProjectManager.getProjectRootRepositoryName(projectId), GitProjectHandler.MARKUP_COLLECTION_SUBMODULES_DIRECTORY_NAME, markupCollectionId, "header.json").toFile();
        assertEquals(expectedSerializedHeader.replaceAll("[\n\t]", ""), FileUtils.readFileToString(markupCollectionHeaderFilePath, StandardCharsets.UTF_8));
    }
}
Also used : ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) JGitRepoManager(de.catma.repository.git.managers.JGitRepoManager) File(java.io.File) GitLabServerManagerTest(de.catma.repository.git.managers.GitLabServerManagerTest) Test(org.junit.Test) JsonLdWebAnnotationTest(de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotationTest)

Aggregations

JGitRepoManager (de.catma.repository.git.managers.JGitRepoManager)23 GitLabServerManagerTest (de.catma.repository.git.managers.GitLabServerManagerTest)22 Test (org.junit.Test)18 ILocalGitRepositoryManager (de.catma.repository.git.interfaces.ILocalGitRepositoryManager)13 JsonLdWebAnnotationTest (de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotationTest)13 File (java.io.File)12 TagDefinition (de.catma.tag.TagDefinition)5 EventBus (com.google.common.eventbus.EventBus)4 BackgroundService (de.catma.backgroundservice.BackgroundService)4 ContentInfoSet (de.catma.document.source.ContentInfoSet)4 IndexInfoSet (de.catma.document.source.IndexInfoSet)4 SourceDocumentInfo (de.catma.document.source.SourceDocumentInfo)4 TechInfoSet (de.catma.document.source.TechInfoSet)4 IDGenerator (de.catma.util.IDGenerator)4 FileInputStream (java.io.FileInputStream)4 Test (org.junit.jupiter.api.Test)4 Range (de.catma.document.Range)3 TermExtractor (de.catma.indexer.TermExtractor)3 GitTagDefinition (de.catma.repository.git.serialization.model_wrappers.GitTagDefinition)3 PropertyDefinition (de.catma.tag.PropertyDefinition)3