javax.jcr.Node

Here are the examples of the java api class javax.jcr.Node taken from open source projects.

1. SimpleQueryTest#testLogicalExpression()

Project: jackrabbit
Source File: SimpleQueryTest.java
View license
public void testLogicalExpression() throws Exception {
    Node foo = testRootNode.addNode("foo");
    foo.setProperty("a", 1);
    foo.setProperty("b", 2);
    foo.setProperty("c", 3);
    Node bar = testRootNode.addNode("bar");
    bar.setProperty("a", 0);
    bar.setProperty("b", 2);
    bar.setProperty("c", 0);
    Node bla = testRootNode.addNode("bla");
    bla.setProperty("a", 1);
    bla.setProperty("b", 0);
    bla.setProperty("c", 3);
    testRootNode.save();
    String sql = "SELECT * FROM nt:unstructured WHERE a=1 and b=2 or c=3";
    Query q = superuser.getWorkspace().getQueryManager().createQuery(sql, Query.SQL);
    QueryResult result = q.execute();
    checkResult(result, new Node[] { foo, bla });
    String xpath = "//*[@a=1 and @b=2 or @c=3] ";
    q = superuser.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
    result = q.execute();
    checkResult(result, new Node[] { foo, bla });
}

2. CndSequencer#processPropertyDefinition()

Project: modeshape
Source File: CndSequencer.java
View license
private void processPropertyDefinition(Node nodeTypeNode, PropertyDefinition propertyDefinition) throws RepositoryException {
    Node propertyDefinitionNode = nodeTypeNode.addNode(PROPERTY_DEFINITION, PROPERTY_DEFINITION);
    if (!RESIDUAL_ITEM_NAME.equals(propertyDefinition.getName())) {
        propertyDefinitionNode.setProperty(NAME, propertyDefinition.getName());
    }
    propertyDefinitionNode.setProperty(AUTO_CREATED, propertyDefinition.isAutoCreated());
    propertyDefinitionNode.setProperty(MANDATORY, propertyDefinition.isMandatory());
    propertyDefinitionNode.setProperty(MULTIPLE, propertyDefinition.isMultiple());
    propertyDefinitionNode.setProperty(PROTECTED, propertyDefinition.isProtected());
    propertyDefinitionNode.setProperty(ON_PARENT_VERSION, OnParentVersionAction.nameFromValue(propertyDefinition.getOnParentVersion()));
    propertyDefinitionNode.setProperty(REQUIRED_TYPE, org.modeshape.jcr.api.PropertyType.nameFromValue(propertyDefinition.getRequiredType()).toUpperCase());
    String[] availableQueryOperators = propertyDefinition.getAvailableQueryOperators();
    propertyDefinitionNode.setProperty(AVAILABLE_QUERY_OPERATORS, availableQueryOperators != null ? availableQueryOperators : new String[0]);
    Value[] defaultValues = propertyDefinition.getDefaultValues();
    propertyDefinitionNode.setProperty(DEFAULT_VALUES, defaultValues != null ? defaultValues : new Value[0]);
    String[] valueConstraints = propertyDefinition.getValueConstraints();
    propertyDefinitionNode.setProperty(VALUE_CONSTRAINTS, valueConstraints != null ? valueConstraints : new String[0]);
    propertyDefinitionNode.setProperty(IS_FULL_TEXT_SEARCHABLE, propertyDefinition.isFullTextSearchable());
    propertyDefinitionNode.setProperty(IS_QUERY_ORDERABLE, propertyDefinition.isQueryOrderable());
}

3. AbstractJcrResourceResolverTest#setUp()

View license
@Before
public final void setUp() throws RepositoryException {
    session = context.resourceResolver().adaptTo(Session.class);
    // prepare some test data using JCR API
    Node rootNode = getTestRootNode();
    Node node1 = rootNode.addNode("node1", JcrConstants.NT_UNSTRUCTURED);
    node1.setProperty("stringProp", STRING_VALUE);
    node1.setProperty("stringArrayProp", STRING_ARRAY_VALUE);
    node1.setProperty("integerProp", INTEGER_VALUE);
    node1.setProperty("doubleProp", DOUBLE_VALUE);
    node1.setProperty("booleanProp", BOOLEAN_VALUE);
    node1.setProperty("dateProp", DateUtils.toCalendar(DATE_VALUE));
    node1.setProperty("calendarProp", CALENDAR_VALUE);
    node1.setProperty("binaryProp", session.getValueFactory().createBinary(new ByteArrayInputStream(BINARY_VALUE)));
    node1.addNode("node11", JcrConstants.NT_UNSTRUCTURED);
    node1.addNode("node12", JcrConstants.NT_UNSTRUCTURED);
    session.save();
}

4. SQL2OrderByTest#testOrderByMVP()

Project: jackrabbit
Source File: SQL2OrderByTest.java
View license
/**
     * SQL2 Test for JCR-2906
     */
public void testOrderByMVP() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    Node n2 = testRootNode.addNode("node2");
    Node n3 = testRootNode.addNode("node3");
    Node n4 = testRootNode.addNode("node4");
    Node n5 = testRootNode.addNode("node5");
    n1.setProperty("text", new String[] { "ccc" });
    n2.setProperty("text", new String[] { "eee", "bbb" });
    n3.setProperty("text", new String[] { "aaa" });
    n4.setProperty("text", new String[] { "bbb", "aaa" });
    n5.setProperty("text", new String[] { "eee", "aaa" });
    testRootNode.getSession().save();
    String sql = "SELECT value FROM [nt:unstructured] WHERE ISCHILDNODE([" + testRoot + "]) ORDER BY text";
    checkSeq(executeSQL2Query(sql), new Node[] { n3, n4, n1, n5, n2 });
}

5. LuceneIndexDescendantSpellcheckTest#createSuggestIndex()

View license
private void createSuggestIndex(Node rootNode, String name, String indexedNodeType, String indexedPropertyName) throws Exception {
    Node def = JcrUtils.getOrAddNode(rootNode, INDEX_DEFINITIONS_NAME).addNode(name, INDEX_DEFINITIONS_NODE_TYPE);
    def.setProperty(TYPE_PROPERTY_NAME, LuceneIndexConstants.TYPE_LUCENE);
    def.setProperty(REINDEX_PROPERTY_NAME, true);
    def.setProperty("name", name);
    def.setProperty(LuceneIndexConstants.COMPAT_MODE, IndexFormatVersion.V2.getVersion());
    def.setProperty(EVALUATE_PATH_RESTRICTION, true);
    Node propertyIdxDef = def.addNode(INDEX_RULES, JcrConstants.NT_UNSTRUCTURED).addNode(indexedNodeType, JcrConstants.NT_UNSTRUCTURED).addNode(LuceneIndexConstants.PROP_NODE, JcrConstants.NT_UNSTRUCTURED).addNode("indexedProperty", JcrConstants.NT_UNSTRUCTURED);
    propertyIdxDef.setProperty("analyzed", true);
    propertyIdxDef.setProperty(PROP_USE_IN_SPELLCHECK, true);
    propertyIdxDef.setProperty("name", indexedPropertyName);
}

6. LuceneIndexDescendantSuggestionTest#createSuggestIndex()

View license
private void createSuggestIndex(Node rootNode, String name, String indexedNodeType, String indexedPropertyName) throws Exception {
    Node def = JcrUtils.getOrAddNode(rootNode, INDEX_DEFINITIONS_NAME).addNode(name, INDEX_DEFINITIONS_NODE_TYPE);
    def.setProperty(TYPE_PROPERTY_NAME, LuceneIndexConstants.TYPE_LUCENE);
    def.setProperty(REINDEX_PROPERTY_NAME, true);
    def.setProperty("name", name);
    def.setProperty(LuceneIndexConstants.COMPAT_MODE, IndexFormatVersion.V2.getVersion());
    def.setProperty(EVALUATE_PATH_RESTRICTION, true);
    Node propertyIdxDef = def.addNode(INDEX_RULES, JcrConstants.NT_UNSTRUCTURED).addNode(indexedNodeType, JcrConstants.NT_UNSTRUCTURED).addNode(LuceneIndexConstants.PROP_NODE, JcrConstants.NT_UNSTRUCTURED).addNode("indexedProperty", JcrConstants.NT_UNSTRUCTURED);
    propertyIdxDef.setProperty("analyzed", true);
    propertyIdxDef.setProperty(PROP_USE_IN_SUGGEST, true);
    propertyIdxDef.setProperty("name", indexedPropertyName);
}

7. LuceneIndexSuggestionTest#createSuggestIndex()

View license
private void createSuggestIndex(String name, String indexedNodeType, String indexedPropertyName, boolean addFullText, boolean suggestAnalyzed) throws Exception {
    Node def = root.getNode(INDEX_DEFINITIONS_NAME).addNode(name, INDEX_DEFINITIONS_NODE_TYPE);
    def.setProperty(TYPE_PROPERTY_NAME, LuceneIndexConstants.TYPE_LUCENE);
    def.setProperty(REINDEX_PROPERTY_NAME, true);
    def.setProperty("name", name);
    def.setProperty(LuceneIndexConstants.COMPAT_MODE, IndexFormatVersion.V2.getVersion());
    if (suggestAnalyzed) {
        def.addNode(LuceneIndexConstants.SUGGESTION_CONFIG).setProperty("suggestAnalyzed", suggestAnalyzed);
    }
    Node propertyIdxDef = def.addNode(INDEX_RULES, JcrConstants.NT_UNSTRUCTURED).addNode(indexedNodeType, JcrConstants.NT_UNSTRUCTURED).addNode(LuceneIndexConstants.PROP_NODE, JcrConstants.NT_UNSTRUCTURED).addNode("indexedProperty", JcrConstants.NT_UNSTRUCTURED);
    propertyIdxDef.setProperty("propertyIndex", true);
    propertyIdxDef.setProperty("analyzed", true);
    propertyIdxDef.setProperty("useInSuggest", true);
    if (addFullText) {
        propertyIdxDef.setProperty("nodeScopeIndex", true);
    }
    propertyIdxDef.setProperty("name", indexedPropertyName);
}

8. JcrSessionTest#initializeData()

Project: modeshape
Source File: JcrSessionTest.java
View license
protected void initializeData() throws Exception {
    Node root = session.getRootNode();
    Node a = root.addNode("a");
    Node b = a.addNode("b");
    Node c = b.addNode("c");
    a.addMixin("mix:lockable");
    a.setProperty("stringProperty", "value");
    b.addMixin("mix:referenceable");
    b.setProperty("booleanProperty", true);
    c.setProperty("stringProperty", "value");
    c.setProperty("multiLineProperty", MULTI_LINE_VALUE);
    session.save();
}

9. JoinTest#setUp()

Project: jackrabbit
Source File: JoinTest.java
View license
@Override
protected void setUp() throws Exception {
    super.setUp();
    node = testRootNode.addNode("jointest", "nt:unstructured");
    Node n1a = node.addNode("n1a", "nt:unstructured");
    n1a.addMixin(NodeType.MIX_REFERENCEABLE);
    n1a.setProperty("type", "parent");
    Node n1b = node.addNode("n1b", "nt:unstructured");
    n1b.addMixin(NodeType.MIX_REFERENCEABLE);
    n1b.setProperty("type", "parent");
    n1b.setProperty("testJoinWithOR4", "testJoinWithOR4");
    Node n1c = node.addNode("n1c", "nt:unstructured");
    n1c.addMixin(NodeType.MIX_REFERENCEABLE);
    n1c.setProperty("type", "parent");
    Node n3 = node.addNode("node3", "nt:unstructured");
    n3.addMixin(NodeType.MIX_REFERENCEABLE);
    n3.setProperty("testref", new String[] { n1a.getIdentifier() }, PropertyType.REFERENCE);
    n3.setProperty("type", "child");
    n3.setProperty("testJoinWithOR4", "testJoinWithOR4");
    Node n4 = node.addNode("node4", "nt:unstructured");
    n4.addMixin(NodeType.MIX_REFERENCEABLE);
    n4.setProperty("testref", new String[] { n1b.getIdentifier() }, PropertyType.REFERENCE);
    n4.setProperty("type", "child");
    Node n5 = node.addNode("node5", "nt:unstructured");
    n5.addMixin(NodeType.MIX_REFERENCEABLE);
    n5.setProperty("testref", new String[] { n1c.getIdentifier() }, PropertyType.REFERENCE);
    n5.setProperty("type", "child");
    Node parent2 = testRootNode.addNode("jointest_other", "nt:unstructured");
    parent2.setProperty("p", "abc");
    Node p2n1 = parent2.addNode("p2n1", "nt:unstructured");
    p2n1.setProperty("p", "abc");
    Node p2n2 = parent2.addNode("p2n2", "nt:unstructured");
    p2n2.setProperty("p", "xyz");
    testRootNode.getSession().save();
}

10. IndexingRuleTest#testRegexp()

