Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MODE-1286 Added more tests for the Git connector

Added several more tests for the Git connector, and changed how the
"git:history" and "git:tree" references are being created so that they
now use the commit ID rather than the tag/branch name.
  • Loading branch information...
commit 85b135ae9112fb075018544b8f8166a87a331371 1 parent 733e438
@rhauch rhauch authored
Showing with 257 additions and 39 deletions.
  1. +2 −1  connectors/modeshape-connector-git/src/main/java/org/modeshape/connector/git/GitBranches.java
  2. +1 −1  connectors/modeshape-connector-git/src/main/java/org/modeshape/connector/git/GitCommitDetails.java
  3. +14 −2 connectors/modeshape-connector-git/src/main/java/org/modeshape/connector/git/GitConnector.java
  4. +2 −4 connectors/modeshape-connector-git/src/main/java/org/modeshape/connector/git/GitFunction.java
  5. +10 −11 connectors/modeshape-connector-git/src/main/java/org/modeshape/connector/git/GitHistory.java
  6. +2 −0  connectors/modeshape-connector-git/src/main/java/org/modeshape/connector/git/GitLexicon.java
  7. +2 −1  connectors/modeshape-connector-git/src/main/java/org/modeshape/connector/git/GitTags.java
  8. +16 −4 connectors/modeshape-connector-git/src/main/java/org/modeshape/connector/git/GitTree.java
  9. +15 −7 connectors/modeshape-connector-git/src/main/resources/org/modeshape/connector/git/git.cnd
  10. +131 −6 connectors/modeshape-connector-git/src/test/java/org/modeshape/connector/git/GitConnectorTest.java
  11. +1 −0  connectors/modeshape-connector-git/src/test/resources/config/repo-config-git-federation.json
  12. +4 −2 modeshape-jcr/src/main/java/org/modeshape/jcr/federation/FederatedDocumentStore.java
  13. +57 −0 modeshape-jcr/src/test/java/org/modeshape/jcr/AbstractJcrRepositoryTest.java
