use of de.catma.repository.git.managers.JGitRepoManager in project catma by forTEXT.
the class JsonLdWebAnnotationTest method serialize.
@Test
public void serialize() 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);
this.projectsToDeleteOnTearDown.add((String) getJsonLdWebAnnotationResult.get("projectUuid"));
JsonLdWebAnnotation jsonLdWebAnnotation = (JsonLdWebAnnotation) getJsonLdWebAnnotationResult.get("jsonLdWebAnnotation");
String serialized = new SerializationHelper<JsonLdWebAnnotation>().serialize(jsonLdWebAnnotation);
String expectedSerializedRepresentation = JsonLdWebAnnotationTest.EXPECTED_SERIALIZED_ANNOTATION.replaceAll("[\n\t]", "");
expectedSerializedRepresentation = String.format(expectedSerializedRepresentation, getJsonLdWebAnnotationResult.get("projectRootRepositoryName"), getJsonLdWebAnnotationResult.get("tagsetDefinitionUuid"), getJsonLdWebAnnotationResult.get("tagDefinitionUuid"), getJsonLdWebAnnotationResult.get("userPropertyDefinitionUuid"), getJsonLdWebAnnotationResult.get("systemPropertyDefinitionUuid"), getJsonLdWebAnnotationResult.get("userMarkupCollectionUuid"), getJsonLdWebAnnotationResult.get("tagInstanceUuid"), getJsonLdWebAnnotationResult.get("sourceDocumentUuid"));
assertEquals(expectedSerializedRepresentation, serialized);
}
}
use of de.catma.repository.git.managers.JGitRepoManager in project catma by forTEXT.
the class GitMarkupCollectionHandlerTest method createTagInstance.
@Test
public void createTagInstance() 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);
JsonLdWebAnnotation jsonLdWebAnnotation = (JsonLdWebAnnotation) getJsonLdWebAnnotationResult.get("jsonLdWebAnnotation");
String projectId = (String) getJsonLdWebAnnotationResult.get("projectUuid");
String markupCollectionId = (String) getJsonLdWebAnnotationResult.get("userMarkupCollectionUuid");
String tagsetId = (String) getJsonLdWebAnnotationResult.get("tagsetDefinitionUuid");
String tagInstanceId = (String) getJsonLdWebAnnotationResult.get("tagInstanceUuid");
this.projectsToDeleteOnTearDown.add(projectId);
// add the tagset to the markup collection
GitMarkupCollectionHandler gitMarkupCollectionHandler = new GitMarkupCollectionHandler(jGitRepoManager, this.gitLabServerManager);
// TODO: use the real tagset hash - currently the handler does not validate it at all
gitMarkupCollectionHandler.addTagset(projectId, markupCollectionId, tagsetId, "fakeTagsetVersion");
// the JGitRepoManager instance should always be in a detached state after GitMarkupCollectionHandler calls
// return
assertFalse(jGitRepoManager.isAttached());
// create the tag instance
gitMarkupCollectionHandler.createTagInstance(projectId, markupCollectionId, jsonLdWebAnnotation);
// the JGitRepoManager instance should always be in a detached state after GitMarkupCollectionHandler
// calls return
assertFalse(jGitRepoManager.isAttached());
String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
jGitRepoManager.open(projectId, projectRootRepositoryName);
File expectedTagInstanceJsonFilePath = new File(jGitRepoManager.getRepositoryWorkTree(), String.format("%s/%s/annotations/%s.json", GitProjectHandler.MARKUP_COLLECTION_SUBMODULES_DIRECTORY_NAME, markupCollectionId, tagInstanceId));
assert expectedTagInstanceJsonFilePath.exists();
assert expectedTagInstanceJsonFilePath.isFile();
String expectedTagInstanceJsonFileContents = JsonLdWebAnnotationTest.EXPECTED_SERIALIZED_ANNOTATION.replaceAll("[\n\t]", "");
expectedTagInstanceJsonFileContents = String.format(expectedTagInstanceJsonFileContents, getJsonLdWebAnnotationResult.get("projectRootRepositoryName"), getJsonLdWebAnnotationResult.get("tagsetDefinitionUuid"), getJsonLdWebAnnotationResult.get("tagDefinitionUuid"), getJsonLdWebAnnotationResult.get("userPropertyDefinitionUuid"), getJsonLdWebAnnotationResult.get("systemPropertyDefinitionUuid"), getJsonLdWebAnnotationResult.get("userMarkupCollectionUuid"), getJsonLdWebAnnotationResult.get("tagInstanceUuid"), getJsonLdWebAnnotationResult.get("sourceDocumentUuid"));
assertEquals(expectedTagInstanceJsonFileContents, FileUtils.readFileToString(expectedTagInstanceJsonFilePath, StandardCharsets.UTF_8));
}
}
use of de.catma.repository.git.managers.JGitRepoManager in project catma by forTEXT.
the class GitMarkupCollectionHandlerTest 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", "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());
GitMarkupCollectionHandler gitMarkupCollectionHandler = new GitMarkupCollectionHandler(jGitRepoManager, this.gitLabServerManager);
String markupCollectionId = gitMarkupCollectionHandler.create(projectId, 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
assertNotNull(markupCollectionId);
assert markupCollectionId.startsWith("CATMA_");
// the JGitRepoManager instance should always be in a detached state after GitMarkupCollectionHandler
// calls return
assertFalse(jGitRepoManager.isAttached());
File expectedRepoPath = new File(jGitRepoManager.getRepositoryBasePath(), GitMarkupCollectionHandler.getMarkupCollectionRepositoryName(markupCollectionId));
assert expectedRepoPath.exists();
assert expectedRepoPath.isDirectory();
assert Arrays.asList(expectedRepoPath.list()).contains("header.json");
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" + "}";
assertEquals(expectedSerializedHeader.replaceAll("[\n\t]", ""), FileUtils.readFileToString(new File(expectedRepoPath, "header.json"), StandardCharsets.UTF_8));
}
}
use of de.catma.repository.git.managers.JGitRepoManager in project catma by forTEXT.
the class GitMarkupCollectionHandlerTest method open.
@Test
public void open() throws Exception {
// TODO: don't hardcode anything in assertions (markup collection name...)
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);
JsonLdWebAnnotation jsonLdWebAnnotation = (JsonLdWebAnnotation) getJsonLdWebAnnotationResult.get("jsonLdWebAnnotation");
String projectId = (String) getJsonLdWebAnnotationResult.get("projectUuid");
String markupCollectionId = (String) getJsonLdWebAnnotationResult.get("userMarkupCollectionUuid");
String tagsetId = (String) getJsonLdWebAnnotationResult.get("tagsetDefinitionUuid");
this.projectsToDeleteOnTearDown.add(projectId);
// add the tagset to the markup collection
GitMarkupCollectionHandler gitMarkupCollectionHandler = new GitMarkupCollectionHandler(jGitRepoManager, this.gitLabServerManager);
// TODO: use the real tagset hash - currently the handler does not validate it at all
gitMarkupCollectionHandler.addTagset(projectId, markupCollectionId, tagsetId, "fakeTagsetVersion");
// the JGitRepoManager instance should always be in a detached state after GitMarkupCollectionHandler calls
// return
assertFalse(jGitRepoManager.isAttached());
// create the tag instance within the markup collection
gitMarkupCollectionHandler.createTagInstance(projectId, markupCollectionId, jsonLdWebAnnotation);
// the JGitRepoManager instance should always be in a detached state after GitMarkupCollectionHandler calls
// return
assertFalse(jGitRepoManager.isAttached());
UserMarkupCollection markupCollection = gitMarkupCollectionHandler.open(projectId, markupCollectionId);
// the JGitRepoManager instance should always be in a detached state after GitMarkupCollectionHandler
// calls return
assertFalse(jGitRepoManager.isAttached());
assertNotNull(markupCollection);
assertEquals("Test Markup Collection", markupCollection.getContentInfoSet().getTitle());
assertEquals(2, markupCollection.getTagReferences().size());
assertTrue(markupCollection.getTagReferences().get(0).getRange().equals(new Range(12, 18)));
assertNotNull(markupCollection.getRevisionHash());
}
}
use of de.catma.repository.git.managers.JGitRepoManager in project catma by forTEXT.
the class GitProjectHandlerTest method create.
@Test
public void create() throws Exception {
try (ILocalGitRepositoryManager jGitRepoManager = new JGitRepoManager(CATMAPropertyKey.GitBasedRepositoryBasePath.getValue(), gitlabManagerRestricted.getUser())) {
directoriesToDeleteOnTearDown.add(jGitRepoManager.getRepositoryBasePath());
BackgroundService mockBackgroundService = mock(BackgroundService.class);
EventBus mockEventBus = mock(EventBus.class);
GitProjectManager gitProjectManager = new GitProjectManager(CATMAPropertyKey.GitBasedRepositoryBasePath.getValue(), gitlabManagerRestricted, // noop deletion handler
(projectId) -> {
}, mockBackgroundService, mockEventBus);
String projectId = gitProjectManager.create("Test CATMA Project", "This is a test CATMA project");
// we don't add the projectId to projectsToDeleteOnTearDown as deletion of the user will take care of that for us
assertNotNull(projectId);
assert projectId.startsWith("CATMA_");
// the JGitRepoManager instance should always be in a detached state after GitProjectManager calls return
assertFalse(jGitRepoManager.isAttached());
String expectedRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
File expectedRootRepositoryPath = Paths.get(jGitRepoManager.getRepositoryBasePath().getPath(), projectId, expectedRootRepositoryName).toFile();
assert expectedRootRepositoryPath.exists();
assert expectedRootRepositoryPath.isDirectory();
}
}
Aggregations