Project: jackrabbit
Source File: IndexingRuleTest.java
View license
public void testRegexp() throws RepositoryException {
    Node node1 = testRootNode.addNode(nodeName1, NT_UNSTRUCTURED);
    node1.setProperty("rule", "regexp");
    node1.setProperty("Text", "foo");
    Node node2 = testRootNode.addNode(nodeName2, NT_UNSTRUCTURED);
    node2.setProperty("rule", "regexp");
    node2.setProperty("OtherText", "foo");
    Node node3 = testRootNode.addNode(nodeName3, NT_UNSTRUCTURED);
    node3.setProperty("rule", "regexp");
    node3.setProperty("Textle", "foo");
    testRootNode.save();
    String stmt = "/jcr:root" + testRootNode.getPath() + "/*[jcr:contains(., 'foo')]";
    checkResult(executeQuery(stmt), new Node[] { node1, node2 });
}

11. IndexingRuleTest#testBoost()

Project: jackrabbit
Source File: IndexingRuleTest.java
View license
public void testBoost() throws RepositoryException {
    Node node1 = testRootNode.addNode(nodeName1, NT_UNSTRUCTURED);
    node1.setProperty("rule", "boost1");
    node1.setProperty("text", TEXT);
    Node node2 = testRootNode.addNode(nodeName2, NT_UNSTRUCTURED);
    node2.setProperty("rule", "boost2");
    node2.setProperty("text", TEXT);
    Node node3 = testRootNode.addNode(nodeName3, NT_UNSTRUCTURED);
    node3.setProperty("rule", "boost3");
    node3.setProperty("text", TEXT);
    testRootNode.getSession().save();
    String stmt = "/jcr:root" + testRootNode.getPath() + "/*[jcr:contains(@text, 'quick')] order by @jcr:score descending";
    executeXPathQuery(stmt, new Node[] { node3, node2, node1 });
}

12. OrderByTest#testOrderByScore()

Project: jackrabbit
Source File: OrderByTest.java
View license
public void testOrderByScore() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    Node n2 = testRootNode.addNode("node2");
    Node n3 = testRootNode.addNode("node3");
    n1.setProperty("text", "aaa");
    n1.setProperty("value", 3);
    n2.setProperty("text", "bbb");
    n2.setProperty("value", 2);
    n3.setProperty("text", "ccc");
    n3.setProperty("value", 2);
    testRootNode.save();
    String sql = "SELECT value FROM nt:unstructured WHERE " + "jcr:path LIKE '" + testRoot + "/%' ORDER BY jcr:score, value";
    Query q = qm.createQuery(sql, Query.SQL);
    QueryResult result = q.execute();
    checkResult(result, 3);
    String xpath = "/" + testRoot + "/*[@jcr:primaryType='nt:unstructured'] order by jcr:score(), @value";
    q = qm.createQuery(xpath, Query.XPATH);
    result = q.execute();
    checkResult(result, 3);
}

13. SQL2OrderByTest#testOrderByValMult()

Project: jackrabbit
Source File: SQL2OrderByTest.java
View license
public void testOrderByValMult() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    Node n2 = testRootNode.addNode("node2");
    Node n3 = testRootNode.addNode("node3");
    n1.setProperty("value", 2);
    n1.setProperty("text", "b");
    n2.setProperty("value", 1);
    n2.setProperty("text", "x");
    n3.setProperty("value", 2);
    n3.setProperty("text", "a");
    testRootNode.getSession().save();
    QueryResult qr = executeSQL2Query("SELECT * FROM [nt:base] WHERE ISCHILDNODE([" + testRoot + "]) ORDER BY [value], [text]");
    checkSeq(qr, new Node[] { n2, n3, n1 });
}

14. SQL2OrderByTest#testOrderByValMultDesc()

Project: jackrabbit
Source File: SQL2OrderByTest.java
View license
public void testOrderByValMultDesc() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    Node n2 = testRootNode.addNode("node2");
    Node n3 = testRootNode.addNode("node3");
    n1.setProperty("value", 2);
    n1.setProperty("text", "b");
    n2.setProperty("value", 1);
    n2.setProperty("text", "x");
    n3.setProperty("value", 2);
    n3.setProperty("text", "a");
    testRootNode.getSession().save();
    QueryResult qr = executeSQL2Query("SELECT * FROM [nt:base] WHERE ISCHILDNODE([" + testRoot + "]) ORDER BY [value] desc, [text] desc");
    checkSeq(qr, new Node[] { n1, n3, n2 });
}

15. SQL2OrderByTest#testOrderByValMultMix()

Project: jackrabbit
Source File: SQL2OrderByTest.java
View license
public void testOrderByValMultMix() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    Node n2 = testRootNode.addNode("node2");
    Node n3 = testRootNode.addNode("node3");
    n1.setProperty("value", 2);
    n1.setProperty("text", "b");
    n2.setProperty("value", 1);
    n2.setProperty("text", "x");
    n3.setProperty("value", 2);
    n3.setProperty("text", "a");
    testRootNode.getSession().save();
    QueryResult qr = executeSQL2Query("SELECT * FROM [nt:base] WHERE ISCHILDNODE([" + testRoot + "]) ORDER BY [value], [text] desc");
    checkSeq(qr, new Node[] { n2, n1, n3 });
}

16. AbstractRepositoryTest#createProperties()

View license
protected void createProperties(Node parent, Node reference) throws RepositoryException {
    Node properties = parent.addNode("properties", "nt:unstructured");
    properties.setProperty("boolean", true);
    properties.setProperty("double", 0.123456789);
    properties.setProperty("long", 1234567890);
    properties.setProperty("reference", reference);
    properties.setProperty("string", "test");
    properties.setProperty("multiple", new String[] { "a", "b", "c" });
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(1234567890);
    properties.setProperty("date", calendar);
    byte[] binary = new byte[100 * 1000];
    new Random(1234567890).nextBytes(binary);
    properties.setProperty("binary", new ByteArrayInputStream(binary));
    parent.save();
}

17. TestContentLoader#addExportValues()

View license
/**
     * create nodes with following properties binary & single binary & multival
     * notbinary & single notbinary & multival
     */
private static void addExportValues(Node node, String name) throws RepositoryException, IOException {
    String prefix = "valid";
    if (name.indexOf('<') != -1) {
        prefix = "invalid";
    }
    node = getOrAddNode(node, prefix + "Names");
    String[] texts = new String[] { "multival text 1", "multival text 2", "multival text 3" };
    getOrAddNode(node, prefix + "MultiNoBin").setProperty(name, texts);
    Node resource = getOrAddNode(node, prefix + "MultiBin");
    resource.setProperty("jcr:encoding", ENCODING);
    resource.setProperty("jcr:mimeType", "text/plain");
    String[] values = new String[] { "SGVsbG8gd8O2cmxkLg==", "SGVsbG8gd8O2cmxkLg==" };
    resource.setProperty(name, values, PropertyType.BINARY);
    resource.setProperty("jcr:lastModified", Calendar.getInstance());
    getOrAddNode(node, prefix + "NoBin").setProperty(name, "text 1");
    resource = getOrAddNode(node, "invalidBin");
    resource.setProperty("jcr:encoding", ENCODING);
    resource.setProperty("jcr:mimeType", "text/plain");
    resource.setProperty(name, "Hello wörld.", PropertyType.BINARY);
    resource.setProperty("jcr:lastModified", Calendar.getInstance());
}

18. FileSystemConnectorTest#shouldSupportVariousPropertyTypesInJsonSidecar()

View license
@Test
@FixFor("MODE-2254")
public void shouldSupportVariousPropertyTypesInJsonSidecar() throws Exception {
    Node file = session.getNode("/testRoot/json/dir3/simple.json");
    file.addMixin("flex:anyProperties");
    file.setProperty("string1", "extraValue");
    file.setProperty("string2", "111111111111111111111");
    file.setProperty("boolean", true);
    file.setProperty("double", 12.4);
    file.setProperty("decimal", BigDecimal.valueOf(12.4));
    file.setProperty("long", 12l);
    Calendar now = Calendar.getInstance();
    file.setProperty("date", now);
    session.save();
    assertThat(file.getProperty("string1").getString(), is("extraValue"));
    assertThat(file.getProperty("string2").getString(), is("111111111111111111111"));
    assertThat(file.getProperty("boolean").getBoolean(), is(true));
    assertThat(file.getProperty("double").getDouble(), is(12.4));
    assertThat(file.getProperty("decimal").getDecimal(), is(BigDecimal.valueOf(12.4)));
    assertThat(file.getProperty("long").getLong(), is(12l));
    assertThat(file.getProperty("date").getDate(), is(now));
    assertJsonSidecarFile(jsonProjection, "dir3/simple.json");
}

19. MixinTest#testBuiltInMixin()

Project: jackrabbit
Source File: MixinTest.java
View license
public void testBuiltInMixin() throws RepositoryException {
    // nt:resource is mix:mimeType by its node type definition
    Node n1 = testRootNode.addNode("n1", "nt:resource");
    n1.setProperty("jcr:data", new ByteArrayInputStream("hello world".getBytes()));
    n1.setProperty("jcr:lastModified", Calendar.getInstance());
    n1.setProperty("jcr:mimeType", "application/octet-stream");
    // assign mix:referenceable to arbitrary node
    Node n2 = testRootNode.addNode("n2");
    n2.addMixin("mix:mimeType");
    // make node referenceable using a mixin that extends from mix:mimeType
    Node n3 = testRootNode.addNode("n3");
    n3.addMixin("test:mimeType");
    testRootNode.save();
    String query = testPath + "//element(*, mix:mimeType)";
    executeXPathQuery(query, new Node[] { n1, n2, n3 });
}

20. VersionStoreQueryTest#testCheckin()

View license
/**
     * Tests if after each checkin an additional node is returned in a result
     * of a query.
     */
public void testCheckin() throws RepositoryException {
    // current time
    Calendar c = Calendar.getInstance();
    Node n1 = testRootNode.addNode(nodeName1);
    n1.setProperty(propertyName1, c);
    n1.addMixin(mixVersionable);
    testRootNode.save();
    String statement = "//*[@" + propertyName1 + "=xs:dateTime('" + n1.getProperty(propertyName1).getString() + "')]";
    Node v1 = n1.checkin().getNode(jcrFrozenNode);
    executeXPathQuery(statement, new Node[] { n1, v1 });
    n1.checkout();
    Node v2 = n1.checkin().getNode(jcrFrozenNode);
    executeXPathQuery(statement, new Node[] { n1, v1, v2 });
    n1.checkout();
    Node v3 = n1.checkin().getNode(jcrFrozenNode);
    executeXPathQuery(statement, new Node[] { n1, v1, v2, v3 });
}

21. OnParentVersionCopyTest#testRestoreNode()

View license
/**
     * Test the restore of a OnParentVersion-COPY node
     *
     * @throws javax.jcr.RepositoryException
     */
@SuppressWarnings("deprecation")
public void testRestoreNode() throws RepositoryException {
    // prepare for node test
    Node childNode = addChildNode(OPVAction);
    Node nodeParent = childNode.getParent();
    // todo: added next line. correct? -> angela
    nodeParent.save();
    nodeParent.checkout();
    Version v = nodeParent.checkin();
    initialNodePath = childNode.getPath();
    nodeParent.checkout();
    childNode.remove();
    nodeParent.save();
    nodeParent.restore(v, false);
    if (!superuser.itemExists(initialNodePath)) {
        fail("On restore of a OnParentVersion-COPY child node, the node needs to be restored, replacing the current node in the workspace.");
    }
// todo: add proper comparison of restored node. equals does not work
// assertEquals("On restore of a OnParentVersion-COPY child node, the node needs to be restored, replacing the current node in the workspace.", childNode, superuser.getItem(initialNodePath));
}

22. ReferencesTest#testRemoveReferenced2()

Project: jackrabbit-oak
Source File: ReferencesTest.java
View license
public void testRemoveReferenced2() throws RepositoryException {
    Node ref = testRootNode.addNode(nodeName1, testNodeType);
    ref.addMixin(mixReferenceable);
    superuser.save();
    Node n1 = testRootNode.addNode(nodeName2, testNodeType);
    n1.setProperty("ref", ref);
    assertEquals(PropertyType.REFERENCE, n1.getProperty("ref").getType());
    Node n2 = testRootNode.addNode(nodeName3, testNodeType);
    n2.setProperty("ref", ref);
    assertEquals(PropertyType.REFERENCE, n2.getProperty("ref").getType());
    superuser.save();
    ref.remove();
    n1.remove();
    try {
        superuser.save();
        fail("must fail with ReferentialIntegrityException");
    } catch (ReferentialIntegrityException e) {
    }
}

23. ReferencesTest#testRemoveReferenced3()

Project: jackrabbit-oak
Source File: ReferencesTest.java
View license
public void testRemoveReferenced3() throws RepositoryException {
    Node ref = testRootNode.addNode(nodeName1, testNodeType);
    ref.addMixin(mixReferenceable);
    superuser.save();
    Node n1 = testRootNode.addNode(nodeName2, testNodeType);
    n1.setProperty("ref", ref);
    assertEquals(PropertyType.REFERENCE, n1.getProperty("ref").getType());
    superuser.save();
    Node n2 = testRootNode.addNode(nodeName3, testNodeType);
    n2.setProperty("ref", ref);
    assertEquals(PropertyType.REFERENCE, n2.getProperty("ref").getType());
    ref.remove();
    n1.remove();
    try {
        superuser.save();
        fail("must fail with ReferentialIntegrityException");
    } catch (ReferentialIntegrityException e) {
    }
}