View
3  connectors/modeshape-connector-git/src/main/java/org/modeshape/connector/git/GitBranches.java
@@ -78,8 +78,9 @@ public Document execute( Repository repository,
// Construct the references to other nodes in this source ...
ObjectId objId = commit.getId();
writer.addProperty(GitLexicon.OBJECT_ID, objId.name());
- writer.addProperty(GitLexicon.TREE, GitTree.referenceToTree(objId, branchName, values));
+ writer.addProperty(GitLexicon.TREE, GitTree.referenceToTree(objId, objId.name(), values));
writer.addProperty(GitLexicon.HISTORY, GitHistory.referenceToHistory(objId, branchName, values));
+ writer.addProperty(GitLexicon.DETAIL, GitCommitDetails.referenceToCommit(objId, values));
} finally {
walker.dispose();
}
View
2  connectors/modeshape-connector-git/src/main/java/org/modeshape/connector/git/GitCommitDetails.java
@@ -113,7 +113,7 @@ public Document execute( Repository repository,
writer.addProperty(GitLexicon.TITLE, commit.getShortMessage());
writer.addProperty(GitLexicon.MESSAGE, commit.getFullMessage().trim());// removes trailing whitespace
writer.addProperty(GitLexicon.PARENTS, GitCommitDetails.referencesToCommits(commit.getParents(), values));
- writer.addProperty(GitLexicon.TREE, GitTree.referenceToTree(objId, branchOrTagOrCommitId, values));
+ writer.addProperty(GitLexicon.TREE, GitTree.referenceToTree(objId, objId.name(), values));
// Compute the difference between the commit and it's parent(s), and generate the diff/patch file ...
List<DiffEntry> differences = computeDifferences(commit, walker, repository);
View
16 connectors/modeshape-connector-git/src/main/java/org/modeshape/connector/git/GitConnector.java
@@ -91,6 +91,7 @@
*/
public class GitConnector extends ReadOnlyConnector implements Pageable {
+ public static final boolean DEFAULT_INCLUDE_MIME_TYPE = false;
public static final String DEFAULT_REMOTE_NAME = "origin";
private static final String GIT_DIRECTORY_NAME = ".git";
@@ -103,11 +104,18 @@
private String directoryPath;
/**
- * The string value representing the name of the remote that serves as the primary remote repository. By default this is
- * "origin". This is set via reflection and is required for this connector.
+ * The optional string value representing the name of the remote that serves as the primary remote repository. By default this
+ * is "origin". This is set via reflection.
*/
private String remoteName = DEFAULT_REMOTE_NAME;
+ /**
+ * The optional boolean value specifying whether the connector should set the "jcr:mimeType" property on the "jcr:content"
+ * child node under each "git:file" node. By default this is '{@value GitConnector#DEFAULT_INCLUDE_MIME_TYPE}'. This is set
+ * via reflection.
+ */
+ private boolean includeMimeType = DEFAULT_INCLUDE_MIME_TYPE;
+
private Repository repository;
private Git git;
private Map<String, GitFunction> functions;
@@ -189,6 +197,10 @@ protected DocumentWriter newDocumentWriter( String id ) {
return super.newDocument(id);
}
+ protected boolean includeMimeType() {
+ return includeMimeType;
+ }
+
@Override
public void shutdown() {
repository = null;
View
6 connectors/modeshape-connector-git/src/main/java/org/modeshape/connector/git/GitFunction.java
@@ -208,8 +208,7 @@ protected void addCommitsAsChildren( Git git,
}
if (actual == pageSize) {
// We wrote the maximum number of commits, so there's (probably) another page ...
- int totalNumberOfChildren = Integer.MAX_VALUE; // don't know how many (or at least it's very expensive)
- writer.addPage(spec.getId(), commitId, pageSize, totalNumberOfChildren);
+ writer.addPage(spec.getId(), commitId, pageSize, PageWriter.UNKNOWN_TOTAL_SIZE);
}
}
@@ -252,8 +251,7 @@ protected void addCommitsAsPageOfChildren( Git git,
if (actual == pageSize) {
assert commitId != null;
// We wrote the maximum number of commits, so there's (probably) another page ...
- int totalNumberOfChildren = Integer.MAX_VALUE; // don't know how many (or at least it's very expensive)
- writer.addPage(pageKey.getParentId(), commitId, pageSize, totalNumberOfChildren);
+ writer.addPage(pageKey.getParentId(), commitId, pageSize, PageWriter.UNKNOWN_TOTAL_SIZE);
}
} finally {
walker.dispose();
View
21 connectors/modeshape-connector-git/src/main/java/org/modeshape/connector/git/GitHistory.java
@@ -89,7 +89,7 @@ public Document execute( Repository repository,
// Generate the child references to the (latest) commits on this branch/tag ...
String branchOrTagNameOrObjectId = spec.parameter(0);
- ObjectId objId = repository.resolve(branchOrTagNameOrObjectId);
+ ObjectId objId = resolveBranchOrTagOrCommitId(repository, branchOrTagNameOrObjectId);
RevWalk walker = new RevWalk(repository);
try {
RevCommit commit = walker.parseCommit(objId);
@@ -97,32 +97,32 @@ public Document execute( Repository repository,
command.add(commit.getId());
command.setMaxCount(pageSize);
for (RevCommit rev : command.call()) {
- String commitId = rev.getId().toString();
+ String commitId = rev.getId().getName();
writer.addChild(spec.childId(commitId), commitId);
}
// Handle paging ...
- int totalNumberOfChildren = Integer.MAX_VALUE; // don't know how many (or at least it's very expensive)
- writer.addPage(spec.getParentId(), pageSize, pageSize, totalNumberOfChildren);
+ writer.addPage(spec.getParentId(), pageSize, pageSize, PageWriter.UNKNOWN_TOTAL_SIZE);
} finally {
walker.dispose();
}
} else if (spec.parameterCount() == 2) {
// This is a specific commit in the history, via "/commits/{branchOrTagNameOrObjectId}/{objectId}"
+ writer.setPrimaryType(GitLexicon.COMMIT);
+
// so we need to show the commit information ...
RevWalk walker = new RevWalk(repository);
try {
- String branchOrTagOrObjectId = spec.parameter(1);
- ObjectId objId = repository.resolve(branchOrTagOrObjectId);
+ String commitId = spec.parameter(1);
+ ObjectId objId = repository.resolve(commitId);
RevCommit commit = walker.parseCommit(objId);
writer.addProperty(GitLexicon.OBJECT_ID, objId.name());
writer.addProperty(GitLexicon.AUTHOR, commit.getAuthorIdent().getName());
writer.addProperty(GitLexicon.COMMITTER, commit.getCommitterIdent().getName());
writer.addProperty(GitLexicon.COMMITTED, values.dateFrom(commit.getCommitTime()));
writer.addProperty(GitLexicon.TITLE, commit.getShortMessage());
- writer.addProperty(GitLexicon.MESSAGE, commit.getFullMessage().trim());
- writer.addProperty(GitLexicon.PARENTS, GitCommitDetails.referencesToCommits(commit.getParents(), values));
- writer.addProperty(GitLexicon.TREE, GitTree.referenceToTree(objId, branchOrTagOrObjectId, values));
+ writer.addProperty(GitLexicon.TREE, GitTree.referenceToTree(objId, objId.name(), values));
+ writer.addProperty(GitLexicon.DETAIL, GitCommitDetails.referenceToCommit(objId, values));
// And there are no children
} finally {
walker.dispose();
@@ -162,9 +162,8 @@ public Document execute( Repository repository,
}
// Handle paging ...
- int totalNumberOfChildren = Integer.MAX_VALUE; // don't know how many (or at least it's very expensive)
int nextOffset = offset + pageSize;
- writer.addPage(pageKey.getParentId(), nextOffset, pageSize, totalNumberOfChildren);
+ writer.addPage(pageKey.getParentId(), nextOffset, pageSize, PageWriter.UNKNOWN_TOTAL_SIZE);
} finally {
walker.dispose();
}
View
2  connectors/modeshape-connector-git/src/main/java/org/modeshape/connector/git/GitLexicon.java
@@ -49,6 +49,7 @@
public static final Name TREES = new BasicName(Namespace.URI, "trees");
public static final Name FOLDER = new BasicName(Namespace.URI, "folder");
public static final Name FILE = new BasicName(Namespace.URI, "file");
+ public static final Name RESOURCE = new BasicName(Namespace.URI, "resource");
public static final Name DETAILS = new BasicName(Namespace.URI, "details");
public static final Name DETAILED_COMMIT = new BasicName(Namespace.URI, "detailedCommit");
@@ -64,4 +65,5 @@
public static final Name HISTORY = new BasicName(Namespace.URI, "history");
public static final Name DIFF = new BasicName(Namespace.URI, "diff");
public static final Name TREE = new BasicName(Namespace.URI, "tree");
+ public static final Name DETAIL = new BasicName(Namespace.URI, "detail");
}
View
3  connectors/modeshape-connector-git/src/main/java/org/modeshape/connector/git/GitTags.java
@@ -77,8 +77,9 @@ public Document execute( Repository repository,
// Construct the references to other nodes in this source ...
ObjectId objId = commit.getId();
writer.addProperty(GitLexicon.OBJECT_ID, objId.name());
- writer.addProperty(GitLexicon.TREE, GitTree.referenceToTree(objId, tagName, values));
+ writer.addProperty(GitLexicon.TREE, GitTree.referenceToTree(objId, objId.name(), values));
writer.addProperty(GitLexicon.HISTORY, GitHistory.referenceToHistory(objId, tagName, values));
+ writer.addProperty(GitLexicon.DETAIL, GitCommitDetails.referenceToCommit(objId, values));
} finally {
walker.dispose();
}
View
20 connectors/modeshape-connector-git/src/main/java/org/modeshape/connector/git/GitTree.java
@@ -24,6 +24,7 @@
package org.modeshape.connector.git;
import java.io.IOException;
+import javax.jcr.RepositoryException;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.GitAPIException;
import org.eclipse.jgit.lib.ObjectId;
@@ -35,7 +36,6 @@
import org.eclipse.jgit.treewalk.filter.PathFilter;
import org.infinispan.schematic.document.Document;
import org.modeshape.jcr.JcrLexicon;
-import org.modeshape.jcr.JcrNtLexicon;
import org.modeshape.jcr.api.value.DateTime;
import org.modeshape.jcr.federation.spi.DocumentWriter;
import org.modeshape.jcr.federation.spi.PageKey;
@@ -106,6 +106,7 @@ public Document execute( Repository repository,
writer.addProperty(GitLexicon.COMMITTED, committed);
writer.addProperty(GitLexicon.TITLE, commit.getShortMessage());
writer.addProperty(GitLexicon.HISTORY, GitHistory.referenceToHistory(objId, branchOrTagOrObjectId, values));
+ writer.addProperty(GitLexicon.DETAIL, GitCommitDetails.referenceToCommit(objId, values));
// Add the top-level children of the directory ...
addInformationForPath(repository, git, writer, commit, "", spec, values);
@@ -190,7 +191,7 @@ protected void addInformationForPath( Repository repository,
String committer = folderCommit.getCommitterIdent().getName();
String author = folderCommit.getAuthorIdent().getName();
DateTime committed = values.dateFrom(folderCommit.getCommitTime());
- writer.setPrimaryType(JcrNtLexicon.FOLDER);
+ writer.setPrimaryType(GitLexicon.FOLDER);
writer.addProperty(JcrLexicon.CREATED, committed);
writer.addProperty(JcrLexicon.CREATED_BY, committer);
writer.addProperty(GitLexicon.OBJECT_ID, folderCommit.getId().name());
@@ -217,7 +218,7 @@ protected void addInformationForPath( Repository repository,
String author = fileCommit.getAuthorIdent().getName();
DateTime committed = values.dateFrom(fileCommit.getCommitTime());
if (isContentNode) {
- writer.setPrimaryType(JcrNtLexicon.RESOURCE);
+ writer.setPrimaryType(GitLexicon.RESOURCE);
writer.addProperty(JcrLexicon.LAST_MODIFIED, committed);
writer.addProperty(JcrLexicon.LAST_MODIFIED_BY, committer);
writer.addProperty(GitLexicon.OBJECT_ID, fileCommit.getId().name());
@@ -241,8 +242,19 @@ protected void addInformationForPath( Repository repository,
}
}
writer.addProperty(JcrLexicon.DATA, value);
+ if (connector.includeMimeType()) {
+ try {
+ String filename = spec.parameter(spec.parameterCount() - 1); // the last is 'jcr:content'
+ String mimeType = value.getMimeType(filename);
+ if (mimeType != null) writer.addProperty(JcrLexicon.MIMETYPE, mimeType);
+ } catch (RepositoryException e) {
+ // do nothing
+ } catch (IOException e) {
+ // do nothing
+ }
+ }
} else {
- writer.setPrimaryType(JcrNtLexicon.FILE);
+ writer.setPrimaryType(GitLexicon.FILE);
writer.addProperty(JcrLexicon.CREATED, committed);
writer.addProperty(JcrLexicon.CREATED_BY, committer);
writer.addProperty(GitLexicon.OBJECT_ID, fileCommit.getId().name());
View
22 connectors/modeshape-connector-git/src/main/resources/org/modeshape/connector/git/git.cnd
@@ -39,13 +39,16 @@
- git:objectId (string) mandatory protected
[git:navigable] mixin
-- git:tree (reference) mandatory protected
+- git:tree (reference) mandatory protected < 'git:folder'
[git:historical] mixin
-- git:history (reference) mandatory protected
+- git:history (reference) mandatory protected < 'git:commit'
+
+[git:detailed] mixin
+- git:detail (reference) mandatory protected < 'git:detailedCommit'
// Represents a branch or tag or commit ...
-[git:reference] > git:referenceable, git:navigable, git:historical abstract
+[git:reference] > git:referenceable, git:navigable, git:historical, git:detailed abstract
[git:committed] > git:referenceable mixin
- git:author (string) mandatory protected
@@ -54,10 +57,10 @@
- git:title (string) mandatory protected
[git:root]
++ tree (git:trees) abort protected primary // the 'tree' subgraph is considered primary
+ branches (git:branches) abort protected
+ tags (git:tags) abort protected
+ commits (git:commits) abort protected
-+ trees (git:trees) abort protected
+ commit (git:details) abort protected
//------------------------------------------------------------------------------
@@ -65,6 +68,7 @@
//------------------------------------------------------------------------------
[git:branches]
++ master (git:branch) abort protected primary // the 'master' branch is considered primary if it exists
+ * (git:branch) abort protected
[git:branch] > git:reference
@@ -84,9 +88,7 @@
[git:object]
+ * (git:commit) = git:commit abort protected
-[git:commit] > git:committed
-- git:message (string) mandatory protected
-- git:parents (reference) multiple mandatory protected
+[git:commit] > git:committed, git:navigable, git:detailed
//------------------------------------------------------------------------------
// The content showing the details of each commit
@@ -96,12 +98,16 @@
+ * (git:detailedCommit) abort protected
[git:detailedCommit] > git:commit
+- git:message (string) mandatory protected
+- git:parents (reference) multiple mandatory protected < 'git:detailedCommit'
+- git:diff (string) mandatory protected
//------------------------------------------------------------------------------
// The content with the folder and file structure of a particular object
//------------------------------------------------------------------------------
[git:trees]
++ master (git:folder) abort protected primary // the 'master' tree is considered primary if it exists
+ * (git:folder) abort protected
[git:folder] > nt:folder, git:committed, git:historical
@@ -109,5 +115,7 @@
[git:file] > nt:file, git:committed
+[git:resource] > nt:resource, git:committed
+
View
137 connectors/modeshape-connector-git/src/test/java/org/modeshape/connector/git/GitConnectorTest.java
@@ -24,14 +24,18 @@
package org.modeshape.connector.git;
import static org.hamcrest.core.Is.is;
+import static org.hamcrest.core.IsInstanceOf.instanceOf;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.core.IsSame.sameInstance;
import static org.junit.Assert.assertThat;
+import javax.jcr.Item;
import javax.jcr.Node;
+import javax.jcr.Value;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.modeshape.common.FixFor;
import org.modeshape.jcr.MultiUseAbstractTest;
import org.modeshape.jcr.RepositoryConfiguration;
import org.modeshape.jcr.api.Session;
@@ -97,18 +101,19 @@ public void shouldReadBranches() throws Exception {
public void shouldReadTreeSubgraph() throws Exception {
Node git = gitNode();
Node tree = git.getNode("tree");
- print = true;
- print(tree, false, 100, 2);
+ // print = true;
+ navigate(tree, false, 100, 2);
}
@Test
public void shouldReadCommitSubgraph() throws Exception {
Node git = gitNode();
Node commit = git.getNode("commit");
- print = true;
- print(commit, false, 100, 2);
+ // print = true;
+ navigate(commit, false, 100, 2);
}
+ @FixFor( "MODE-1732" )
@Test
public void shouldFollowReferenceFromRecentTagToCommit() throws Exception {
Node git = gitNode();
@@ -117,8 +122,38 @@ public void shouldFollowReferenceFromRecentTagToCommit() throws Exception {
assertThat(tag.getProperty("git:tree").getString(), is(notNullValue()));
assertThat(tag.getProperty("git:history").getString(), is(notNullValue()));
Node tagTree = tag.getProperty("git:tree").getNode();
- assertThat(tagTree.getPath().startsWith(git.getPath() + "/tree/modeshape-3.0.0.Final"), is(true));
+ assertThat(tagTree.getPath(), is(treePathFor(tag)));
assertChildrenInclude(tagTree, expectedTopLevelFileAndFolderNames());
+
+ // Load some of the child nodes ...
+ Node pomFile = tagTree.getNode("pom.xml");
+ assertThat(pomFile.getPrimaryNodeType().getName(), is("git:file"));
+ assertNodeHasObjectIdProperty(pomFile);
+ assertNodeHasCommittedProperties(pomFile);
+ Node pomContent = pomFile.getNode("jcr:content");
+ assertNodeHasCommittedProperties(pomContent);
+ // TODO: MODE-1732 Uncomment this next line ...
+ // assertThat(pomContent.getProperty("jcr:data").getString(), is(notNullValue()));
+
+ Node readmeFile = tagTree.getNode("README.md");
+ assertThat(readmeFile.getPrimaryNodeType().getName(), is("git:file"));
+ assertNodeHasObjectIdProperty(readmeFile);
+ assertNodeHasCommittedProperties(readmeFile);
+ Node readmeContent = readmeFile.getNode("jcr:content");
+ assertNodeHasCommittedProperties(readmeContent);
+ // TODO: MODE-1732 Uncomment this next line ...
+ // assertThat(readmeContent.getProperty("jcr:data").getString(), is(notNullValue()));
+
+ Node parentModule = tagTree.getNode("modeshape-parent");
+ assertThat(parentModule.getPrimaryNodeType().getName(), is("git:folder"));
+ assertNodeHasObjectIdProperty(parentModule);
+ assertNodeHasCommittedProperties(parentModule);
+ }
+
+ protected String treePathFor( Node node ) throws Exception {
+ Node git = gitNode();
+ String commitId = node.getProperty("git:objectId").getString();
+ return git.getPath() + "/tree/" + commitId;
}
@Test
@@ -129,7 +164,7 @@ public void shouldFollowReferenceFromOldTagToCommit() throws Exception {
assertThat(tag.getProperty("git:tree").getString(), is(notNullValue()));
assertThat(tag.getProperty("git:history").getString(), is(notNullValue()));
Node tagTree = tag.getProperty("git:tree").getNode();
- assertThat(tagTree.getPath().startsWith(git.getPath() + "/tree/dna-0.2"), is(true));
+ assertThat(tagTree.getPath(), is(treePathFor(tag)));
assertChildrenInclude(tagTree, "pom.xml", "dna-jcr", "dna-common", ".project");
}
@@ -142,6 +177,96 @@ public void shouldContainTagsAndBranchNamesAndCommitsUnderTreeNode() throws Exce
assertChildrenInclude(tree, expectedTagNames());
}
+ @Test
+ public void shouldFindMasterBranchAsPrimaryItemUnderBranchNode() throws Exception {
+ Node git = gitNode();
+ Node branches = git.getNode("branches");
+ Item primaryItem = branches.getPrimaryItem();
+ assertThat(primaryItem, is(notNullValue()));
+ assertThat(primaryItem, is(instanceOf(Node.class)));
+ Node primaryNode = (Node)primaryItem;
+ assertThat(primaryNode.getName(), is("master"));
+ assertThat(primaryNode.getParent(), is(sameInstance(branches)));
+ assertThat(primaryNode, is(sameInstance(branches.getNode("master"))));
+ }
+
+ @Test
+ public void shouldFindMasterBranchAsPrimaryItemUnderTreeNode() throws Exception {
+ Node git = gitNode();
+ Node tree = git.getNode("tree");
+ Item primaryItem = tree.getPrimaryItem();
+ assertThat(primaryItem, is(notNullValue()));
+ assertThat(primaryItem, is(instanceOf(Node.class)));
+ Node primaryNode = (Node)primaryItem;
+ assertThat(primaryNode.getName(), is("master"));
+ assertThat(primaryNode.getParent(), is(sameInstance(tree)));
+ assertThat(primaryNode, is(sameInstance(tree.getNode("master"))));
+ }
+
+ @Test
+ public void shouldFindTreeBranchAsPrimaryItemUnderGitRoot() throws Exception {
+ Node git = gitNode();
+ Node tree = git.getNode("tree");
+ assertThat(tree, is(notNullValue()));
+ Item primaryItem = git.getPrimaryItem();
+ assertThat(primaryItem, is(notNullValue()));
+ assertThat(primaryItem, is(instanceOf(Node.class)));
+ Node primaryNode = (Node)primaryItem;
+ assertThat(primaryNode.getName(), is(tree.getName()));
+ assertThat(primaryNode.getParent(), is(sameInstance(git)));
+ assertThat(primaryNode, is(sameInstance(tree)));
+ }
+
+ @Test
+ public void shouldFindLatestCommitInMasterBranch() throws Exception {
+ Node git = gitNode();
+ Node commits = git.getNode("commits");
+ Node master = commits.getNode("master");
+ Node commit = master.getNodes().nextNode(); // the first commit in the history of the 'master' branch ...
+ // print = true;
+ printDetails(commit);
+ assertNodeHasObjectIdProperty(commit, commit.getName());
+ assertNodeHasCommittedProperties(commit);
+ assertThat(commit.getProperty("git:title").getString(), is(notNullValue()));
+ assertThat(commit.getProperty("git:tree").getNode().getPath(), is(git.getPath() + "/tree/" + commit.getName()));
+ assertThat(commit.getProperty("git:detail").getNode().getPath(), is(git.getPath() + "/commit/" + commit.getName()));
+ }
+
+ @Test
+ public void shouldFindLatestCommitDetailsInMasterBranch() throws Exception {
+ Node git = gitNode();
+ Node commits = git.getNode("commit");
+ Node commit = commits.getNodes().nextNode(); // the first commit ...
+ // print = true;
+ printDetails(commit);
+ assertNodeHasObjectIdProperty(commit);
+ assertNodeHasCommittedProperties(commit);
+ assertThat(commit.getProperty("git:parents").isMultiple(), is(true));
+ for (Value parentValue : commit.getProperty("git:parents").getValues()) {
+ String identifier = parentValue.getString();
+ Node parent = getSession().getNodeByIdentifier(identifier);
+ assertThat(parent, is(notNullValue()));
+ }
+ assertThat(commit.getProperty("git:diff").getString(), is(notNullValue()));
+ assertThat(commit.getProperty("git:tree").getNode().getPath(), is(treePathFor(commit)));
+ }
+
+ protected void assertNodeHasObjectIdProperty( Node node ) throws Exception {
+ assertThat(node.getProperty("git:objectId").getString(), is(notNullValue()));
+ }
+
+ protected void assertNodeHasObjectIdProperty( Node node,
+ String commitId ) throws Exception {
+ assertThat(node.getProperty("git:objectId").getString(), is(commitId));
+ }
+
+ protected void assertNodeHasCommittedProperties( Node node ) throws Exception {
+ assertThat(node.getProperty("git:author").getString(), is(notNullValue()));
+ assertThat(node.getProperty("git:committer").getString(), is(notNullValue()));
+ assertThat(node.getProperty("git:committed").getDate(), is(notNullValue()));
+ assertThat(node.getProperty("git:title").getString(), is(notNullValue()));
+ }
+
/**
* The <i>minimal</i> names of the files and/or folders that are expected to exist at the top-level of the Git repository.
* Additional file and folder names will be acceptable.
View
1  connectors/modeshape-connector-git/src/test/resources/config/repo-config-git-federation.json
@@ -8,6 +8,7 @@
"classname" : "org.modeshape.connector.git.GitConnector",
"directoryPath" : "../../",
"remoteName" : "upstream,origin",
+ "includeMimeType" : true,
},
}
}
View
6 modeshape-jcr/src/main/java/org/modeshape/jcr/federation/FederatedDocumentStore.java
@@ -460,13 +460,15 @@ private Object convertReferenceValue( Object value,
NodeKeyReference ref = (NodeKeyReference)value;
NodeKey key = ref.getNodeKey();
NodeKey converted = documentIdToNodeKey(sourceName, key.toString());
+ boolean foreign = !converted.getSourceKey().equals(localSourceKey);
ReferenceFactory factory = ref.isWeak() ? translator.getReferenceFactory() : translator.getReferenceFactory();
- return factory.create(converted);
+ return factory.create(converted, foreign);
} else if (value instanceof StringReference) {
StringReference ref = (StringReference)value;
NodeKey converted = documentIdToNodeKey(sourceName, ref.toString());
+ boolean foreign = !converted.getSourceKey().equals(localSourceKey);
ReferenceFactory factory = ref.isWeak() ? translator.getReferenceFactory() : translator.getReferenceFactory();
- return factory.create(converted);
+ return factory.create(converted, foreign);
}
return value;
}
View
57 modeshape-jcr/src/test/java/org/modeshape/jcr/AbstractJcrRepositoryTest.java
@@ -44,6 +44,7 @@
import org.junit.Before;
import org.modeshape.common.statistic.Stopwatch;
import org.modeshape.common.util.StringUtil;
+import org.modeshape.jcr.api.JcrTools;
import org.modeshape.jcr.value.Path;
import org.modeshape.jcr.value.Path.Segment;
@@ -192,6 +193,12 @@ protected boolean hasMixin( Node node,
return false;
}
+ protected void printDetails( Node node ) throws RepositoryException {
+ if (print) {
+ new JcrTools().printNode(node);
+ }
+ }
+
protected void print() throws RepositoryException {
print(session().getRootNode(), true);
}
@@ -201,6 +208,10 @@ protected void print( String path ) throws RepositoryException {
print(node, true);
}
+ protected void print( Node node ) throws RepositoryException {
+ print(node, true);
+ }
+
protected void print( Node node,
boolean includeSystem ) throws RepositoryException {
print(node, includeSystem, Integer.MAX_VALUE, Integer.MAX_VALUE);
@@ -238,6 +249,52 @@ protected void print( Node node,
}
}
+ protected void navigate( String path ) throws RepositoryException {
+ Node node = session().getRootNode().getNode(relativePath(path));
+ navigate(node, true);
+ }
+
+ protected void navigate( Node node ) throws RepositoryException {
+ navigate(node, true);
+ }
+
+ protected void navigate( Node node,
+ boolean includeSystem ) throws RepositoryException {
+ navigate(node, includeSystem, Integer.MAX_VALUE, Integer.MAX_VALUE);
+ }
+
+ protected void navigate( Node node,
+ boolean includeSystem,
+ int maxNumberOfChildren ) throws RepositoryException {
+ navigate(node, includeSystem, maxNumberOfChildren, Integer.MAX_VALUE);
+ }
+
+ protected void navigate( Node node,
+ boolean includeSystem,
+ int maxNumberOfChildren,
+ int depth ) throws RepositoryException {
+ if (depth > 0) {
+ if (!includeSystem && node.getPath().equals("/jcr:system")) return;
+ if (node.getDepth() != 0) {
+ int snsIndex = node.getIndex();
+ String segment = node.getName() + (snsIndex > 1 ? ("[" + snsIndex + "]") : "");
+ if (print) System.out.println(StringUtil.createString(' ', 2 * node.getDepth()) + '/' + segment);
+ }
+ int nextDepth = depth - 1;
+ if (nextDepth <= 0) return;
+ NodeIterator children = node.getNodes();
+ int count = 0;
+ while (children.hasNext()) {
+ if (count >= maxNumberOfChildren) {
+ if (print) System.out.println(StringUtil.createString(' ', 2 * (node.getDepth() + 1)) + "...");
+ break;
+ }
+ navigate(children.nextNode(), includeSystem, maxNumberOfChildren, nextDepth);
+ ++count;
+ }
+ }
+ }
+
private static String getRandomString( int length ) {
StringBuffer buff = new StringBuffer(length);
Please sign in to comment.
Something went wrong with that request. Please try again.