@BeforeClass public static void beforeAll() throws Exception { initTestDatabase(); RepositoryConfiguration config = RepositoryConfiguration.read("config/repo-config-jdbc-meta-federation.json"); startRepository(config); Session session = getSession(); Node testRoot = session.getRootNode().addNode("testRoot"); session.save(); FederationManager fedMgr = session.getWorkspace().getFederationManager(); fedMgr.createProjection(testRoot.getPath(), "jdbc-meta", "/", "database"); }
@Test public void shouldManuallySequence() throws Exception { URL url = getClass().getClassLoader().getResource("log4j.properties"); assertNotNull(url); Session session = session(); tools.uploadFile(session, "/files/log4j.properties", url); Node propFile = session.getNode("/files/log4j.properties"); Property content = propFile.getProperty("jcr:content/jcr:data"); assertNotNull(content); Node output = session.getRootNode().addNode("output"); assertFalse(output.hasNode(TestSequencersHolder.DERIVED_NODE_NAME)); session.sequence("Counting sequencer", content, output); assertTrue(output.hasNode(TestSequencersHolder.DERIVED_NODE_NAME)); session.refresh(false); assertFalse(session.getRootNode().hasNode("files")); assertFalse(session.getRootNode().hasNode("output")); }
private Node createFromAstNode( Node parent, AstNode astNode ) throws RepositoryException { String relativePath = astNode.getAbsolutePath().substring(1); Node sequenceNode = null; // for SNS the absolute path will use first node it finds as the parent so find real parent if possible Node parentNode = getNode(astNode.getParent()); if (parentNode == null) { sequenceNode = parent.addNode(relativePath, astNode.getPrimaryType()); } else { final Session session = (Session)parentNode.getSession(); String jcrName = astNode.getName(); // if first character is a '{' then the name is prefixed by the namespace URL if ((jcrName.charAt(0) == '{') && (jcrName.indexOf('}') != -1)) { final int index = jcrName.indexOf('}'); String localName = jcrName.substring(index + 1); localName = session.encode(localName); jcrName = jcrName.substring(0, (index + 1)) + localName; } else { jcrName = session.encode(jcrName); } sequenceNode = parentNode.addNode(jcrName, astNode.getPrimaryType()); } this.nodeMap.put(astNode, sequenceNode); for (String mixin : astNode.getMixins()) { sequenceNode.addMixin(mixin); } astNode.removeProperty(JcrConstants.JCR_MIXIN_TYPES); astNode.removeProperty(JcrConstants.JCR_PRIMARY_TYPE); return sequenceNode; }
@Test public void shouldCreateFolderAndDocument() throws Exception { Node root = getSession().getNode("/cmis"); String name = "test" + System.currentTimeMillis(); Node node = root.addNode(name, "nt:folder"); assertTrue(name.equals(node.getName())); // node.setProperty("name", "test-name"); root = getSession().getNode("/cmis/" + name); Node node1 = root.addNode("test-1", "nt:file"); // System.out.println("Test: creating binary content"); byte[] content = "Hello World".getBytes(); ByteArrayInputStream bin = new ByteArrayInputStream(content); bin.reset(); // System.out.println("Test: creating content node"); Node contentNode = node1.addNode("jcr:content", "nt:resource"); Binary binary = session.getValueFactory().createBinary(bin); contentNode.setProperty("jcr:data", binary); contentNode.setProperty("jcr:lastModified", Calendar.getInstance()); getSession().save(); }
session.getWorkspace().importXML("/", stream, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW); } catch (Throwable t) { t.printStackTrace(); Node other = session.getRootNode().addNode("Other", "nt:unstructured"); Node a = other.addNode("NodeA", "nt:unstructured"); a.addMixin("mix:referenceable"); other3.setProperty("propC", "value3"); Value[] refValues = new Value[2]; refValues[0] = session.getValueFactory().createValue(other2); refValues[1] = session.getValueFactory().createValue(other3); other3.setProperty("otherNode", a); other3.setProperty("otherNodes", refValues); c.setProperty("notion:singleReference", a); c.setProperty("notion:multipleReferences", refValues); Node b = session.getRootNode().addNode("NodeB", "nt:unstructured"); b.setProperty("myUrl", "http://www.acme.com/foo/bar"); b.setProperty("pathProperty", a.getPath()); session.save(); session.logout();
@Override public Collection<Throwable> restoreRepository(final FedoraSession session, final File backupDirectory) { final Session jcrSession = getJcrSession(session); try { final RepositoryManager repoMgr = ((org.modeshape.jcr.api.Session) jcrSession) .getWorkspace() .getRepositoryManager(); final Collection<Throwable> problems = new ArrayList<>(); repoMgr.restoreRepository(backupDirectory).forEach(x -> problems.add(x.getThrowable())); return problems; } catch (final RepositoryException e) { throw new RepositoryRuntimeException(e); } }
@Test public void shouldAccessRepositoryInfo() throws Exception { Node repoInfo = getSession().getNode("/cmis/repositoryInfo"); // Different Chemistry versions return different things ... assertTrue(repoInfo.getProperty("cmis:productName").getString().contains("OpenCMIS")); assertTrue(repoInfo.getProperty("cmis:productName").getString().contains("InMemory")); assertEquals("Apache Chemistry", repoInfo.getProperty("cmis:vendorName").getString()); assertTrue(repoInfo.getProperty("cmis:productVersion").getString() != null); }
testRoot = session.getRootNode().addNode("testRoot"); testRoot.addNode("node1"); session.save();
String path = federatedNode.getPath() + "/" + childName; Node files = session.getNode(path); assertThat(files.getName(), is(childName)); assertThat(files.getPrimaryNodeType().getName(), is("nt:folder")); Node dir1 = session.getNode(path + "/dir1"); Node dir2 = session.getNode(path + "/dir2"); Node dir3 = session.getNode(path + "/dir3"); Node simpleJson = session.getNode(path + "/dir3/simple.json"); Node simpleText = session.getNode(path + "/dir3/simple.txt"); assertFolder(dir1, getTestFile("dir1")); assertFolder(dir2, getTestFile("dir2")); Node simpleJson2 = session.getNodeByIdentifier(externalNodeId); assertFile(simpleJson2, getTestFile("dir3/simple.json")); Node simpleJson3 = session.getNode(path + "/dir3/simple.json"); assertFile(simpleJson3, getTestFile("dir3/simple.json")); session.getNode(path + "/dir3/non-existant.oops"); fail("Should not have been able to find a non-existing file"); } catch (PathNotFoundException e) {
@Before public void before() throws Exception { testRoot = getSession().getRootNode().getNode("repos"); }
@Test public void shouldFindLatestCommitDetailsInMasterBranch() throws Exception { Node git = gitRemoteNode(); 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))); }
@Override public Collection<Throwable> backupRepository(final FedoraSession session, final File backupDirectory) { final Session jcrSession = getJcrSession(session); try { final RepositoryManager repoMgr = ((org.modeshape.jcr.api.Session) jcrSession) .getWorkspace() .getRepositoryManager(); final Collection<Throwable> problems = new ArrayList<>(); repoMgr.backupRepository(backupDirectory).forEach(x -> problems.add(x.getThrowable())); return problems; } catch (final RepositoryException e) { throw new RepositoryRuntimeException(e); } }
@Test public void shouldBrowseExternalWorkspace() throws Exception { Session session2 = session.getRepository().login("readonly-fls"); assertTrue(session2 != null); Node node = session2.getNode("/"); NodeIterator it = node.getNodes(); ArrayList<String> dirs = new ArrayList<>(); dirs.add("dir1"); dirs.add("dir2"); dirs.add("dir3"); while (it.hasNext()) { dirs.remove(it.nextNode().getName()); } assertEquals(0, dirs.size()); }
@Test public void shouldModifyDocument() throws Exception { Node file = getSession().getNode("/cmis/My_Folder-0-0/My_Document-1-0"); PropertyIterator it = file.getProperties(); while (it.hasNext()) { Object val = it.nextProperty(); printMessage("property=>" + val); } file.setProperty("StringProp", "modeshape"); getSession().save(); }
@BeforeClass public static void beforeAll() throws Exception { loadGitRepositoryData(); RepositoryConfiguration config = RepositoryConfiguration.read("config/repo-config-git-federation.json"); startRepository(config); Session session = getSession(); Node testRoot = session.getRootNode().addNode("repos"); session.save(); FederationManager fedMgr = session.getWorkspace().getFederationManager(); fedMgr.createProjection(testRoot.getPath(), "remote-git-repo", "/", "git-modeshape-remote"); fedMgr.createProjection(testRoot.getPath(), "local-git-repo", "/", "git-modeshape-local"); }
public void create( Node parentNode, String childName ) throws RepositoryException { Session session = (Session)parentNode.getSession(); FederationManager fedMgr = session.getWorkspace().getFederationManager(); fedMgr.createProjection(parentNode.getPath(), getName(), "/", childName); }
@Test public void shouldAccessCreatedByPropertyForDocument() throws Exception { Node node = getSession().getNode("/cmis/My_Folder-0-0/My_Document-1-0"); String name = node.getProperty("jcr:createdBy").getString(); assertEquals("unknown", name); }
private Node createFromAstNode( Node parent, AstNode astNode ) throws RepositoryException { String relativePath = astNode.getAbsolutePath().substring(1); Node sequenceNode = null; // for SNS the absolute path will use first node it finds as the parent so find real parent if possible Node parentNode = getNode(astNode.getParent()); if (parentNode == null) { sequenceNode = parent.addNode(relativePath, astNode.getPrimaryType()); } else { final Session session = (Session)parentNode.getSession(); String jcrName = astNode.getName(); // if first character is a '{' then the name is prefixed by the namespace URL if ((jcrName.charAt(0) == '{') && (jcrName.indexOf('}') != -1)) { final int index = jcrName.indexOf('}'); String localName = jcrName.substring(index + 1); localName = session.encode(localName); jcrName = jcrName.substring(0, (index + 1)) + localName; } else { jcrName = session.encode(jcrName); } sequenceNode = parentNode.addNode(jcrName, astNode.getPrimaryType()); } this.nodeMap.put(astNode, sequenceNode); for (String mixin : astNode.getMixins()) { sequenceNode.addMixin(mixin); } astNode.removeProperty(JcrConstants.JCR_MIXIN_TYPES); astNode.removeProperty(JcrConstants.JCR_PRIMARY_TYPE); return sequenceNode; }
protected static void registerNodeTypes( Session session, String pathToClasspathResource ) throws RepositoryException, IOException { URL url = resourceUrl(pathToClasspathResource); session.getWorkspace().getNodeTypeManager().registerNodeTypes(url, true); }
@Test public void shouldAccessObjectIdPropertyForFolder() throws Exception { Node node = getSession().getNode("/cmis/My_Folder-0-0"); String objectId = node.getProperty("jcr:uuid").getString(); assertTrue(objectId != null); }