24. RestoreTest#testRestoreReferenceableChild()

Project: jackrabbit-oak
Source File: RestoreTest.java
View license
public void testRestoreReferenceableChild() throws RepositoryException {
    VersionManager vMgr = superuser.getWorkspace().getVersionManager();
    Node n = testRootNode.addNode(nodeName1, "test:versionable");
    n.addMixin(mixVersionable);
    n.setProperty("prop", "a");
    Node child = n.addNode("test:copyOnParentVersion", ntUnstructured);
    child.addMixin(mixReferenceable);
    child.setProperty("prop", "a");
    superuser.save();
    String path = n.getPath();
    // 1.0
    Version v = vMgr.checkpoint(path);
    n.setProperty("prop", "b");
    child.setProperty("prop", "b");
    superuser.save();
    // 1.1
    vMgr.checkpoint(path);
    vMgr.restore(v, true);
    assertEquals("Property not restored", "a", n.getProperty("prop").getString());
    assertEquals("Property not restored", "a", child.getProperty("prop").getString());
    assertFalse("Restored node must not have jcr:frozenPrimaryType property", child.hasProperty(JcrConstants.JCR_FROZENPRIMARYTYPE));
}

25. ResultSizeTest#testResultSizeLuceneV1()

Project: jackrabbit-oak
Source File: ResultSizeTest.java
View license
public void testResultSizeLuceneV1() throws Exception {
    Session session = superuser;
    Node index = session.getRootNode().getNode("oak:index");
    Node luceneGlobal = index.getNode("luceneGlobal");
    luceneGlobal.setProperty("type", "disabled");
    Node luceneV1 = index.addNode("luceneV1", "oak:QueryIndexDefinition");
    luceneV1.setProperty("type", "lucene");
    luceneV1.setProperty(LuceneIndexConstants.COMPAT_MODE, IndexFormatVersion.V1.getVersion());
    session.save();
    doTestResultSize(true);
    luceneV1.remove();
    luceneGlobal.setProperty("type", "lucene");
    session.save();
}

26. SpellcheckTest#testSpellcheckMultipleWords()

Project: jackrabbit-oak
Source File: SpellcheckTest.java
View license
public void testSpellcheckMultipleWords() throws Exception {
    Session session = superuser;
    QueryManager qm = session.getWorkspace().getQueryManager();
    Node n1 = testRootNode.addNode("node1");
    n1.setProperty("jcr:title", "it is always a good idea to go visiting ontario");
    Node n2 = testRootNode.addNode("node2");
    n2.setProperty("jcr:title", "ontario is a nice place to live in");
    Node n3 = testRootNode.addNode("node3");
    n2.setProperty("jcr:title", "I flied to ontario for voting for the major polls");
    Node n4 = testRootNode.addNode("node4");
    n2.setProperty("jcr:title", "I will go voting in ontario, I always voted since I've been allowed to");
    session.save();
    String xpath = "/jcr:root[rep:spellcheck('votin in ontari')]/(rep:spellcheck())";
    Query q = qm.createQuery(xpath, Query.XPATH);
    List<String> result = getResult(q.execute(), "rep:spellcheck()");
    assertNotNull(result);
    assertEquals("[voting in ontario]", result.toString());
}

27. SpellcheckTest#testSpellcheckMultipleWords()

Project: jackrabbit-oak
Source File: SpellcheckTest.java
View license
public void testSpellcheckMultipleWords() throws Exception {
    Session session = superuser;
    QueryManager qm = session.getWorkspace().getQueryManager();
    Node n1 = testRootNode.addNode("node1");
    n1.setProperty("jcr:title", "it is always a good idea to go visiting ontario");
    Node n2 = testRootNode.addNode("node2");
    n2.setProperty("jcr:title", "ontario is a nice place to live in");
    Node n3 = testRootNode.addNode("node3");
    n2.setProperty("jcr:title", "I flied to ontario for voting for the major polls");
    Node n4 = testRootNode.addNode("node4");
    n2.setProperty("jcr:title", "I will go voting in ontario, I always voted since I've been allowed to");
    session.save();
    String xpath = "/jcr:root[rep:spellcheck('votin in ontari')]/(rep:spellcheck())";
    Query q = qm.createQuery(xpath, Query.XPATH);
    List<String> result = getResult(q.execute(), "rep:spellcheck()");
    assertNotNull(result);
    assertEquals(1, result.size());
    assertEquals("voting in ontario", result.get(0));
}

28. CndSequencer#processChildNodeDefinition()

Project: modeshape
Source File: CndSequencer.java
View license
private void processChildNodeDefinition(Node nodeTypeNode, NodeDefinition childNodeDefinition) throws RepositoryException {
    Node childNode = nodeTypeNode.addNode(CHILD_NODE_DEFINITION, CHILD_NODE_DEFINITION);
    if (!RESIDUAL_ITEM_NAME.equals(childNodeDefinition.getName())) {
        childNode.setProperty(NAME, childNodeDefinition.getName());
    }
    childNode.setProperty(AUTO_CREATED, childNodeDefinition.isAutoCreated());
    childNode.setProperty(MANDATORY, childNodeDefinition.isMandatory());
    childNode.setProperty(ON_PARENT_VERSION, OnParentVersionAction.nameFromValue(childNodeDefinition.getOnParentVersion()));
    childNode.setProperty(PROTECTED, childNodeDefinition.isProtected());
    String[] requiredPrimaryTypeNames = childNodeDefinition.getRequiredPrimaryTypeNames();
    childNode.setProperty(REQUIRED_PRIMARY_TYPES, requiredPrimaryTypeNames != null ? requiredPrimaryTypeNames : new String[0]);
    childNode.setProperty(SAME_NAME_SIBLINGS, childNodeDefinition.allowsSameNameSiblings());
    childNode.setProperty(DEFAULT_PRIMARY_TYPE, childNodeDefinition.getDefaultPrimaryTypeName());
}

29. MockConnectorTest#shouldMoveExternalNode()

