Search in sources :

Example 16 with JGitRepoManager

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

the class GitProjectHandlerTest method createMarkupCollection.

@Test
public void createMarkupCollection() throws Exception {
    try (JGitRepoManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(RepositoryPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
        this.directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
        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);
        // the JGitRepoManager instance should always be in a detached state after GitProjectHandler calls return
        assertFalse(jGitRepoManager.isAttached());
        GitProjectHandler gitProjectHandler = new GitProjectHandler(null, projectId, jGitRepoManager, gitLabServerManager);
        String markupCollectionId = gitProjectHandler.createMarkupCollection(null, "Test Markup Collection", null, "fakeSourceDocumentId", "fakeSourceDocumentVersion");
        assertNotNull(markupCollectionId);
        // the JGitRepoManager instance should always be in a detached state after GitProjectHandler calls return
        assertFalse(jGitRepoManager.isAttached());
        jGitRepoManager.open(projectId, GitProjectManager.getProjectRootRepositoryName(projectId));
        Status status = jGitRepoManager.getGitApi().status().call();
        Set<String> added = status.getAdded();
        assert status.hasUncommittedChanges();
        assert added.contains(".gitmodules");
        assert added.contains(String.format("%s/%s", GitProjectHandler.MARKUP_COLLECTION_SUBMODULES_DIRECTORY_NAME, markupCollectionId));
    }
}
Also used : Status(org.eclipse.jgit.api.Status) JGitRepoManager(de.catma.repository.git.managers.JGitRepoManager) GitLabServerManagerTest(de.catma.repository.git.managers.GitLabServerManagerTest) Test(org.junit.Test)

Example 17 with JGitRepoManager

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

the class GitProjectHandlerTest method delete.

@Test
public void delete() 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", "This is a test CATMA project");
        // we don't add the projectId to this.projectsToDeleteOnTearDown as this is the delete test
        assertNotNull(projectId);
        assert projectId.startsWith("CATMA_");
        // the JGitRepoManager instance should always be in a detached state after GitProjectHandler calls
        // return
        assertFalse(jGitRepoManager.isAttached());
        String expectedRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        File expectedRootRepositoryPath = new File(jGitRepoManager.getRepositoryBasePath(), expectedRootRepositoryName);
        assert expectedRootRepositoryPath.exists();
        assert expectedRootRepositoryPath.isDirectory();
        gitProjectHandler.delete(projectId);
        assertFalse(expectedRootRepositoryPath.exists());
        // the JGitRepoManager instance should always be in a detached state after GitProjectHandler calls
        // return
        assertFalse(jGitRepoManager.isAttached());
    }
}
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)

Example 18 with JGitRepoManager

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

the class GitSourceDocumentHandlerTest method open.