Project: modeshape
Source File: MockConnectorTest.java
View license
@Test
public void shouldMoveExternalNode() throws Exception {
    federationManager.createProjection("/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "federated1");
    Node doc1Federated = session.getNode("/testRoot/federated1");
    Node parent1 = doc1Federated.addNode("parent1", null);
    parent1.addNode("child1");
    parent1.addNode("childX");
    parent1.addNode("child2");
    Node parent2 = doc1Federated.addNode("parent2", null);
    parent2.addNode("child3");
    parent2.addNode("child4");
    session.save();
    assertExternalNodeHasChildren("/testRoot/federated1/parent1", "child1", "childX", "child2");
    assertExternalNodeHasChildren("/testRoot/federated1/parent2", "child3", "child4");
    ((Workspace) session.getWorkspace()).move("/testRoot/federated1/parent1/childX", "/testRoot/federated1/parent2/childX");
    assertExternalNodeHasChildren("/testRoot/federated1/parent1", "child1", "child2");
    assertExternalNodeHasChildren("/testRoot/federated1/parent2", "child3", "child4", "childX");
}

30. QueryTest#shouldExecuteThreeWayJoinToResolveRelationships()

Project: modeshape
Source File: QueryTest.java
View license
@Test
public void shouldExecuteThreeWayJoinToResolveRelationships() throws Exception {
    // Register some namespaces ...
    NamespaceRegistry namespaceRegistry = session.getWorkspace().getNamespaceRegistry();
    namespaceRegistry.registerNamespace("sramp", "http://s-ramp.org/xmlns/2010/s-ramp");
    // and node types ...
    registerNodeTypes("cnd/sramp-notional.cnd");
    // Add some artifact nodes.
    session = repository.login();
    Node rootNode = session.getRootNode();
    String jcrNodeType = "sramp:artifact";
    // Node - Artifact A
    Node artifactA = rootNode.addNode("artifact-a", jcrNodeType);
    artifactA.setProperty("sramp:uuid", "1");
    artifactA.setProperty("sramp:name", "A");
    artifactA.setProperty("sramp:model", "core");
    artifactA.setProperty("sramp:type", "Document");
    // Node - Artifact B
    Node artifactB = rootNode.addNode("artifact-b", jcrNodeType);
    artifactB.setProperty("sramp:uuid", "2");
    artifactB.setProperty("sramp:name", "B");
    artifactB.setProperty("sramp:model", "core");
    artifactB.setProperty("sramp:type", "Document");
    // Node - Artifact C
    Node artifactC = rootNode.addNode("artifact-c", jcrNodeType);
    artifactC.setProperty("sramp:uuid", "3");
    artifactC.setProperty("sramp:name", "C");
    artifactC.setProperty("sramp:model", "core");
    artifactC.setProperty("sramp:type", "Document");
    session.save();
    // ////////////////////////////////////////////////////////////////////
    // Add the relationship nodes. Here's what
    // I'm going for here:
    // A has relationships to both B and C of type 'relatesTo'
    // A has a relationship to C of type 'isDocumentedBy'
    // B has a single relationship to C of type 'covets'
    // C has no relationships
    // ////////////////////////////////////////////////////////////////////
    Node relA_relatesTo = artifactA.addNode("relatesTo", "sramp:relationship");
    relA_relatesTo.setProperty("sramp:type", "relatesTo");
    Value[] targets = new Value[2];
    targets[0] = session.getValueFactory().createValue(artifactB, false);
    targets[1] = session.getValueFactory().createValue(artifactC, false);
    relA_relatesTo.setProperty("sramp:target", targets);
    Node relA_isDocumentedBy = artifactA.addNode("isDocumentedBy", "sramp:relationship");
    relA_isDocumentedBy.setProperty("sramp:type", "isDocumentedBy");
    relA_isDocumentedBy.setProperty("sramp:target", session.getValueFactory().createValue(artifactC, false));
    Node relB_covets = artifactB.addNode("relationship-b-1", "sramp:relationship");
    relB_covets.setProperty("sramp:type", "covets");
    relB_covets.setProperty("sramp:target", session.getValueFactory().createValue(artifactC, false));
    session.save();
    // print = true;
    tools.setDebug(print);
    if (print) {
        tools.printSubgraph(artifactA);
        tools.printSubgraph(artifactB);
        tools.printSubgraph(artifactC);
    }
    session.logout();
    String query = null;
    QueryResult jcrQueryResult = null;
    NodeIterator jcrNodes = null;
    Set<String> jcr_uuids = new HashSet<String>();
    // Now it's time to do some querying.
    session = repository.login();
    // Show that we have the 'relatesTo' relationship set up for Artifact A (with two targets)
    query = "SELECT relationship.[sramp:target] AS target_jcr_uuid, relationship.[sramp:type] " + " FROM [sramp:artifact] AS artifact" + " JOIN [sramp:relationship] AS relationship ON ISCHILDNODE(relationship, artifact)" + " WHERE artifact.[sramp:name] = 'A' AND relationship.[sramp:type] = 'relatesTo'";
    jcrQueryResult = assertJcrSql2Query(query, 1);
    jcrNodes = jcrQueryResult.getNodes();
    Node n = jcrNodes.nextNode();
    String setCriteria = "";
    for (Value value : n.getProperty("sramp:target").getValues()) {
        printMessage("  Found JCR UUID: " + value.getString());
        if (!jcr_uuids.isEmpty())
            setCriteria = setCriteria + ", ";
        jcr_uuids.add(value.getString());
        setCriteria = setCriteria + "'" + value.getString() + "'";
    }
    // Now show that the UUIDs found above match the jcr:uuid for Artifact B and Artifact C
    query = "SELECT artifact.[jcr:uuid] FROM [sramp:artifact] AS artifact" + " WHERE artifact.[sramp:name] = 'B' OR artifact.[sramp:name] = 'C'";
    jcrQueryResult = assertJcrSql2Query(query, 2);
    jcrNodes = jcrQueryResult.getNodes();
    Node n1 = jcrNodes.nextNode();
    Node n2 = jcrNodes.nextNode();
    Assert.assertTrue("Expected to find the JCR UUID in jcr_uuids", jcr_uuids.contains(n1.getProperty("jcr:uuid").getString()));
    Assert.assertTrue("Expected to find the JCR UUID in jcr_uuids", jcr_uuids.contains(n2.getProperty("jcr:uuid").getString()));
    printMessage("Confirmed: the [jcr:uuid] for both Artifact B and Artifact C were found!");
    // OK - so far so good. Now put it all together in a single query! Here
    // we are trying to select Artifact B and Artifact C by selecting all Artifacts
    // that Artifatc A has a 'relatesTo' relationship on
    query = "SELECT artifact2.* FROM [sramp:artifact] AS artifact1" + "   JOIN [sramp:relationship] AS relationship1 ON ISCHILDNODE(relationship1, artifact1)" + "   JOIN [sramp:artifact] AS artifact2 ON artifact2.[jcr:uuid] = relationship1.[sramp:target]" + "   WHERE artifact1.[sramp:name] = 'A' AND relationship1.[sramp:type] = 'relatesTo')";
    jcrQueryResult = assertJcrSql2Query(query, 2);
    jcrNodes = jcrQueryResult.getNodes();
    Assert.assertEquals("Expected two (2) nodes (Artifact B and Artifact C) to come back!", 2, jcrNodes.getSize());
}

31. CopyValueTest#doTestCopy()

Project: jackrabbit
Source File: CopyValueTest.java
View license
private void doTestCopy(int length) throws Exception {
    Node root = superuser.getRootNode();
    if (root.hasNode("testCopy")) {
        root.getNode("testCopy").remove();
        superuser.save();
    }
    Node testRoot = root.addNode("testCopy");
    Node n = testRoot.addNode("a");
    superuser.save();
    byte[] data = new byte[length + 1];
    ValueFactory vf = superuser.getValueFactory();
    n.setProperty("data", vf.createBinary(new ByteArrayInputStream(data)));
    superuser.save();
    data = new byte[length];
    n.setProperty("data", vf.createBinary(new ByteArrayInputStream(data)));
    Property p = testRoot.getNode("a").getProperty("data");
    assertEquals(length, p.getLength());
    superuser.getWorkspace().copy("/testCopy/a", "/testCopy/b");
    assertEquals(length, p.getLength());
    p = testRoot.getNode("b").getProperty("data");
    assertEquals(length + 1, p.getLength());
    testRoot.remove();
    superuser.save();
}

32. MixinTest#testMultipleMixinOnNode()

Project: jackrabbit
Source File: MixinTest.java
View license
/**
     * Tests event filtering on nodes with multiple mixins applied.
     */
public void testMultipleMixinOnNode() throws RepositoryException {
    Node node1 = testRootNode.addNode(nodeName1, testNodeType);
    node1.addMixin(mixReferenceable);
    node1.addMixin(mixLockable);
    Node node2 = testRootNode.addNode(nodeName2, testNodeType);
    Node node3 = testRootNode.addNode(nodeName3, testNodeType);
    node3.addMixin(mixLockable);
    node3.addMixin(mixReferenceable);
    testRootNode.save();
    EventResult propertyAddedListener = new EventResult(log);
    addEventListener(propertyAddedListener, new String[] { mixReferenceable }, Event.PROPERTY_ADDED);
    try {
        node1.setProperty(propertyName1, "test");
        node2.setProperty(propertyName1, "test");
        node3.setProperty(propertyName1, "test");
        testRootNode.save();
        Event[] added = propertyAddedListener.getEvents(DEFAULT_WAIT_TIMEOUT);
        checkPropertyAdded(added, new String[] { nodeName1 + "/" + propertyName1, nodeName3 + "/" + propertyName1 });
    } finally {
        removeEventListener(propertyAddedListener);
    }
}

33. AbstractQueryLevel2Test#setUpMultiValueTest()

View license
/**
     * Creates three nodes with names: {@link #nodeName1}, {@link #nodeName2}
     * and {@link #nodeName3}. All nodes are of node type {@link #testNodeType}.
     * the node type must allow a String property with name {@link
     * #propertyName1} and a multi valued String property with name {@link
     * #propertyName2}.
     * <p>
     * If the node type does not support multi values for {@link #propertyName2}
     * a {@link org.apache.jackrabbit.test.NotExecutableException} is thrown.
     */
protected void setUpMultiValueTest() throws RepositoryException, NotExecutableException {
    // check if NodeType supports mvp
    NodeType nt = superuser.getWorkspace().getNodeTypeManager().getNodeType(testNodeType);
    Value[] testValue = new Value[] { superuser.getValueFactory().createValue("one"), superuser.getValueFactory().createValue("two"), superuser.getValueFactory().createValue("three") };
    if (!nt.canSetProperty(propertyName2, testValue)) {
        throw new NotExecutableException("Property " + propertyName2 + " of NodeType " + testNodeType + " does not allow multi values");
    }
    Node node = testRootNode.addNode(nodeName1, testNodeType);
    node.setProperty(propertyName1, "existence");
    node.setProperty(propertyName2, testValue);
    node = testRootNode.addNode(nodeName2, testNodeType);
    node.setProperty(propertyName1, "nonexistence");
    node.setProperty(propertyName2, new String[] { "one", "three" });
    Node cNode = node.addNode(nodeName3, testNodeType);
    cNode.setProperty(propertyName1, "existence");
    testRootNode.getSession().save();
}

34. JcrPackageImpl#createNew()

View license
/**
     * Creates a new jcr vault package.
     *
     * @param parent the parent node
     * @param pid the package id of the new package.
     * @param bin the binary containing the zip
     * @param archive the archive with the meta data
     * @return the created jcr vault package.
     * @throws RepositoryException if an repository error occurs
     * @throws IOException if an I/O error occurs
     *
     * @since 3.1
     */
public static JcrPackage createNew(Node parent, PackageId pid, Binary bin, MemoryArchive archive) throws RepositoryException, IOException {
    Node node = parent.addNode(Text.getName(pid.getInstallationPath() + ".zip"), JcrConstants.NT_FILE);
    Node content = node.addNode(JcrConstants.JCR_CONTENT, JcrConstants.NT_RESOURCE);
    content.addMixin(NT_VLT_PACKAGE);
    Node defNode = content.addNode(NN_VLT_DEFINITION);
    JcrPackageDefinitionImpl def = new JcrPackageDefinitionImpl(defNode);
    def.set(JcrPackageDefinition.PN_NAME, pid.getName(), false);
    def.set(JcrPackageDefinition.PN_GROUP, pid.getGroup(), false);
    def.set(JcrPackageDefinition.PN_VERSION, pid.getVersionString(), false);
    def.touch(null, false);
    content.setProperty(JcrConstants.JCR_LASTMODIFIED, Calendar.getInstance());
    content.setProperty(JcrConstants.JCR_MIMETYPE, MIME_TYPE);
    content.setProperty(JcrConstants.JCR_DATA, bin);
    def.unwrap(archive, false);
    return new JcrPackageImpl(node);
}

35. NodeTypeTest#illegalAddNodeWithProps()

Project: jackrabbit-oak
Source File: NodeTypeTest.java
View license
@Test(expected = ConstraintViolationException.class)
public void illegalAddNodeWithProps() throws Exception {
    Session session = getAdminSession();
    Node root = session.getRootNode();
    ValueFactory vf = session.getValueFactory();
    Node n = root.addNode("q1", "nt:query");
    n.setProperty("jcr:statement", vf.createValue("statement"));
    n.setProperty("jcr:language", vf.createValue("language"));
    Node n2 = n.addNode("q2", "nt:query");
    n2.setProperty("jcr:statement", vf.createValue("statement"));
    n2.setProperty("jcr:language", vf.createValue("language"));
    session.save();
}

36. ReferencesTest#testMultipleMultiReferences()

Project: jackrabbit-oak
Source File: ReferencesTest.java
View license
public void testMultipleMultiReferences() throws RepositoryException {
    Node ref = testRootNode.addNode(nodeName2, testNodeType);
    ref.addMixin(mixReferenceable);
    superuser.save();
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    Value weak = superuser.getValueFactory().createValue(ref, true);
    n.setProperty("ref1", new Value[] { weak, weak });
    n.setProperty("ref2", new Value[] { weak, weak });
    Value hard = superuser.getValueFactory().createValue(ref, false);
    n.setProperty("ref3", new Value[] { hard, hard });
    n.setProperty("ref4", new Value[] { hard, hard });
    superuser.save();
    checkReferences("refs", ref.getWeakReferences(), n.getPath() + "/ref1", n.getPath() + "/ref2");
    checkReferences("refs", ref.getReferences(), n.getPath() + "/ref3", n.getPath() + "/ref4");
}

37. ReferencesTest#testMixedReferencesOnSameNode3()

Project: jackrabbit-oak
Source File: ReferencesTest.java
View license
public void testMixedReferencesOnSameNode3() throws RepositoryException {
    Node ref = testRootNode.addNode(nodeName2, testNodeType);
    ref.addMixin(mixReferenceable);
    superuser.save();
    Node n0 = testRootNode.addNode(nodeName1, testNodeType);
    n0.setProperty("strong_reference", ref);
    n0.setProperty("mv_strong_reference", new Value[] { superuser.getValueFactory().createValue(ref, false) });
    n0.setProperty("weak_reference", superuser.getValueFactory().createValue(ref, true));
    n0.setProperty("mv_weak_reference", new Value[] { superuser.getValueFactory().createValue(ref, true) });
    superuser.save();
    checkReferences("refs", ref.getReferences(), n0.getPath() + "/strong_reference", n0.getPath() + "/mv_strong_reference");
    checkReferences("refs", ref.getWeakReferences(), n0.getPath() + "/weak_reference", n0.getPath() + "/mv_weak_reference");
}

38. RepositoryTest#setup()

Project: jackrabbit-oak
Source File: RepositoryTest.java
View license
@Before
public void setup() throws RepositoryException {
    Session session = getAdminSession();
    ValueFactory valueFactory = session.getValueFactory();
    Node root = session.getRootNode();
    Node foo = root.addNode("foo");
    foo.setProperty("stringProp", "stringVal");
    foo.setProperty("intProp", 42);
    foo.setProperty("mvProp", new Value[] { valueFactory.createValue(1), valueFactory.createValue(2), valueFactory.createValue(3) });
    root.addNode("bar");
    root.addNode(TEST_NODE);
    session.save();
}

39. ImportMvPropertyTest#setUp()

View license
@Override
protected void setUp() throws Exception {
    super.setUp();
    vf = superuser.getValueFactory();
    Node node = testRootNode.addNode(nodeName4);
    path = node.getPath();
    Node n1 = node.addNode(nodeName1, "test:setProperty");
    n1.setProperty("test:multiProperty", "v1");
    Node n2 = node.addNode(nodeName2, "test:setProperty");
    n2.setProperty("test:multiProperty", new String[] { "v1", "v2" });
    Node n3 = node.addNode(nodeName3, "test:setProperty");
    n3.setProperty("test:multiProperty", new String[] {});
    targetPath = testRootNode.addNode("target").getPath();
    superuser.save();
}

40. OakIndexUtils#propertyIndexDefinition()

Project: jackrabbit-oak
Source File: OakIndexUtils.java
View license
/**
     * Helper method to create or update a property index definition.
     *
     * @param session the session
     * @param indexDefinitionName the name of the node for the index definition
     * @param propertyNames the list of properties to index
     * @param unique if unique or not
     * @param enclosingNodeTypes the enclosing node types
     * @return the node just created
     * @throws RepositoryException the repository exception
     */
public static Node propertyIndexDefinition(Session session, String indexDefinitionName, String[] propertyNames, boolean unique, String[] enclosingNodeTypes) throws RepositoryException {
    Node root = session.getRootNode();
    Node indexDefRoot = JcrUtils.getOrAddNode(root, IndexConstants.INDEX_DEFINITIONS_NAME, NodeTypeConstants.NT_UNSTRUCTURED);
    Node indexDef = JcrUtils.getOrAddNode(indexDefRoot, indexDefinitionName, IndexConstants.INDEX_DEFINITIONS_NODE_TYPE);
    indexDef.setProperty(IndexConstants.TYPE_PROPERTY_NAME, PropertyIndexEditorProvider.TYPE);
    indexDef.setProperty(IndexConstants.REINDEX_PROPERTY_NAME, true);
    indexDef.setProperty(IndexConstants.PROPERTY_NAMES, propertyNames, PropertyType.NAME);
    indexDef.setProperty(IndexConstants.UNIQUE_PROPERTY_NAME, unique);
    if (enclosingNodeTypes != null && enclosingNodeTypes.length != 0) {
        indexDef.setProperty(IndexConstants.DECLARING_NODE_TYPES, enclosingNodeTypes, PropertyType.NAME);
    }
    session.save();
    return indexDef;
}

41. EsIndexIntegrationTest#shouldQueryUsingElasticsearchIndex()

View license
@Test
public void shouldQueryUsingElasticsearchIndex() throws Exception {
    Node testRoot = session.getRootNode().addNode("root");
    Node node1 = testRoot.addNode("node5");
    node1.addMixin("mix:mimeType");
    node1.setProperty("jcr:mimeType", "5");
    Node node2 = testRoot.addNode("node6");
    node2.addMixin("mix:mimeType");
    node2.setProperty("jcr:mimeType", "6");
    session.save();
    try {
        String sql = "select [jcr:path] from [mix:mimeType] where [jcr:mimeType] = '5'";
        Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
        validateQuery().rowCount(1).useIndex("mime-types").validate(query, query.execute());
    } finally {
        testRoot.remove();
        session.save();
    }
}

42. CndSequencer#processNodeTypeDefinition()

Project: modeshape
Source File: CndSequencer.java
View license
private Node processNodeTypeDefinition(Node outputNode, NodeTypeDefinition nodeTypeDefinition) throws RepositoryException {
    Node nodeTypeNode = outputNode.addNode(nodeTypeDefinition.getName(), NODE_TYPE);
    nodeTypeNode.setProperty(IS_MIXIN, nodeTypeDefinition.isMixin());
    nodeTypeNode.setProperty(IS_ABSTRACT, nodeTypeDefinition.isAbstract());
    nodeTypeNode.setProperty(IS_QUERYABLE, nodeTypeDefinition.isQueryable());
    nodeTypeNode.setProperty(NODE_TYPE_NAME, nodeTypeDefinition.getName());
    nodeTypeNode.setProperty(HAS_ORDERABLE_CHILD_NODES, nodeTypeDefinition.hasOrderableChildNodes());
    String[] declaredSupertypeNames = nodeTypeDefinition.getDeclaredSupertypeNames();
    nodeTypeNode.setProperty(SUPERTYPES, declaredSupertypeNames != null ? declaredSupertypeNames : new String[0]);
    if (nodeTypeDefinition.getPrimaryItemName() != null) {
        nodeTypeNode.setProperty(PRIMARY_ITEM_NAME, nodeTypeDefinition.getPrimaryItemName());
    }
    return nodeTypeNode;
}

43. FileSystemConnectorTest#shouldAllowUpdatingNodesInWritableJsonBasedProjection()

View license
@Test
public void shouldAllowUpdatingNodesInWritableJsonBasedProjection() throws Exception {
    Node file = session.getNode("/testRoot/json/dir3/simple.json");
    file.addMixin("flex:anyProperties");
    file.setProperty("extraProp", "extraValue");
    Node content = file.getNode("jcr:content");
    content.addMixin("flex:anyProperties");
    content.setProperty("extraProp2", "extraValue2");
    session.save();
    assertThat(file.getProperty("extraProp").getString(), is("extraValue"));
    assertThat(file.getProperty("jcr:content/extraProp2").getString(), is("extraValue2"));
    assertJsonSidecarFile(jsonProjection, "dir3/simple.json");
    assertJsonSidecarFile(jsonProjection, "dir3/simple.json");
    Node file2 = session.getNode("/testRoot/json/dir3/simple.json");
    assertThat(file2.getProperty("extraProp").getString(), is("extraValue"));
    try {
        // Make sure the sidecar file can't be seen via JCR ...
        session.getNode("/testRoot/json/dir3/simple.json.modeshape.json");
        fail("found sidecar file as JCR node");
    } catch (PathNotFoundException e) {
    }
}

44. MockConnectorTest#shouldUpdateExternalNodeProperties()

Project: modeshape
Source File: MockConnectorTest.java
View license
@Test
public void shouldUpdateExternalNodeProperties() throws Exception {
    federationManager.createProjection("/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "federated1");
    Node doc1Federated = session.getNode("/testRoot/federated1");
    Node externalNode1 = doc1Federated.addNode("federated1_1", null);
    externalNode1.setProperty("prop1", "a value");
    externalNode1.setProperty("prop2", "a value 2");
    session.save();
    externalNode1.setProperty("prop1", "edited value");
    assertEquals("a value 2", externalNode1.getProperty("prop2").getString());
    externalNode1.getProperty("prop2").remove();
    externalNode1.setProperty("prop3", "a value 3");
    session.save();
    Node federated1_1 = doc1Federated.getNode("federated1_1");
    assertEquals("edited value", federated1_1.getProperty("prop1").getString());
    assertEquals("a value 3", federated1_1.getProperty("prop3").getString());
    try {
        federated1_1.getProperty("prop2");
        fail("Property was not removed from external node");
    } catch (PathNotFoundException e) {
    }
}

45. ImportExportTest#shouldImportExportEscapedXmlCharactersInSystemViewUsingSession()

Project: modeshape
Source File: ImportExportTest.java
View license
@Test
public void shouldImportExportEscapedXmlCharactersInSystemViewUsingSession() throws Exception {
    String testName = "importExportEscapedXmlCharacters";
    Node rootNode = session.getRootNode();
    Node sourceNode = rootNode.addNode(testName + "Source", "nt:unstructured");
    Node targetNode = rootNode.addNode(testName + "Target", "nt:unstructured");
    // Test data
    sourceNode.setProperty("badcharacters", BAD_CHARACTER_STRING);
    assertThat(sourceNode.getProperty("badcharacters").getString(), is(BAD_CHARACTER_STRING));
    sourceNode.addNode(BAD_CHARACTER_STRING);
    testImportExport(sourceNode.getPath(), targetNode.getPath(), ExportType.SYSTEM, false, false, false);
    Node newSourceNode = targetNode.getNode(testName + "Source");
    newSourceNode.getNode(BAD_CHARACTER_STRING);
    assertThat(newSourceNode.getProperty("badcharacters").getString(), is(BAD_CHARACTER_STRING));
}

46. ImportExportTest#shouldImportExportEscapedXmlCharactersInSystemViewUsingWorkspace()

Project: modeshape
Source File: ImportExportTest.java
View license
@Test
public void shouldImportExportEscapedXmlCharactersInSystemViewUsingWorkspace() throws Exception {
    String testName = "importExportEscapedXmlCharacters";
    Node rootNode = session.getRootNode();
    Node sourceNode = rootNode.addNode(testName + "Source", "nt:unstructured");
    Node targetNode = rootNode.addNode(testName + "Target", "nt:unstructured");
    // Test data
    sourceNode.setProperty("badcharacters", BAD_CHARACTER_STRING);
    assertThat(sourceNode.getProperty("badcharacters").getString(), is(BAD_CHARACTER_STRING));
    sourceNode.addNode(BAD_CHARACTER_STRING);
    session.save();
    testImportExport(sourceNode.getPath(), targetNode.getPath(), ExportType.SYSTEM, false, false, true);
    Node newSourceNode = targetNode.getNode(testName + "Source");
    newSourceNode.getNode(BAD_CHARACTER_STRING);
    assertThat(newSourceNode.getProperty("badcharacters").getString(), is(BAD_CHARACTER_STRING));
}

47. ImportExportTest#shouldImportProtectedContentUsingWorkpace()

Project: modeshape
Source File: ImportExportTest.java
View license
@FixFor("MODE-1405")
@Test
public void shouldImportProtectedContentUsingWorkpace() throws Exception {
    String testName = "importExportEscapedXmlCharacters";
    Node rootNode = session.getRootNode();
    Node sourceNode = rootNode.addNode(testName + "Source", "nt:unstructured");
    Node targetNode = rootNode.addNode(testName + "Target", "nt:unstructured");
    // Test data
    Node child = sourceNode.addNode("child");
    child.addMixin("mix:created");
    session.save();
    // Verify there are 'jcr:createdBy' and 'jcr:created' properties ...
    assertThat(child.getProperty("jcr:createdBy").getString(), is(notNullValue()));
    assertThat(child.getProperty("jcr:created").getString(), is(notNullValue()));
    testImportExport(sourceNode.getPath(), targetNode.getPath(), ExportType.SYSTEM, false, false, true);
    Node newSourceNode = targetNode.getNode(testName + "Source");
    Node newChild = newSourceNode.getNode("child");
    // Verify there are 'jcr:createdBy' and 'jcr:created' properties ...
    assertThat(newChild.getProperty("jcr:createdBy").getString(), is(notNullValue()));
    assertThat(newChild.getProperty("jcr:created").getString(), is(notNullValue()));
}

48. ImportExportTest#shouldImportExportEscapedXmlCharactersInDocumentViewUsingSession()

Project: modeshape
Source File: ImportExportTest.java
View license
@Test
public void shouldImportExportEscapedXmlCharactersInDocumentViewUsingSession() throws Exception {
    String testName = "importExportEscapedXmlCharacters";
    Node rootNode = session.getRootNode();
    Node sourceNode = rootNode.addNode(testName + "Source", "nt:unstructured");
    Node targetNode = rootNode.addNode(testName + "Target", "nt:unstructured");
    // Test data
    sourceNode.setProperty("badcharacters", BAD_CHARACTER_STRING);
    assertThat(sourceNode.getProperty("badcharacters").getString(), is(BAD_CHARACTER_STRING));
    sourceNode.addNode(BAD_CHARACTER_STRING);
    testImportExport(sourceNode.getPath(), targetNode.getPath(), ExportType.DOCUMENT, false, false, false);
    Node newSourceNode = targetNode.getNode(testName + "Source");
    newSourceNode.getNode(BAD_CHARACTER_STRING);
    assertThat(newSourceNode.getProperty("badcharacters").getString(), is(BAD_CHARACTER_STRING));
}

49. JcrNodeTest#shouldNotCauseReferentialIntegrityExceptionWhenSameReferrerUpdatedMultipleTimes()

Project: modeshape
Source File: JcrNodeTest.java
View license
@Test
@FixFor("MODE-1751")
public void shouldNotCauseReferentialIntegrityExceptionWhenSameReferrerUpdatedMultipleTimes() throws Exception {
    Node nodeA = session.getRootNode().addNode("nodeA");
    nodeA.addMixin("mix:referenceable");
    Node nodeB = session.getRootNode().addNode("nodeB");
    nodeB.setProperty("nodeA", session.getValueFactory().createValue(nodeA, false));
    session.save();
    nodeB.setProperty("nodeA", session.getValueFactory().createValue(nodeA, false));
    session.save();
    nodeB.remove();
    session.save();
    nodeA.remove();
    session.save();
}

50. JcrObservationManagerTest#shouldProvideFullEventJournal()

View license
@Test
@FixFor("MODE-2019")
public void shouldProvideFullEventJournal() throws Exception {
    // add node
    Node node1 = getRoot().addNode("node1");
    node1.setProperty("prop1", "value");
    node1.setProperty("prop2", "value2");
    Node node2 = getRoot().addNode("node2");
    session.save();
    Thread.sleep(100);
    node1.setProperty("prop2", "edited value");
    node1.setProperty("prop1", (String) null);
    node2.remove();
    session.save();
    Thread.sleep(100);
    EventJournal eventJournal = getObservationManager().getEventJournal();
    assertPathsInJournal(eventJournal, false, "/testroot/node1", "/testroot/node1/jcr:primaryType", "/testroot/node1/prop1", "/testroot/node1/prop2", "/testroot/node2/jcr:primaryType", "/testroot/node2/jcr:primaryType", "/testroot/node1/prop2", "/testroot/node1/prop1", "/testroot/node1/prop2");
}

51. JcrSessionTest#shouldCheckReferentialIntegrityOfSubgraphWhenRemovingNodes()

Project: modeshape
Source File: JcrSessionTest.java
View license
@FixFor("MODE-1685")
@Test
public void shouldCheckReferentialIntegrityOfSubgraphWhenRemovingNodes() throws Exception {
    JcrValueFactory valueFactory = session.getValueFactory();
    Node targetNode = session.getRootNode().addNode("target");
    targetNode.addMixin(JcrMixLexicon.REFERENCEABLE.toString());
    Node parentNode = session.getRootNode().addNode("parent");
    Node childNode = parentNode.addNode("child");
    childNode.setProperty("ref1", valueFactory.createValue(targetNode, false));
    session.save();
    // Delete the parent (which will delete the child and the reference to the target ...
    parentNode.remove();
    session.save();
    // Delete the target - there should be no references ...
    targetNode.remove();
    session.save();
}

52. MixinTest#shouldAllowAddingNewChildNodeAfterAddingMixin()

Project: modeshape
Source File: MixinTest.java
View license
@Test
public void shouldAllowAddingNewChildNodeAfterAddingMixin() throws Exception {
    session.getRootNode().addNode("a", PRIMARY_TYPE_A).addMixin("mix:referenceable");
    session.save();
    Node rootNode = session.getRootNode();
    Node nodeA = rootNode.getNode("a");
    assertThat(nodeA.canAddMixin(MIXIN_TYPE_B), is(true));
    nodeA.addMixin(MIXIN_TYPE_B);
    nodeA.addNode(CHILD_NODE_B);
    session.save();
    Node newRootNode = session.getRootNode();
    Node newNodeA = newRootNode.getNode("a");
    Node newNodeB = newNodeA.getNode(CHILD_NODE_B);
    assertThat(newNodeB, is(notNullValue()));
    assertThat(newNodeB.getDefinition().getDeclaringNodeType().getName(), is(MIXIN_TYPE_B));
}

53. GQLTest#testOrder()

Project: jackrabbit
Source File: GQLTest.java
View license
public void testOrder() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    n1.setProperty("p", 1);
    Node n2 = testRootNode.addNode("node2");
    n2.setProperty("p", 2);
    Node n3 = testRootNode.addNode("node3");
    n3.setProperty("p", 3);
    superuser.save();
    // default: ascending
    String stmt = createStatement("order:p");
    RowIterator rows = GQL.execute(stmt, superuser);
    checkResultSequence(rows, new Node[] { n1, n2, n3 });
    // explicit ascending
    stmt = createStatement("order:+p");
    rows = GQL.execute(stmt, superuser);
    checkResultSequence(rows, new Node[] { n1, n2, n3 });
    // explicit descending
    stmt = createStatement("order:-p");
    rows = GQL.execute(stmt, superuser);
    checkResultSequence(rows, new Node[] { n3, n2, n1 });
}

54. GQLTest#testOrderDeep()

Project: jackrabbit
Source File: GQLTest.java
View license
public void testOrderDeep() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    n1.setProperty("prop", "value");
    n1.addNode("sub").setProperty("p", 1);
    Node n2 = testRootNode.addNode("node2");
    n2.setProperty("prop", "value");
    n2.addNode("sub").setProperty("p", 2);
    Node n3 = testRootNode.addNode("node3");
    n3.setProperty("prop", "value");
    n3.addNode("sub").setProperty("p", 3);
    superuser.save();
    // default: ascending
    String stmt = createStatement("prop:value order:sub/p");
    RowIterator rows = GQL.execute(stmt, superuser);
    checkResultSequence(rows, new Node[] { n1, n2, n3 });
    // explicit ascending
    stmt = createStatement("prop:value order:+sub/p");
    rows = GQL.execute(stmt, superuser);
    checkResultSequence(rows, new Node[] { n1, n2, n3 });
    // explicit descending
    stmt = createStatement("prop:value order:-sub/p");
    rows = GQL.execute(stmt, superuser);
    checkResultSequence(rows, new Node[] { n3, n2, n1 });
}

55. GQLTest#testExcludeTerm()

Project: jackrabbit
Source File: GQLTest.java
View license
public void testExcludeTerm() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    n1.setProperty("text", "foo");
    Node n2 = testRootNode.addNode("node2");
    n2.setProperty("text", "bar");
    Node n3 = testRootNode.addNode("node3");
    n3.setProperty("text", "foo bar");
    superuser.save();
    String stmt = createStatement("foo -bar");
    RowIterator rows = GQL.execute(stmt, superuser);
    checkResult(rows, new Node[] { n1 });
}

56. GQLTest#testOptionalTerm()

Project: jackrabbit
Source File: GQLTest.java
View license
public void testOptionalTerm() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    n1.setProperty("text", "apache jackrabbit");
    Node n2 = testRootNode.addNode("node2");
    n2.setProperty("text", "apache jcr");
    Node n3 = testRootNode.addNode("node3");
    n3.setProperty("text", "jackrabbit jcr");
    superuser.save();
    String stmt = createStatement("apache jackrabbit OR jcr");
    RowIterator rows = GQL.execute(stmt, superuser);
    checkResult(rows, new Node[] { n1, n2 });
}

57. GQLTest#testPrefixedValue()

Project: jackrabbit
Source File: GQLTest.java
View license
public void testPrefixedValue() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    n1.setProperty("jcr:title", "a");
    Node n2 = testRootNode.addNode("node2");
    n2.setProperty("jcr:title", "b");
    Node n3 = testRootNode.addNode("node3");
    n3.setProperty("jcr:title", "c");
    superuser.save();
    String stmt = createStatement("order:jcr:title");
    RowIterator rows = GQL.execute(stmt, superuser);
    checkResultSequence(rows, new Node[] { n1, n2, n3 });
}