@Test
public void open() throws Exception {
    try (JGitRepoManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(RepositoryPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
        this.directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
        HashMap<String, Object> getJsonLdWebAnnotationResult = JsonLdWebAnnotationTest.getJsonLdWebAnnotation(jGitRepoManager, this.gitLabServerManager, this.catmaUser);
        String projectId = (String) getJsonLdWebAnnotationResult.get("projectUuid");
        String sourceDocumentId = (String) getJsonLdWebAnnotationResult.get("sourceDocumentUuid");
        this.projectsToDeleteOnTearDown.add(projectId);
        GitSourceDocumentHandler gitSourceDocumentHandler = new GitSourceDocumentHandler(jGitRepoManager, this.gitLabServerManager);
        SourceDocument loadedSourceDocument = gitSourceDocumentHandler.open(projectId, sourceDocumentId);
        assertNotNull(loadedSourceDocument);
        assertEquals("William Faulkner", loadedSourceDocument.getSourceContentHandler().getSourceDocumentInfo().getContentInfoSet().getAuthor());
        assertEquals("A Rose for Emily", loadedSourceDocument.getSourceContentHandler().getSourceDocumentInfo().getContentInfoSet().getTitle());
        assertNotNull(loadedSourceDocument.getRevisionHash());
    }
}
Also used : JGitRepoManager(de.catma.repository.git.managers.JGitRepoManager) SourceDocument(de.catma.document.source.SourceDocument) GitLabServerManagerTest(de.catma.repository.git.managers.GitLabServerManagerTest) Test(org.junit.Test) JsonLdWebAnnotationTest(de.catma.repository.git.serialization.models.json_ld.JsonLdWebAnnotationTest)

Example 19 with JGitRepoManager

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

the class GitSourceDocumentHandlerTest method delete.

@Test
public void delete() throws Exception {
    try (ILocalGitRepositoryManager jGitRepoManager = new JGitRepoManager(this.catmaProperties.getProperty(RepositoryPropertyKey.GitBasedRepositoryBasePath.name()), this.catmaUser)) {
        GitSourceDocumentHandler gitSourceDocumentHandler = new GitSourceDocumentHandler(jGitRepoManager, this.gitLabServerManager);
        thrown.expect(IOException.class);
        thrown.expectMessage("Not implemented");
        gitSourceDocumentHandler.delete("fakeProjectId", "fakeSourceDocumentId");
    }
}
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 20 with JGitRepoManager

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

the class GitTagsetHandlerTest method createTagDefinitionWithoutParent.

@Test
public void createTagDefinitionWithoutParent() 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 for Tagset", "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 TagDefinition object
        String tagDefinitionId = this.idGenerator.generate();
        Version tagDefinitionVersion = new Version();
        TagDefinition tagDefinition = new TagDefinition(null, tagDefinitionId, "FakeTagDefinitionName", tagDefinitionVersion, null, null);
        PropertyDefinition propertyDefinition = new PropertyDefinition("Weather", Arrays.asList("Good", "Bad", "Toto, I've a feeling we're not in Kansas anymore."));
        tagDefinition.addUserDefinedPropertyDefinition(propertyDefinition);
        // call createTagDefinition
        GitTagsetHandler gitTagsetHandler = new GitTagsetHandler(jGitRepoManager, this.gitLabServerManager);
        String returnedTagDefinitionId = gitTagsetHandler.createOrUpdateTagDefinition(projectId, tagsetId, tagDefinition);
        assertNotNull(returnedTagDefinitionId);
        assert returnedTagDefinitionId.startsWith("CATMA_");
        // the JGitRepoManager instance should always be in a detached state after GitTagsetHandler calls return
        assertFalse(jGitRepoManager.isAttached());
        assertEquals(tagDefinitionId, returnedTagDefinitionId);
        String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        File expectedTagDefinitionPath = Paths.get(jGitRepoManager.getRepositoryBasePath().toString(), projectRootRepositoryName, GitProjectHandler.TAGSET_SUBMODULES_DIRECTORY_NAME, tagsetId, tagDefinition.getUuid()).toFile();
        assert expectedTagDefinitionPath.exists() : "Directory does not exist";
        assert expectedTagDefinitionPath.isDirectory() : "Path is not a directory";
        assert Arrays.asList(expectedTagDefinitionPath.list()).contains("propertydefs.json");
        GitTagDefinition expectedGitTagDefinition = new GitTagDefinition(tagDefinition);
        String actualSerializedGitTagDefinition = FileUtils.readFileToString(new File(expectedTagDefinitionPath, "propertydefs.json"), StandardCharsets.UTF_8);
        GitTagDefinition actualGitTagDefinition = new SerializationHelper<GitTagDefinition>().deserialize(actualSerializedGitTagDefinition, GitTagDefinition.class);
        assertEquals(expectedGitTagDefinition.getTagsetDefinitionUuid(), actualGitTagDefinition.getTagsetDefinitionUuid());
        assertEquals(expectedGitTagDefinition.getParentUuid(), actualGitTagDefinition.getParentUuid());
        assertEquals(expectedGitTagDefinition.getUuid(), actualGitTagDefinition.getUuid());
        assertEquals(expectedGitTagDefinition.getName(), actualGitTagDefinition.getName());
    // TODO: assert tag definition and properties
    }
}
Also used : GitTagDefinition(de.catma.repository.git.serialization.model_wrappers.GitTagDefinition) TagDefinition(de.catma.tag.TagDefinition) GitTagDefinition(de.catma.repository.git.serialization.model_wrappers.GitTagDefinition) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) Version(de.catma.tag.Version) JGitRepoManager(de.catma.repository.git.managers.JGitRepoManager) PropertyDefinition(de.catma.tag.PropertyDefinition) 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