58. GQLTest#testFilter()

Project: jackrabbit
Source File: GQLTest.java
View license
public void testFilter() throws RepositoryException {
    final Node n1 = testRootNode.addNode("node1");
    n1.setProperty("jcr:title", "a");
    Node n2 = testRootNode.addNode("node2");
    n2.setProperty("jcr:title", "b");
    Node n3 = testRootNode.addNode("node3");
    n3.setProperty("jcr:title", "c");
    superuser.save();
    String stmt = createStatement("order:jcr:title");
    RowIterator rows = GQL.execute(stmt, superuser, null, new GQL.Filter() {

        public boolean include(Row row) throws RepositoryException {
            return !n1.getPath().equals(row.getValue("jcr:path").getString());
        }
    });
    checkResultSequence(rows, new Node[] { n2, n3 });
}

59. GQLTest#testFilterLimit()

Project: jackrabbit
Source File: GQLTest.java
View license
public void testFilterLimit() throws RepositoryException {
    final Node n1 = testRootNode.addNode("node1");
    n1.setProperty("jcr:title", "a");
    Node n2 = testRootNode.addNode("node2");
    n2.setProperty("jcr:title", "b");
    Node n3 = testRootNode.addNode("node3");
    n3.setProperty("jcr:title", "c");
    superuser.save();
    String stmt = createStatement("order:jcr:title limit:1");
    RowIterator rows = GQL.execute(stmt, superuser, null, new GQL.Filter() {

        public boolean include(Row row) throws RepositoryException {
            return !n1.getPath().equals(row.getValue("jcr:path").getString());
        }
    });
    checkResultSequence(rows, new Node[] { n2 });
}

60. LostFromCacheIssueTest#testIssue()

View license
public void testIssue() throws Exception {
    Node node = superuser.getRootNode().getNode(TESTNODE_PATH.substring(1));
    node.addMixin(NODETYPE_2);
    mixinTypes = node.getProperty("jcr:mixinTypes");
    superuser.save();
    node.addMixin(NODETYPE_1);
    superuser.save();
    node.removeMixin(NODETYPE_2);
    node.removeMixin(NODETYPE_1);
    superuser.save();
    node.addMixin(NODETYPE_1);
    superuser.save();
}

61. ChildAxisQueryTest#testLike()

Project: jackrabbit
Source File: ChildAxisQueryTest.java
View license
public void testLike() throws RepositoryException {
    Node n1 = testRootNode.addNode(nodeName1);
    n1.setProperty(propertyName1, "foo");
    Node n2 = testRootNode.addNode(nodeName1);
    n2.setProperty(propertyName1, "foobar");
    Node n3 = testRootNode.addNode(nodeName1);
    n3.setProperty(propertyName1, "foo bar");
    testRootNode.save();
    String base = testPath + "[jcr:like(" + nodeName1 + "/@" + propertyName1;
    executeXPathQuery(base + ", 'fo_')]", new Node[] { testRootNode });
    executeXPathQuery(base + ", 'foo_ar')]", new Node[] { testRootNode });
    executeXPathQuery(base + ", 'foo %')]", new Node[] { testRootNode });
    executeXPathQuery(base + ", 'f_oba')]", new Node[] {});
}

62. FnNameQueryTest#testSimple()

Project: jackrabbit
Source File: FnNameQueryTest.java
View license
public void testSimple() throws RepositoryException {
    Node n1 = testRootNode.addNode(nodeName1);
    n1.setProperty(propertyName1, 1);
    Node n2 = testRootNode.addNode(nodeName2);
    n2.setProperty(propertyName1, 2);
    Node n3 = testRootNode.addNode(nodeName3);
    n3.setProperty(propertyName1, 3);
    superuser.save();
    String base = testPath + "/*[@" + propertyName1;
    executeXPathQuery(base + " = 1 and fn:name() = '" + nodeName1 + "']", new Node[] { n1 });
    executeXPathQuery(base + " = 1 and fn:name() = '" + nodeName2 + "']", new Node[] {});
    executeXPathQuery(base + " > 0 and fn:name() = '" + nodeName2 + "']", new Node[] { n2 });
    executeXPathQuery(base + " > 0 and (fn:name() = '" + nodeName1 + "' or fn:name() = '" + nodeName2 + "')]", new Node[] { n1, n2 });
    executeXPathQuery(base + " > 0 and not(fn:name() = '" + nodeName1 + "')]", new Node[] { n2, n3 });
}

63. IndexingAggregateTest#addFile()

View license
private static Node addFile(Node folder, String name, long lastModified) throws RepositoryException {
    Node file = folder.addNode(name, "nt:file");
    Node resource = file.addNode("jcr:content", "nt:resource");
    Calendar cal = Calendar.getInstance();
    cal.setTimeInMillis(lastModified);
    resource.setProperty("jcr:lastModified", cal);
    resource.setProperty("jcr:encoding", "UTF-8");
    resource.setProperty("jcr:mimeType", "text/plain");
    resource.setProperty("jcr:data", new ByteArrayInputStream("test".getBytes()));
    return file;
}

64. IndexingRuleTest#testNodeScopeIndex()

Project: jackrabbit
Source File: IndexingRuleTest.java
View license
public void testNodeScopeIndex() throws RepositoryException {
    Node node1 = testRootNode.addNode(nodeName1, NT_UNSTRUCTURED);
    node1.setProperty("rule", "nsiTrue");
    node1.setProperty("text", TEXT);
    Node node2 = testRootNode.addNode(nodeName2, NT_UNSTRUCTURED);
    node2.setProperty("rule", "nsiFalse");
    node2.setProperty("text", TEXT);
    testRootNode.save();
    String stmt = "/jcr:root" + testRootNode.getPath() + "/*[jcr:contains(., 'quick')]";
    checkResult(executeQuery(stmt), new Node[] { node1 });
}

65. TextExtractionQueryTest#testNtFile()

View license
public void testNtFile() throws RepositoryException, IOException {
    Node file = testRootNode.addNode(nodeName1, "nt:file");
    Node resource = file.addNode("jcr:content", "nt:resource");
    resource.setProperty("jcr:encoding", "UTF-8");
    resource.setProperty("jcr:mimeType", "text/plain");
    ByteArrayOutputStream data = new ByteArrayOutputStream();
    OutputStreamWriter writer = new OutputStreamWriter(data, "UTF-8");
    writer.write("The quick brown fox jumps over the lazy dog.");
    writer.close();
    resource.setProperty("jcr:data", new ByteArrayInputStream(data.toByteArray()));
    resource.setProperty("jcr:lastModified", Calendar.getInstance());
    testRootNode.save();
    String xpath = testPath + "/*[jcr:contains(jcr:content, 'lazy')]";
    executeXPathQuery(xpath, new Node[] { file });
}

66. OrderByTest#testOrderByUpperCase()

Project: jackrabbit
Source File: OrderByTest.java
View license
public void testOrderByUpperCase() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    Node n2 = testRootNode.addNode("node2");
    Node n3 = testRootNode.addNode("node3");
    n1.setProperty("text", "Amundsen");
    n2.setProperty("text", "barents");
    n3.setProperty("text", "Wegener");
    testRootNode.save();
    String xpath = "/" + testRoot + "/*[@jcr:primaryType='nt:unstructured'] order by fn:upper-case(@text)";
    Query q = qm.createQuery(xpath, Query.XPATH);
    QueryResult result = q.execute();
    checkResult(result, new Node[] { n1, n2, n3 });
}

67. OrderByTest#testOrderByLowerCase()

Project: jackrabbit
Source File: OrderByTest.java
View license
public void testOrderByLowerCase() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    Node n2 = testRootNode.addNode("node2");
    Node n3 = testRootNode.addNode("node3");
    n1.setProperty("text", "Amundsen");
    n2.setProperty("text", "barents");
    n3.setProperty("text", "Wegener");
    testRootNode.save();
    String xpath = "/" + testRoot + "/*[@jcr:primaryType='nt:unstructured'] order by fn:lower-case(@text)";
    Query q = qm.createQuery(xpath, Query.XPATH);
    QueryResult result = q.execute();
    checkResult(result, new Node[] { n1, n2, n3 });
}

68. SQL2OrderByTest#testOrderByVal()

Project: jackrabbit
Source File: SQL2OrderByTest.java
View license
public void testOrderByVal() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    Node n2 = testRootNode.addNode("node2");
    Node n3 = testRootNode.addNode("node3");
    n1.setProperty("value", 3);
    n2.setProperty("value", 1);
    n3.setProperty("value", 2);
    testRootNode.getSession().save();
    QueryResult qr = executeSQL2Query("SELECT * FROM [nt:base] WHERE ISCHILDNODE([" + testRoot + "]) ORDER BY [value]");
    checkSeq(qr, new Node[] { n2, n3, n1 });
}

69. SQL2OrderByTest#testOrderByValDesc()

Project: jackrabbit
Source File: SQL2OrderByTest.java
View license
public void testOrderByValDesc() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1");
    Node n2 = testRootNode.addNode("node2");
    Node n3 = testRootNode.addNode("node3");
    n1.setProperty("value", 3);
    n2.setProperty("value", 1);
    n3.setProperty("value", 2);
    testRootNode.getSession().save();
    QueryResult qr = executeSQL2Query("SELECT * FROM [nt:base] WHERE ISCHILDNODE([" + testRoot + "]) ORDER BY [value] desc");
    checkSeq(qr, new Node[] { n1, n3, n2 });
}

70. SQL2OrderByTest#testOrderByFnc()

Project: jackrabbit
Source File: SQL2OrderByTest.java
View license
public void testOrderByFnc() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1", "nt:unstructured");
    Node n2 = testRootNode.addNode("node2", "nt:unstructured");
    Node n3 = testRootNode.addNode("node3", "nt:unstructured");
    n1.setProperty("value", "aaa");
    n2.setProperty("value", "a");
    n3.setProperty("value", "aa");
    testRootNode.getSession().save();
    QueryResult qr = executeSQL2Query("SELECT * FROM [nt:base] WHERE ISCHILDNODE([" + testRoot + "]) ORDER BY LENGTH([value])");
    checkSeq(qr, new Node[] { n2, n3, n1 });
}

71. SQL2OrderByTest#testOrderByFncDesc()

Project: jackrabbit
Source File: SQL2OrderByTest.java
View license
public void testOrderByFncDesc() throws RepositoryException {
    Node n1 = testRootNode.addNode("node1", "nt:unstructured");
    Node n2 = testRootNode.addNode("node2", "nt:unstructured");
    Node n3 = testRootNode.addNode("node3", "nt:unstructured");
    n1.setProperty("value", "aaa");
    n2.setProperty("value", "a");
    n3.setProperty("value", "aa");
    testRootNode.getSession().save();
    QueryResult qr = executeSQL2Query("SELECT * FROM [nt:base] WHERE ISCHILDNODE([" + testRoot + "]) ORDER BY LENGTH([value]) desc");
    checkSeq(qr, new Node[] { n1, n3, n2 });
}

72. NodeTest#testIsModified()

Project: jackrabbit
Source File: NodeTest.java
View license
/**
     * Checks if {@link Node#isModified()} works correctly for unmodified and
     * modified nodes.
     */
public void testIsModified() throws RepositoryException {
    // get default workspace test root node using superuser session
    Node defaultRootNode = (Node) superuser.getItem(testRootNode.getPath());
    // create a node
    Node testNode = defaultRootNode.addNode(nodeName1, testNodeType);
    defaultRootNode.save();
    assertFalse("Unmodified node should return false on Node.isModified()", testNode.isModified());
    // check if modified properties are recognized
    testNode.setProperty(propertyName1, "test");
    assertTrue("Modified node should return true on Node.isModified()", testNode.isModified());
    defaultRootNode.save();
    // check if modified child nodes are recognized
    testNode.addNode(nodeName2, testNodeType);
    assertTrue("Modified node should return true on Node.isModified()", testNode.isModified());
}

73. ShareableNodeTest#testGetName()

Project: jackrabbit
Source File: ShareableNodeTest.java
View license
/**
     * Verify that Node.getName returns the correct name in a shareable node
     * (6.13).
     */
public void testGetName() throws Exception {
    // setup parent nodes and first child
    Node a1 = testRootNode.addNode("a1");
    Node a2 = testRootNode.addNode("a2");
    Node b1 = a1.addNode("b1");
    testRootNode.getSession().save();
    // add mixin
    ensureMixinType(b1, mixShareable);
    b1.save();
    // clone
    Workspace workspace = b1.getSession().getWorkspace();
    workspace.clone(workspace.getName(), b1.getPath(), a2.getPath() + "/b2", false);
    Node[] shared = getSharedSet(b1);
    assertEquals(2, shared.length);
    b1 = shared[0];
    Node b2 = shared[1];
    // verify names of nodes b1/b2 in shared set
    assertEquals("b1", b1.getName());
    assertEquals("b2", b2.getName());
}

74. ShareableNodeTest#testSameUUID()

Project: jackrabbit
Source File: ShareableNodeTest.java
View license
/**
     * Verify that shareable nodes in the same shared set have the same
     * jcr:uuid (6.13.10).
     */
public void testSameUUID() throws Exception {
    // setup parent nodes and first child
    Node a1 = testRootNode.addNode("a1");
    Node a2 = testRootNode.addNode("a2");
    Node b1 = a1.addNode("b1");
    testRootNode.getSession().save();
    // add mixin
    ensureMixinType(b1, mixShareable);
    b1.save();
    // clone
    Workspace workspace = b1.getSession().getWorkspace();
    workspace.clone(workspace.getName(), b1.getPath(), a2.getPath() + "/b2", false);
    Node[] shared = getSharedSet(b1);
    assertEquals(2, shared.length);
    b1 = shared[0];
    Node b2 = shared[1];
    // verify nodes in a shared set have the same jcr:uuid
    assertTrue(b1.getUUID().equals(b2.getUUID()));
}

75. ShareableNodeTest#testIsSame()

Project: jackrabbit
Source File: ShareableNodeTest.java
View license
/**
     * Verify that Node.isSame returns <code>true</code> for shareable nodes
     * in the same shared set (6.13.21)
     */
public void testIsSame() throws Exception {
    // setup parent nodes and first child
    Node a1 = testRootNode.addNode("a1");
    Node a2 = testRootNode.addNode("a2");
    Node b1 = a1.addNode("b1");
    testRootNode.getSession().save();
    // add mixin
    ensureMixinType(b1, mixShareable);
    b1.save();
    // clone
    Workspace workspace = b1.getSession().getWorkspace();
    workspace.clone(workspace.getName(), b1.getPath(), a2.getPath() + "/b2", false);
    Node[] shared = getSharedSet(b1);
    assertEquals(2, shared.length);
    b1 = shared[0];
    Node b2 = shared[1];
    // verify b1 is same as b2 (and vice-versa)
    assertTrue(b1.isSame(b2));
    assertTrue(b2.isSame(b1));
}

76. ConcurrentAddNodesClusterIT#ensureIndex()

View license
private static void ensureIndex(Node root, String propertyName) throws RepositoryException {
    Node indexDef = root.getNode(IndexConstants.INDEX_DEFINITIONS_NAME);
    if (indexDef.hasNode(propertyName)) {
        return;
    }
    Node index = indexDef.addNode(propertyName, IndexConstants.INDEX_DEFINITIONS_NODE_TYPE);
    index.setProperty(IndexConstants.TYPE_PROPERTY_NAME, PropertyIndexEditorProvider.TYPE);
    index.setProperty(IndexConstants.REINDEX_PROPERTY_NAME, true);
    index.setProperty(IndexConstants.PROPERTY_NAMES, new String[] { propertyName }, PropertyType.NAME);
    try {
        root.getSession().save();
    } catch (RepositoryException e) {
        root.getSession().refresh(false);
    }
}

77. ObservationTest#setup()

Project: jackrabbit-oak
Source File: ObservationTest.java
View license
@Before
public void setup() throws RepositoryException {
    Session session = getAdminSession();
    NodeTypeManager ntMgr = session.getWorkspace().getNodeTypeManager();
    NodeTypeTemplate mixTest = ntMgr.createNodeTypeTemplate();
    mixTest.setName(TEST_TYPE);
    mixTest.setMixin(true);
    ntMgr.registerNodeType(mixTest, false);
    Node n = session.getRootNode().addNode(TEST_NODE);
    n.setProperty("test_property1", 42);
    n.setProperty("test_property2", "forty_two");
    n.addMixin(TEST_TYPE);
    Node refNode = n.addNode(REFERENCEABLE_NODE);
    refNode.addMixin(JcrConstants.MIX_REFERENCEABLE);
    test_uuid = refNode.getProperty(JcrConstants.JCR_UUID).getString();
    session.save();
    observingSession = createAdminSession();
    observationManager = observingSession.getWorkspace().getObservationManager();
}

78. ReferencesTest#testMultipleReferences()

Project: jackrabbit-oak
Source File: ReferencesTest.java
View license
public void testMultipleReferences() throws RepositoryException {
    Node ref = testRootNode.addNode(nodeName2, testNodeType);
    ref.addMixin(mixReferenceable);
    superuser.save();
    Node n0 = testRootNode.addNode(nodeName1, testNodeType);
    n0.setProperty("myref", ref);
    Node n1 = testRootNode.addNode(nodeName3, testNodeType);
    n1.setProperty("myref", ref);
    superuser.save();
    checkReferences("refs", ref.getReferences(), n0.getPath() + "/myref", n1.getPath() + "/myref");
}

79. ReferencesTest#testMultipleReferences1()

Project: jackrabbit-oak
Source File: ReferencesTest.java
View license
public void testMultipleReferences1() throws RepositoryException {
    Node ref = testRootNode.addNode(nodeName2, testNodeType);
    ref.addMixin(mixReferenceable);
    superuser.save();
    Node n0 = testRootNode.addNode(nodeName1, testNodeType);
    n0.setProperty("myref0", ref);
    Node n1 = testRootNode.addNode(nodeName3, testNodeType);
    n1.setProperty("myref1", ref);
    superuser.save();
    checkReferences("refs", ref.getReferences("myref0"), n0.getPath() + "/myref0");
    checkReferences("refs", ref.getReferences("myref1"), n1.getPath() + "/myref1");
}

80. ReferencesTest#testMixedReferences()

Project: jackrabbit-oak
Source File: ReferencesTest.java
View license
public void testMixedReferences() throws RepositoryException {
    Node ref = testRootNode.addNode(nodeName2, testNodeType);
    ref.addMixin(mixReferenceable);
    superuser.save();
    Node n0 = testRootNode.addNode(nodeName1, testNodeType);
    n0.setProperty("strong_reference", ref);
    Node n1 = testRootNode.addNode(nodeName3, testNodeType);
    n1.setProperty("weak_reference", superuser.getValueFactory().createValue(ref, true));
    superuser.save();
    checkReferences("refs", ref.getReferences(), n0.getPath() + "/strong_reference");
    checkReferences("refs", ref.getWeakReferences(), n1.getPath() + "/weak_reference");
}

81. ReferencesTest#testMVReferences()

Project: jackrabbit-oak
Source File: ReferencesTest.java
View license
public void testMVReferences() throws RepositoryException {
    Node ref0 = testRootNode.addNode(nodeName2, testNodeType);
    ref0.addMixin(mixReferenceable);
    Node ref1 = testRootNode.addNode(nodeName3, testNodeType);
    ref1.addMixin(mixReferenceable);
    superuser.save();
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    Value[] vs = new Value[] { superuser.getValueFactory().createValue(ref0), superuser.getValueFactory().createValue(ref1) };
    n.setProperty("myref", vs);
    superuser.save();
    assertEquals("ref0", ref0.getIdentifier(), n.getProperty("myref").getValues()[0].getString());
    assertEquals("ref1", ref1.getIdentifier(), n.getProperty("myref").getValues()[1].getString());
    checkReferences("refs", ref0.getReferences(), n.getPath() + "/myref");
    checkReferences("refs", ref1.getReferences(), n.getPath() + "/myref");
}

82. ReferencesTest#testMovedVersionedReferences()

Project: jackrabbit-oak
Source File: ReferencesTest.java
View license
public void testMovedVersionedReferences() throws RepositoryException {
    Node ref = testRootNode.addNode(nodeName2, testNodeType);
    ref.addMixin(mixReferenceable);
    superuser.save();
    Node n = testRootNode.addNode(nodeName1, testNodeType);
    n.addMixin(mixVersionable);
    n.setProperty("myref", ref);
    superuser.save();
    String p = n.getPath();
    VersionManager vMgr = superuser.getWorkspace().getVersionManager();
    Version v1 = vMgr.checkpoint(p);
    String newPath = testRootNode.getPath() + "/" + nodeName3;
    superuser.move(ref.getPath(), newPath);
    superuser.save();
    ref = superuser.getNode(newPath);
    Node frozen = v1.getFrozenNode();
    assertEquals("ref", ref.getPath(), frozen.getProperty("myref").getNode().getPath());
    checkReferences("ref in version store", ref.getReferences(), n.getPath() + "/myref");
}

83. ReferencesTest#testRemoveReferenced1()

Project: jackrabbit-oak
Source File: ReferencesTest.java
View license
public void testRemoveReferenced1() throws RepositoryException {
    Node ref = testRootNode.addNode(nodeName1, testNodeType);
    ref.addMixin(mixReferenceable);
    superuser.save();
    Node n1 = testRootNode.addNode(nodeName2, testNodeType);
    n1.setProperty("ref", ref);
    assertEquals(PropertyType.REFERENCE, n1.getProperty("ref").getType());
    superuser.save();
    ref.remove();
    n1.remove();
    superuser.save();
}

84. ReferencesTest#testRecreateWithDifferentUUID()

Project: jackrabbit-oak
Source File: ReferencesTest.java
View license
public void testRecreateWithDifferentUUID() throws RepositoryException {
    Node ref = testRootNode.addNode(nodeName1, testNodeType);
    ref.addMixin(mixReferenceable);
    superuser.save();
    String uuid = ref.getIdentifier();
    Node n1 = testRootNode.addNode(nodeName2, testNodeType);
    n1.setProperty("ref", ref);
    assertEquals(PropertyType.REFERENCE, n1.getProperty("ref").getType());
    superuser.save();
    // recreate
    ref.remove();
    ref = testRootNode.addNode(nodeName1, testNodeType);
    ref.addMixin(mixReferenceable);
    assertFalse(uuid.equals(ref.getIdentifier()));
    try {
        superuser.save();
        fail("must fail with ReferentialIntegrityException");
    } catch (ReferentialIntegrityException e) {
    }
}

85. RepositoryTest#liveNodes()

Project: jackrabbit-oak
Source File: RepositoryTest.java
View license
@Test
public void liveNodes() throws RepositoryException {
    Session session = getAdminSession();
    Node n1 = (Node) session.getItem(TEST_PATH);
    Node n2 = (Node) session.getItem(TEST_PATH);
    Node c1 = n1.addNode("c1");
    Node c2 = n2.addNode("c2");
    assertTrue(n1.hasNode("c1"));
    assertTrue(n1.hasNode("c2"));
    assertTrue(n2.hasNode("c1"));
    assertTrue(n2.hasNode("c2"));
    c1.remove();
    assertFalse(n1.hasNode("c1"));
    assertTrue(n1.hasNode("c2"));
    assertFalse(n2.hasNode("c1"));
    assertTrue(n2.hasNode("c2"));
    c2.remove();
    assertFalse(n1.hasNode("c1"));
    assertFalse(n1.hasNode("c2"));
    assertFalse(n2.hasNode("c1"));
    assertFalse(n2.hasNode("c2"));
}

86. OpvVersionTest#setUp()

Project: jackrabbit-oak
Source File: OpvVersionTest.java
View license
@Override
protected void setUp() throws Exception {
    super.setUp();
    Node n1 = testRootNode.addNode(nodeName1, NodeTypeConstants.NT_OAK_UNSTRUCTURED);
    Node n2 = n1.addNode(nodeName2, NodeTypeConstants.NT_OAK_UNSTRUCTURED);
    Node n3 = n1.addNode(nodeName3, NodeTypeConstants.NT_OAK_UNSTRUCTURED);
    siblingName = nodeName1 + 'b';
    Node n1b = testRootNode.addNode(siblingName, NodeTypeConstants.NT_OAK_UNSTRUCTURED);
    assertEquals(OnParentVersionAction.VERSION, n1.getDefinition().getOnParentVersion());
    assertEquals(OnParentVersionAction.VERSION, n2.getDefinition().getOnParentVersion());
    assertEquals(OnParentVersionAction.VERSION, n3.getDefinition().getOnParentVersion());
    assertEquals(OnParentVersionAction.VERSION, n1b.getDefinition().getOnParentVersion());
    testRootNode.addMixin(MIX_VERSIONABLE);
    n1b.addMixin(MIX_VERSIONABLE);
    n2.addMixin(MIX_VERSIONABLE);
    superuser.save();
    versionManager = superuser.getWorkspace().getVersionManager();
    frozen = versionManager.checkpoint(testRoot).getFrozenNode();
}

87. VersionableTest#testRecreateVersionableNodeWithChangedProperty()

Project: jackrabbit-oak
Source File: VersionableTest.java
View license
// Oak-1272
public void testRecreateVersionableNodeWithChangedProperty() throws Exception {
    Node node = testRootNode.addNode(nodeName1, ntUnstructured);
    node.addMixin(mixVersionable);
    node.setProperty(propertyName1, "foo");
    superuser.save();
    VersionManager vm = superuser.getWorkspace().getVersionManager();
    vm.checkin(node.getPath());
    // re-create node
    node.remove();
    node = testRootNode.addNode(nodeName1, ntUnstructured);
    node.addMixin(mixVersionable);
    node.setProperty(propertyName1, "bar");
    superuser.save();
}

88. QueryFulltextTest#testFulltext()

View license
public void testFulltext() throws Exception {
    Session session = superuser;
    QueryManager qm = session.getWorkspace().getQueryManager();
    Node n1 = testRootNode.addNode("node1");
    n1.setProperty("text", "hello");
    Node n2 = testRootNode.addNode("node2");
    n2.setProperty("text", "hallo");
    Node n3 = testRootNode.addNode("node3");
    n3.setProperty("text", "hello hallo");
    session.save();
    // lowercase "or" mean search for the term "or"
    String sql2 = "select [jcr:path] as [path] from [nt:base] " + "where contains([text], 'hello or hallo') order by [jcr:path]";
    Query q = qm.createQuery(sql2, Query.JCR_SQL2);
    assertEquals("", getResult(q.execute(), "path"));
}

89. QueryFulltextTest#testFulltext()

View license
public void testFulltext() throws Exception {
    Session session = superuser;
    QueryManager qm = session.getWorkspace().getQueryManager();
    Node n1 = testRootNode.addNode("node1");
    n1.setProperty("text", "hello");
    Node n2 = testRootNode.addNode("node2");
    n2.setProperty("text", "hallo");
    Node n3 = testRootNode.addNode("node3");
    n3.setProperty("text", "hello hallo");
    session.save();
    // lowercase "or" mean search for the term "or"
    String sql2 = "select [jcr:path] as [path] from [nt:base] " + "where contains([text], 'hello or hallo') order by [jcr:path]";
    Query q = qm.createQuery(sql2, Query.JCR_SQL2);
    assertEquals("", getResult(q.execute(), "path"));
}

90. QueryFulltextTest#testInValues()

View license
public void testInValues() throws Exception {
    Session session = superuser;
    QueryManager qm = session.getWorkspace().getQueryManager();
    Node n1 = testRootNode.addNode("node1");
    n1.setProperty("text", "hello");
    Node n2 = testRootNode.addNode("node2");
    n2.setProperty("text", "hallo");
    Node n3 = testRootNode.addNode("node3");
    n3.setProperty("text", "hello hallo");
    session.save();
    String sql2 = "select [jcr:path] as [path], [jcr:score], * from [nt:base] as a " + "where [text] in('hello', 'hallo')";
    Query q = qm.createQuery(sql2, Query.JCR_SQL2);
    String path = getResult(q.execute(), "path");
    assertEquals("/testroot/node1, /testroot/node2", path);
}

91. CmisConnectorIT#shouldCreateFolderAndDocument()

Project: modeshape
Source File: CmisConnectorIT.java
View license
@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();
}

92. QueryIntegrationTest#shouldQueryForMixTitle()

Project: modeshape
Source File: QueryIntegrationTest.java
View license
@Test
public void shouldQueryForMixTitle() throws Exception {
    testRoot = session.getRootNode().addNode("root");
    Node node1 = testRoot.addNode("node1");
    node1.addMixin("mix:title");
    node1.setProperty("jcr:title", "title_1");
    Node node2 = testRoot.addNode("node2");
    node2.addMixin("mix:title");
    node2.setProperty("jcr:title", "title_2");
    session.save();
    String sql = "select [jcr:path] from [mix:title] where [jcr:title] LIKE 'ti%'";
    Query query = session.getWorkspace().getQueryManager().createQuery(sql, Query.JCR_SQL2);
    validateQuery().rowCount(2).hasNodesAtPaths("/root/node1", "/root/node2").useIndex("titles").validate(query, query.execute());
}

93. FileSystemConnectorTest#shouldBeAbleToMoveExternalNodes()

View license
@Test
@FixFor({ "MODE-1971", "MODE-1977", "MODE-2256" })
public void shouldBeAbleToMoveExternalNodes() throws Exception {
    Node dir3 = session.getNode("/testRoot/json/dir3");
    dir3.addNode("dir4", "nt:folder");
    session.save();
    assertEquals("nt:folder", ((Node) session.getNode("/testRoot/json/dir3/dir4")).getPrimaryNodeType().getName());
    Node file = session.getNode("/testRoot/json/dir3/simple.json");
    file.addMixin("flex:anyProperties");
    file.setProperty("extraProp", "extraValue");
    assertEquals("nt:file", file.getPrimaryNodeType().getName());
    session.save();
    ((Workspace) session.getWorkspace()).move("/testRoot/json/dir3/simple.json", "/testRoot/json/dir3/dir4/simple.json");
    Node movedFile = session.getNode("/testRoot/json/dir3/dir4/simple.json");
    assertEquals("nt:file", movedFile.getPrimaryNodeType().getName());
    assertThat(movedFile.getProperty("extraProp").getString(), is("extraValue"));
}

94. MockConnectorTest#shouldCreateExternalNode()

Project: modeshape
Source File: MockConnectorTest.java
View license
@Test
public void shouldCreateExternalNode() throws Exception {
    federationManager.createProjection("/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "federated1");
    Node doc1Federated = session.getNode("/testRoot/federated1");
    Node externalNode1 = doc1Federated.addNode("federated1_1", null);
    externalNode1.setProperty("prop1", "a value");
    externalNode1.addNode("federated1_1_1", null);
    session.save();
    Node federated1_1 = doc1Federated.getNode("federated1_1");
    assertNotNull(federated1_1);
    assertEquals(doc1Federated, federated1_1.getParent());
    assertEquals(1, doc1Federated.getNodes().getSize());
    assertNotNull(session.getNode("/testRoot/federated1/federated1_1"));
    assertEquals("a value", federated1_1.getProperty("prop1").getString());
    Node federated1_1_1 = assertNodeFound("/testRoot/federated1/federated1_1/federated1_1_1");
    assertEquals(federated1_1, federated1_1_1.getParent());
}

95. MockConnectorTest#shouldUpdateExternalNodeChildren()

Project: modeshape
Source File: MockConnectorTest.java
View license
@Test
public void shouldUpdateExternalNodeChildren() throws Exception {
    federationManager.createProjection("/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "federated1");
    Node doc1Federated = session.getNode("/testRoot/federated1");
    doc1Federated.addNode("federated1_1", null);
    session.save();
    String externalNodePath = "/testRoot/federated1/federated1_1";
    assertExternalNodeHasChildren(externalNodePath);
    Node externalNode = session.getNode(externalNodePath);
    externalNode.addNode("child1");
    externalNode.addNode("child2");
    session.save();
    assertExternalNodeHasChildren(externalNodePath, "child1", "child2");
    externalNode = session.getNode(externalNodePath);
    externalNode.getNode("child1").remove();
    externalNode.getNode("child2").remove();
    externalNode.addNode("child3");
    session.save();
    assertExternalNodeHasChildren(externalNodePath, "child3");
}

96. MockConnectorTest#shouldReorderExternalNodes()

Project: modeshape
Source File: MockConnectorTest.java
View license
@Test
public void shouldReorderExternalNodes() throws Exception {
    federationManager.createProjection("/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "federated1");
    Node doc1Federated = session.getNode("/testRoot/federated1");
    Node parent1 = doc1Federated.addNode("parent1", null);
    parent1.addNode("child1");
    parent1.addNode("child2");
    parent1.addNode("child3");
    session.save();
    assertExternalNodeHasChildren("/testRoot/federated1/parent1", "child1", "child2", "child3");
    parent1.orderBefore("child1", "child2");
    session.save();
    assertExternalNodeHasChildren("/testRoot/federated1/parent1", "child2", "child1", "child3");
}

97. ImportExportTest#shouldExportViewsWithLocks()

Project: modeshape
Source File: ImportExportTest.java
View license
@Test
@FixFor("MODE-2035")
public void shouldExportViewsWithLocks() throws Exception {
    Node node1 = session.getRootNode().addNode("node1");
    node1.addMixin("mix:lockable");
    Node node1_1 = node1.addNode("node1_1");
    node1_1.addMixin("mix:lockable");
    Node node2 = session.getRootNode().addNode("node2");
    node2.addMixin("mix:lockable");
    session.save();
    session.getWorkspace().lockManager().lock("/node1", true, true, Long.MAX_VALUE, null);
    session.getWorkspace().lockManager().lock("/node2", false, false, Long.MAX_VALUE, null);
    testImportExport("/", "/", ExportType.SYSTEM, true, false, true);
    testImportExport("/", "/", ExportType.DOCUMENT, true, false, true);
}

98. JcrNodeTest#shouldMakeReferenceableNodesUsingCustomTypes()

Project: modeshape
Source File: JcrNodeTest.java
View license
@Test
@FixFor("MODE-1663")
public void shouldMakeReferenceableNodesUsingCustomTypes() throws Exception {
    Node cars = session.getNode("/Cars");
    cars.addNode("referenceableCar1", "car:referenceableCar");
    Node refCar = cars.addNode("referenceableCar2");
    refCar.setPrimaryType("car:referenceableCar");
    session.save();
    Node referenceableCar1 = session.getNode("/Cars/referenceableCar1");
    String uuid = referenceableCar1.getProperty(JcrLexicon.UUID.getString()).getString();
    assertEquals(referenceableCar1.getIdentifier(), uuid);
    Node referenceableCar2 = session.getNode("/Cars/referenceableCar2");
    uuid = referenceableCar2.getProperty(JcrLexicon.UUID.getString()).getString();
    assertEquals(referenceableCar2.getIdentifier(), uuid);
}

99. JcrSessionTest#shouldAllowRemovingAndRestoringPersistedReference()

Project: modeshape
Source File: JcrSessionTest.java
View license
@FixFor("MODE-2283")
@Test
public void shouldAllowRemovingAndRestoringPersistedReference() throws Exception {
    Node referenceableNode = session.getRootNode().addNode("referenceable");
    referenceableNode.addMixin(JcrMixLexicon.REFERENCEABLE.toString());
    Value strongRefValue = session.getValueFactory().createValue(referenceableNode, false);
    Node node1 = session.getRootNode().addNode("node1");
    node1.setProperty("prop1", strongRefValue);
    session.save();
    // First remove the property ...
    node1.setProperty("prop1", (Value) null);
    // And then set the property to the same value that's persisted. Essentially, this session is trying to restore
    // the reference that we just removed (transitively). The result should be no net changes in this session.
    node1.setProperty("prop1", strongRefValue);
    // Now save the changes (even though there should be none) ...
    session.save();
    PropertyIterator propertyIterator = referenceableNode.getReferences();
    assertEquals(1, propertyIterator.getSize());
}

100. JcrSessionTest#shouldNotEnforceReferentialIntegrityOfWeakReferenceWhenRemovingNodes()

Project: modeshape
Source File: JcrSessionTest.java
View license
@FixFor("MODE-1685")
@Test
public void shouldNotEnforceReferentialIntegrityOfWeakReferenceWhenRemovingNodes() throws Exception {
    JcrValueFactory valueFactory = session.getValueFactory();
    Node targetNode = session.getRootNode().addNode("target");
    targetNode.addMixin(JcrMixLexicon.REFERENCEABLE.toString());
    Node parentNode = session.getRootNode().addNode("parent");
    Node childNode = parentNode.addNode("child");
    childNode.setProperty("ref1", valueFactory.createValue(targetNode, true));
    session.save();
    // Delete the target - there should be no strong references, but the weak is okay and won't prevent removal ...
    targetNode.remove();
    session.save();
}