javax.jcr.PropertyType Java Examples

The following examples show how to use javax.jcr.PropertyType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DocViewPropertyTest.java    From jackrabbit-filevault with Apache License 2.0 7 votes vote down vote up
@Test
public void testEmptyMVBoolean() throws Exception {
    Property p = Mockito.mock(Property.class);
    Value value = Mockito.mock(Value.class);

    Mockito.when(value.getString()).thenReturn("false");
    Value[] values = new Value[]{value};
    PropertyDefinition pd = Mockito.mock(PropertyDefinition.class);
    Mockito.when(pd.isMultiple()).thenReturn(true);

    Mockito.when(p.getType()).thenReturn(PropertyType.BOOLEAN);
    Mockito.when(p.getName()).thenReturn("foo");
    Mockito.when(p.getValues()).thenReturn(values);
    Mockito.when(p.getDefinition()).thenReturn(pd);

    String result = DocViewProperty.format(p);
    Assert.assertEquals("formatted property", "{Boolean}[false]", result);

    // now round trip back
    DocViewProperty dp = DocViewProperty.parse("foo", result);
    Assert.assertEquals(new DocViewProperty("foo", new String[] {"false"}, true, PropertyType.BOOLEAN), dp);
}
 
Example #2
Source File: RCPTest.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimple() throws IOException, RepositoryException, ConfigurationException {
    Node a = JcrUtils.getOrCreateByPath(SRC_TEST_NODE_PATH, NodeType.NT_UNSTRUCTURED, NodeType.NT_UNSTRUCTURED, admin, true);
    a.setProperty("p0", "0");
    a.setProperty("p1", "1");
    a.setProperty("m0", new String[]{"0", "1", "2"}, PropertyType.STRING);
    admin.save();

    assertNodeExists(SRC_TEST_NODE_PATH);

    RepositoryCopier rcp = new RepositoryCopier();
    rcp.copy(admin, SRC_PATH, admin, DST_PATH, true);

    assertProperty(DST_TEST_NODE_PATH + "/p0", "0");
    assertProperty(DST_TEST_NODE_PATH + "/p1", "1");
    assertProperty(DST_TEST_NODE_PATH + "/m0", new String[]{"0", "1", "2"});
}
 
Example #3
Source File: OakIndexDefinitionValidatorTest.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
@Test
public void test_index_acl() throws IOException, ConfigurationException {
    try (InputStream input = this.getClass().getResourceAsStream("/oak-index/filter-with-acl.xml")) {
        DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter();
        filter.load(input);
        Assert.assertThat(validator.validate(filter), AnyValidationMessageMatcher.noValidationInCollection());
    }
    Map<String, DocViewProperty> props = new HashMap<>();
    props.put("rep:policy", new DocViewProperty("rep:policy", new String[] { "/home]" }, true, PropertyType.STRING));
    DocViewNode node = new DocViewNode("rep:policy", "rep:policy", null, props, null, "rep:ACL");

    Collection<ValidationMessage> messages = validator.validate(node, "/oak:index/rep:policy",
            Paths.get("_oak_index", "_rep_policy.xml"), true);
    Assert.assertThat(messages, AnyValidationMessageMatcher.noValidationInCollection());
    node = new DocViewNode("allow", "allow", null, props, null, "rep:GrantACE");
    messages = validator.validate(node, "/oak:index/rep:policy/allow",
            Paths.get("_oak_index", "_rep_policy.xml"), false);
    Assert.assertThat(messages, AnyValidationMessageMatcher.noValidationInCollection());
}
 
Example #4
Source File: DocViewProperty.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new property.
 * @param name name of the property
 * @param values values.
 * @param multi multiple flag
 * @param type type of the property
 * @param isRef {@code true} to indicated that this is a binary reference property
 * @throws IllegalArgumentException if single value property and not exactly 1 value is given.
 */
public DocViewProperty(String name, String[] values, boolean multi, int type, boolean isRef) {
    this.name = name;
    this.values = values;
    isMulti = multi;
    // validate type
    if (type == PropertyType.UNDEFINED) {
        if ("jcr:primaryType".equals(name) || "jcr:mixinTypes".equals(name)) {
            type = PropertyType.NAME;
        }
    }
    this.type = type;
    if (!isMulti && values.length != 1) {
        throw new IllegalArgumentException("Single value property needs exactly 1 value.");
    }
    this.isReferenceProperty = isRef;
}
 
Example #5
Source File: ValueComparator.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
public int compare(Value o1, Value o2) {
    try {
        // assume types are equal
        switch (o1.getType()) {
            case PropertyType.BINARY:
                throw new IllegalArgumentException("sorting of binary values not supported.");
            case PropertyType.DATE:
                return o1.getDate().compareTo(o2.getDate());
            case PropertyType.DECIMAL:
                return o1.getDecimal().compareTo(o2.getDecimal());
            case PropertyType.DOUBLE:
                return ((Double) o1.getDouble()).compareTo(o2.getDouble());
            case PropertyType.LONG:
                return ((Long) o1.getLong()).compareTo(o2.getLong());
            default:
                return o1.getString().compareTo(o2.getString());
        }
    } catch (RepositoryException e) {
        throw new IllegalArgumentException(e);
    }
}
 
Example #6
Source File: ValueFactoryImpl.java    From jackalope with Apache License 2.0 6 votes vote down vote up
@Override
public Value createValue(String value, int type) throws ValueFormatException {
    switch (type) {
        case PropertyType.STRING:
            return createValue(value);
        case PropertyType.LONG:
            return createValue(Long.valueOf(value));
        case PropertyType.DOUBLE:
            return createValue(Double.valueOf(value));
        case PropertyType.BOOLEAN:
            return createValue(Boolean.valueOf(value));
        case PropertyType.DECIMAL:
            return createValue(new BigDecimal(value));
        case PropertyType.DATE: // TODO: parse dates
        case PropertyType.BINARY:
            return createValue(createBinary(value));
        default:
            return null;
    }
}
 
Example #7
Source File: DocViewPropertyTest.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
@Test
public void testParseMVSpecial() {
    DocViewProperty p = DocViewProperty.parse("foo", "[\\[hello,world]");
    assertEquals(p, true, PropertyType.UNDEFINED, "[hello", "world");
    p = DocViewProperty.parse("foo", "[[hello],[world]]");
    assertEquals(p, true, PropertyType.UNDEFINED, "[hello]", "[world]");
    p = DocViewProperty.parse("foo", "[he\\[llo,world]");
    assertEquals(p, true, PropertyType.UNDEFINED, "he[llo", "world");
    p = DocViewProperty.parse("foo", "[hello\\[,world]");
    assertEquals(p, true, PropertyType.UNDEFINED, "hello[", "world");
    p = DocViewProperty.parse("foo", "[hello,\\[world]");
    assertEquals(p, true, PropertyType.UNDEFINED, "hello", "[world");
    p = DocViewProperty.parse("foo", "[hello,world\\[]");
    assertEquals(p, true, PropertyType.UNDEFINED, "hello", "world[");
    p = DocViewProperty.parse("foo", "[hello,world");
    assertEquals(p, true, PropertyType.UNDEFINED, "hello", "world");
    p = DocViewProperty.parse("foo", "[bla{a\\,b},foo{a\\,b},bar{a\\,b}]");
    assertEquals(p, true, PropertyType.UNDEFINED, "bla{a,b}", "foo{a,b}", "bar{a,b}");
    p = DocViewProperty.parse("foo", "[/content/[a-z]{2\\,3}/[a-z]{2\\,3}(/.*)]");
    assertEquals(p, true, PropertyType.UNDEFINED, "/content/[a-z]{2,3}/[a-z]{2,3}(/.*)");
}
 
Example #8
Source File: DocViewPropertyTest.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
/**
 * Special test for mv properties with 1 empty string value (JCR-3661)
 * @throws Exception
 */
@Test
public void testEmptyMVString() throws Exception {
    Property p = Mockito.mock(Property.class);
    Value value = Mockito.mock(Value.class);

    Mockito.when(value.getString()).thenReturn("");
    Value[] values = new Value[]{value};
    PropertyDefinition pd = Mockito.mock(PropertyDefinition.class);
    Mockito.when(pd.isMultiple()).thenReturn(true);

    Mockito.when(p.getType()).thenReturn(PropertyType.STRING);
    Mockito.when(p.getName()).thenReturn("foo");
    Mockito.when(p.getValues()).thenReturn(values);
    Mockito.when(p.getDefinition()).thenReturn(pd);

    String result = DocViewProperty.format(p);
    Assert.assertEquals("formatted property", "[\\0]", result);

    // now round trip back
    DocViewProperty dp = DocViewProperty.parse("foo", result);
    Assert.assertEquals(new DocViewProperty("foo", new String[] {""}, true, PropertyType.UNDEFINED), dp);
}
 
Example #9
Source File: TestPackageInstall.java    From jackrabbit-filevault with Apache License 2.0 6 votes vote down vote up
/**
 * Installs a binary properties.
 */
@Test
public void testBinaryProperties() throws RepositoryException, IOException, PackageException {
    JcrPackage pack = packMgr.upload(getStream("/test-packages/tmp_binary.zip"), false);
    assertNotNull(pack);
    pack.install(getDefaultOptions());

    Property p = admin.getProperty("/tmp/binary/test/jcr:data");
    assertEquals(PropertyType.BINARY, p.getType());

    StringBuilder buffer = new StringBuilder(8192);
    while (buffer.length() < 8192) {
        buffer.append("0123456789abcdef");
    }
    String result = IOUtils.toString(p.getBinary().getStream());

    assertEquals(buffer.toString(), result);
}
 
Example #10
Source File: EmptyElementsValidatorTest.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithEmptyElements() {
    Map<String, DocViewProperty> props = new HashMap<>();
    props.put("prop1", new DocViewProperty("prop1", new String[] { "value1" } , false, PropertyType.STRING));

    // order node only (no other property)
    DocViewNode node = new DocViewNode("jcr:root", "jcr:root", null, Collections.emptyMap(), null, null);
    Assert.assertThat(validator.validate(node, new NodeContextImpl("/apps/test/node1", Paths.get("node1"), Paths.get("")), false), AnyValidationMessageMatcher.noValidationInCollection());
    
    // another order node (to be covered by another file)
    node = new DocViewNode("jcr:root", "jcr:root", null, Collections.emptyMap(), null, null);
    Assert.assertThat(validator.validate(node, new NodeContextImpl("/apps/test/node2", Paths.get("node2"), Paths.get("")), false), AnyValidationMessageMatcher.noValidationInCollection());
    
    // another order node only
    node = new DocViewNode("jcr:root", "jcr:root", null, Collections.emptyMap(), null, null);
    Assert.assertThat(validator.validate(node, new NodeContextImpl("/apps/test/node3", Paths.get("node3"), Paths.get("")), false), AnyValidationMessageMatcher.noValidationInCollection());
    
    // no order node (due to props)
    node = new DocViewNode("jcr:root", "jcr:root", null, props, null, null);
    Assert.assertThat(validator.validate(node, new NodeContextImpl("/apps/test/node4", Paths.get("node4"), Paths.get("")), false), AnyValidationMessageMatcher.noValidationInCollection());
    
    // no order node (due to primary type)
    node = new DocViewNode("jcr:root", "jcr:root", null, Collections.emptyMap(), null, "nt:unstructed");
    Assert.assertThat(validator.validate(node, new NodeContextImpl("/apps/test/node5", Paths.get("node5"), Paths.get("")), false), AnyValidationMessageMatcher.noValidationInCollection());
    
    // overwritten node 2 (plain file/folder)
    Assert.assertNull(validator.validate(new NodeContextImpl("/apps/test/node2", Paths.get("apps", "test", "node.xml"), Paths.get("base"))));
    
    // empty node with name rep:policy (doesn't do any harm and is included in standard packages from exporter as well)
    node = new DocViewNode("rep:policy", "rep:polucy", null, Collections.emptyMap(), null, null);
    Assert.assertThat(validator.validate(node, new NodeContextImpl("/apps/test/node6", Paths.get("node6"), Paths.get("")), false), AnyValidationMessageMatcher.noValidationInCollection());
    
    ValidationExecutorTest.assertViolation(validator.done(), 
            new ValidationMessage(ValidationMessageSeverity.ERROR, EmptyElementsValidator.MESSAGE_EMPTY_NODES, "/apps/test/node1", Paths.get("node1"), Paths.get(""), null),
            new ValidationMessage(ValidationMessageSeverity.ERROR, EmptyElementsValidator.MESSAGE_EMPTY_NODES, "/apps/test/node3", Paths.get("node3"), Paths.get(""), null));
}
 
Example #11
Source File: AggregateImpl.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
private void include(Node parent, Property prop, String propPath)
        throws RepositoryException {
    String relPath = propPath.substring(path.length());
    if (includes == null || !includes.contains(relPath)) {
        if (log.isDebugEnabled()) {
            log.trace("including {} -> {}", path, propPath);
        }
        // ensure that parent node is included as well
        include(parent, null);
        includes.add(mgr.cacheString(relPath));
        if (prop.getType() == PropertyType.BINARY) {
            boolean includeBinary = true;
            if (useBinaryReferences) {
                Binary bin = prop.getBinary();
                if (bin != null && bin instanceof ReferenceBinary) {
                    String binaryReference = ((ReferenceBinary) bin).getReference();

                    // do not create a separate binary file if there is a reference
                    if (binaryReference != null) {
                        includeBinary = false;
                    }
                }
            }

            if (includeBinary) {
                if (binaries == null) {
                    binaries = new LinkedList<Property>();
                }
                binaries.add(prop);
            }
        }
    }
}
 
Example #12
Source File: CNDImporter.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
private int doPropertyType(Node pdi) throws ParseException, RepositoryException {
    if (!currentTokenEquals(Lexer.BEGIN_TYPE)) {
        return PropertyType.UNDEFINED;
    }
    nextToken();
    int type = PropertyType.UNDEFINED;
    if (currentTokenEquals(Lexer.STRING)) {
        type = PropertyType.STRING;
    } else if (currentTokenEquals(Lexer.BINARY)) {
        type = PropertyType.BINARY;
    } else if (currentTokenEquals(Lexer.LONG)) {
        type = PropertyType.LONG;
    } else if (currentTokenEquals(Lexer.DOUBLE)) {
        type = PropertyType.DOUBLE;
    } else if (currentTokenEquals(Lexer.BOOLEAN)) {
        type = PropertyType.BOOLEAN;
    } else if (currentTokenEquals(Lexer.DATE)) {
        type = PropertyType.DATE;
    } else if (currentTokenEquals(Lexer.NAME)) {
        type = PropertyType.NAME;
    } else if (currentTokenEquals(Lexer.PATH)) {
        type = PropertyType.PATH;
    } else if (currentTokenEquals(Lexer.REFERENCE)) {
        type = PropertyType.REFERENCE;
    } else if (currentTokenEquals(Lexer.UNDEFINED)) {
        type = PropertyType.UNDEFINED;
    } else {
        lexer.fail("Unknown property type '" + currentToken + "' specified");
    }
    pdi.setProperty(JcrConstants.JCR_REQUIREDTYPE, PropertyType.nameFromValue(type).toUpperCase());
    nextToken();
    if (!currentTokenEquals(Lexer.END_TYPE)) {
        lexer.fail("Missing '" + Lexer.END_TYPE + "' delimiter for end of property type");
    }
    nextToken();
    return type;
}
 
Example #13
Source File: ValueImpl.java    From jackalope with Apache License 2.0 5 votes vote down vote up
private static int selectPropertyType(Object value) {
    return (value instanceof String) ? PropertyType.STRING :
        (value instanceof Long) ? PropertyType.LONG :
            (value instanceof Double) ? PropertyType.DOUBLE :
                (value instanceof BigDecimal) ? PropertyType.DECIMAL :
                    (value instanceof Calendar) ? PropertyType.DATE :
                        (value instanceof Boolean) ? PropertyType.BOOLEAN :
                            (value instanceof Binary) ? PropertyType.BINARY :
                                PropertyType.UNDEFINED;
}
 
Example #14
Source File: DocViewPropertyTest.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
@Test
public void testParseSpecial() {
    DocViewProperty p = DocViewProperty.parse("foo", "\\{hello, world}");
    assertEquals(p, false, PropertyType.UNDEFINED, "{hello, world}");
    p = DocViewProperty.parse("foo", "{String}\\[hello");
    assertEquals(p, false, PropertyType.STRING, "[hello");
}
 
Example #15
Source File: DocViewPropertyTest.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
@Test
public void testParseMVString() {
    DocViewProperty p = DocViewProperty.parse("foo", "[hello,world]");
    assertEquals(p, true, PropertyType.UNDEFINED, "hello", "world");
    p = DocViewProperty.parse("foo", "[hello\\,world]");
    assertEquals(p, true, PropertyType.UNDEFINED, "hello,world");
}
 
Example #16
Source File: DocViewPropertyTest.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
@Test
public void testParseEmptyMVStrings() {
    DocViewProperty p = DocViewProperty.parse("foo", "[,a,b,c]");
    assertEquals(p, true, PropertyType.UNDEFINED, "", "a", "b", "c");
    p = DocViewProperty.parse("foo", "[a,b,c,]");
    assertEquals(p, true, PropertyType.UNDEFINED, "a", "b", "c", "");
    p = DocViewProperty.parse("foo", "[,,,]");
    assertEquals(p, true, PropertyType.UNDEFINED, "", "", "", "");
}
 
Example #17
Source File: TestPackageInstall.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
/**
 * Installs a binary properties twice to check if it doesn't report an update.
 * TODO: this is not implemented yet. see JCRVLT-110
 */
@Test
@Ignore
public void testBinaryPropertyTwice() throws RepositoryException, IOException, PackageException {
    JcrPackage pack = packMgr.upload(getStream("/test-packages/tmp_binary.zip"), false);
    assertNotNull(pack);
    pack.install(getDefaultOptions());

    Property p = admin.getProperty("/tmp/binary/test/jcr:data");
    assertEquals(PropertyType.BINARY, p.getType());

    StringBuilder buffer = new StringBuilder(8192);
    while (buffer.length() < 8192) {
        buffer.append("0123456789abcdef");
    }
    String result = IOUtils.toString(p.getBinary().getStream());

    assertEquals(buffer.toString(), result);

    // install again to check if binary data is not updated
    ImportOptions opts = getDefaultOptions();
    TrackingListener listener = new TrackingListener(opts.getListener());
    opts.setListener(listener);

    pack.install(opts);

    //TODO: assertEquals("-", listener.getActions().get("/tmp/binary/test"));
    assertEquals("U", listener.getActions().get("/tmp/binary/test"));
}
 
Example #18
Source File: Restrictions.java    From APM with Apache License 2.0 5 votes vote down vote up
private Value[] createRestrictions(ValueFactory valueFactory, List<String> names)
    throws ValueFormatException {

  Value[] values = new Value[names.size()];
  for (int index = 0; index < names.size(); index++) {
    values[index] = valueFactory.createValue(names.get(index), PropertyType.NAME);
  }
  return values;
}
 
Example #19
Source File: EmptyElementsValidatorTest.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoEmptyElements() {
    Map<String, DocViewProperty> props = new HashMap<>();
    props.put("prop1", new DocViewProperty("prop1", new String[] { "value1" } , false, PropertyType.STRING));

    // primary node type set as well
    DocViewNode node = new DocViewNode("jcr:root", "jcr:root", null, Collections.emptyMap(), null, "nt:unstructured");
    Assert.assertThat(validator.validate(node, new NodeContextImpl("somepath1", Paths.get("/some/path"), Paths.get("")), false), AnyValidationMessageMatcher.noValidationInCollection());
    
    // primary node type set with additional properties
    node = new DocViewNode("jcr:root", "jcr:root", null, props, null, "nt:unstructured");
    Assert.assertThat(validator.validate(node, new NodeContextImpl("somepath2", Paths.get("/some/path"), Paths.get("")), false), AnyValidationMessageMatcher.noValidationInCollection());
    Assert.assertThat(validator.done(), AnyValidationMessageMatcher.noValidationInCollection());
}
 
Example #20
Source File: EmptyElementsValidatorTest.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithEmptyElementsAndFolders() {
    Map<String, DocViewProperty> props = new HashMap<>();
    props.put("prop1", new DocViewProperty("prop1", new String[] { "value1" } , false, PropertyType.STRING));

    // order node only (no other property)
    DocViewNode node = new DocViewNode("jcr:root", "jcr:root", null, Collections.emptyMap(), null, null);
    Assert.assertThat(validator.validate(node, new NodeContextImpl("/apps/test/node1", Paths.get("node1"), Paths.get("")), false), AnyValidationMessageMatcher.noValidationInCollection());
    
    // folder below 
    Assert.assertThat(validator.validate(new NodeContextImpl("/apps/test/node1", Paths.get("test"), Paths.get("base"))), AnyValidationMessageMatcher.noValidationInCollection());
    Assert.assertThat(validator.done(), AnyValidationMessageMatcher.noValidationInCollection());;
}
 
Example #21
Source File: MergeLimitationsValidatorTest.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithAggregateAtWrongLevel() {
    Map<String, DocViewProperty> props = new HashMap<>();
    props.put("prop1", new DocViewProperty("prop1", new String[] { "value1" } , false, PropertyType.STRING));

    DocViewNode node = new DocViewNode("somename", "somename", null, props, null, "nt:unstructured");
    Collection<ValidationMessage> messages = validator.validate(node, "/apps/test/deep", Paths.get(".content.xml"), false);
    ValidationExecutorTest.assertViolation(messages,
            new ValidationMessage(ValidationMessageSeverity.ERROR, String.format(MergeLimitationsValidator.PACKAGE_NON_ROOT_NODE_MERGED, "/apps/test/deep")));
}
 
Example #22
Source File: MergeLimitationsValidatorTest.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithAggregateAtCorrectLevel() {
    Map<String, DocViewProperty> props = new HashMap<>();
    props.put("prop1", new DocViewProperty("prop1", new String[] { "value1" } , false, PropertyType.STRING));

    DocViewNode node = new DocViewNode("somename", "somename", null, props, null, "nt:unstructured");
    Collection<ValidationMessage> messages = validator.validate(node, "/apps/test/deep", Paths.get(".content.xml"), true);
    Assert.assertThat(messages, AnyValidationMessageMatcher.noValidationInCollection());
}
 
Example #23
Source File: OakIndexDefinitionValidatorTest.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
@Test
public void test_index_at_root() throws Exception {
    Map<String, DocViewProperty> props = new HashMap<>();
    props.put("includedPaths", new DocViewProperty("includedPaths", new String[] { "/home]" }, true, PropertyType.STRING));
    DocViewNode node = new DocViewNode("testindex", "testindex", null, props, null, "oak:QueryIndexDefinition");

    Collection<ValidationMessage> messages = validator.validate(node, "/oak:index/testindex",
            Paths.get("_oak_index/testindex/.content.xml"), true);
    ValidationExecutorTest.assertViolation(messages,
            new ValidationMessage(ValidationMessageSeverity.ERROR,
                    String.format(OakIndexDefinitionValidator.MESSAGE_INDEX_AT_NODE, rootPackagePath, "/oak:index/testindex")));
}
 
Example #24
Source File: OakIndexDefinitionValidatorTest.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
@Test
public void test_index_at_deep_path() throws Exception {
    Map<String, DocViewProperty> props = new HashMap<>();
    props.put("includedPaths", new DocViewProperty("includedPaths", new String[] { "/home]" }, true, PropertyType.STRING));
    DocViewNode node = new DocViewNode("indexDef", "indexDef", null, props, null, "oak:QueryIndexDefinition");

    Collection<ValidationMessage> messages = validator.validate(node, "/apps/project/oak:index/indexDef",
            Paths.get("apps", "project", "_oak_index", "content.xml"), false);
    ValidationExecutorTest.assertViolation(messages,
            new ValidationMessage(ValidationMessageSeverity.ERROR,
                    String.format(OakIndexDefinitionValidator.MESSAGE_INDEX_AT_NODE, rootPackagePath, "/apps/project/oak:index/indexDef")));

}
 
Example #25
Source File: PrimaryNodeTypeValidatorTest.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
@Test
public void testNodeTypes() throws IOException, ConfigurationException {
    DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter();
    try (InputStream input = this.getClass().getResourceAsStream("/filter.xml")) {
        filter.load(input);
    }
    validator = new PrimaryNodeTypeValidator(ValidationMessageSeverity.ERROR, filter);
    Map<String, DocViewProperty> props = new HashMap<>();
    props.put("prop1", new DocViewProperty("prop1", new String[] { "value1" } , false, PropertyType.STRING));

    // order node only (no other property)
    DocViewNode node = new DocViewNode("jcr:root", "jcr:root", null, Collections.emptyMap(), null, null);
    Assert.assertThat(validator.validate(node, "/apps/test", Paths.get("/some/path"), false), AnyValidationMessageMatcher.noValidationInCollection());

    // primary node type set with additional properties
    node = new DocViewNode("jcr:root", "jcr:root", null, props, null, "nt:unstructured");
    Assert.assertThat(validator.validate(node, "/apps/test", Paths.get("/some/path"), false), AnyValidationMessageMatcher.noValidationInCollection());

    // missing node type but not contained in filter (with properties)
    node = new DocViewNode("jcr:root", "jcr:root", null, props, null, null);
    Assert.assertThat(validator.validate(node, "/apps/test2/invalid", Paths.get("/some/path"), false), AnyValidationMessageMatcher.noValidationInCollection());

    // missing node type and contained in filter (with properties)
    ValidationExecutorTest.assertViolation(
                    validator.validate(node, "/apps/test", Paths.get("/some/path"), false),
                    new ValidationMessage(ValidationMessageSeverity.ERROR, String.format(PrimaryNodeTypeValidator.MESSAGE_MISSING_PRIMARY_TYPE, "/apps/test")));
}
 
Example #26
Source File: DocumentViewParserValidatorTest.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
@Test
public void testDocViewDotContentXmlOnRootLevel()
        throws ParserConfigurationException, SAXException, URISyntaxException, IOException, NamespaceException {
    Mockito.when(docViewXmlValidator.validate(Mockito.any(), Mockito.any(), Mockito.anyBoolean())).thenReturn(Collections.singleton(new ValidationMessage(ValidationMessageSeverity.ERROR, "startDocView")));
    try (InputStream input = this.getClass().getResourceAsStream("/simple-package/jcr_root/.content.xml")) {
        Collection<ValidationMessage> messages = validator.validateJcrData(input, Paths.get(".content.xml"), Paths.get(""), nodePathsAndLineNumbers);
        // filter
        ValidationExecutorTest.assertViolation(messages,
                new ValidationViolation("docviewid", ValidationMessageSeverity.ERROR, "startDocView", Paths.get(".content.xml"), Paths.get(""), "/", 6, 32, null
                        ));

        // verify node names
        Map<String, Integer> expectedNodePathsAndLineNumber = new HashMap<>();
        expectedNodePathsAndLineNumber.put("/", 6);
        Assert.assertEquals(expectedNodePathsAndLineNumber, nodePathsAndLineNumbers);
        Map<String, DocViewProperty> properties = new HashMap<>();
        properties.put(NameConstants.JCR_PRIMARYTYPE.toString(),
                new DocViewProperty(NameConstants.JCR_PRIMARYTYPE.toString(), new String[] { "rep:root" }, false,
                        PropertyType.UNDEFINED));
        properties.put(NameConstants.JCR_MIXINTYPES.toString(), new DocViewProperty(NameConstants.JCR_MIXINTYPES.toString(), new String[] { "rep:AccessControllable" ,"rep:RepoAccessControllable" }, true, PropertyType.UNDEFINED));
        properties.put(NAME_SLING_RESOURCE_TYPE.toString(), new DocViewProperty(NAME_SLING_RESOURCE_TYPE.toString(), new String[] { "sling:redirect" }, false, PropertyType.UNDEFINED));
        properties.put(NAME_SLING_TARGET.toString(), new DocViewProperty(NAME_SLING_TARGET.toString(), new String[] { "/index.html" }, false, PropertyType.UNDEFINED));
        
        DocViewNode node = new DocViewNode(NameConstants.JCR_ROOT.toString(), "jcr:root", null, properties, new String[] { "rep:AccessControllable" ,"rep:RepoAccessControllable" }, "rep:root");
        Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/", Paths.get(".content.xml"), Paths.get("")), true);
    }
}
 
Example #27
Source File: DocumentViewParserValidatorTest.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
@Test
public void testDocViewWithRegularFileName()
        throws ParserConfigurationException, SAXException, URISyntaxException, IOException, NamespaceException {

    try (InputStream input = this.getClass().getResourceAsStream("/simple-package/jcr_root/apps/child1.xml")) {
        Collection<ValidationMessage> messages = validator.validateJcrData(input, Paths.get("apps", "child1.xml"), Paths.get(""), nodePathsAndLineNumbers);
        Assert.assertThat(messages, AnyValidationViolationMatcher.noValidationInCollection());

        Map<String, DocViewProperty> properties = new HashMap<>();
        properties.put(NameConstants.JCR_PRIMARYTYPE.toString(),
                new DocViewProperty(NameConstants.JCR_PRIMARYTYPE.toString(), new String[] { "sling:Folder" }, false,
                        PropertyType.UNDEFINED));
        DocViewNode node = new DocViewNode("{}child1", "jcr:root", null, properties, null, "sling:Folder");
        Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps/child1", Paths.get("apps", "child1.xml"), Paths.get("")), true);

        properties = new HashMap<>();
        properties.put(NameConstants.JCR_PRIMARYTYPE.toString(),
                new DocViewProperty(NameConstants.JCR_PRIMARYTYPE.toString(), new String[] { JcrConstants.NT_UNSTRUCTURED }, false,
                        PropertyType.UNDEFINED));
        properties.put("{}attribute1", new DocViewProperty("{}attribute1", new String[] { "value1" }, false, PropertyType.UNDEFINED));
        node = new DocViewNode("{}somepath", "somepath", null, properties, null, JcrConstants.NT_UNSTRUCTURED);
        Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps/child1/somepath", Paths.get("apps", "child1.xml"), Paths.get("")), false);

        // verify node names
        Map<String, Integer> expectedNodePathsAndLineNumber = new HashMap<>();
        expectedNodePathsAndLineNumber.put("/apps/child1", 20);
        expectedNodePathsAndLineNumber.put("/apps/child1/somepath", 23);
        Assert.assertEquals(expectedNodePathsAndLineNumber, nodePathsAndLineNumbers);
    }
}
 
Example #28
Source File: DocumentViewParserValidatorTest.java    From jackrabbit-filevault with Apache License 2.0 5 votes vote down vote up
@Test
public void testDocViewDotContentXmlWithRootElementDifferentThanJcrRoot()
        throws ParserConfigurationException, SAXException, URISyntaxException, IOException, NamespaceException {
    try (InputStream input = this.getClass().getResourceAsStream("/simple-package/jcr_root/apps/child2/.content.xml")) {
        Collection<ValidationMessage> messages = validator.validateJcrData(input, Paths.get("apps", "child2", ".content.xml"), Paths.get(""), nodePathsAndLineNumbers);
        Assert.assertThat(messages, AnyValidationViolationMatcher.noValidationInCollection());

        Map<String, DocViewProperty> properties = new HashMap<>();
        properties.put(NameConstants.JCR_PRIMARYTYPE.toString(),
                new DocViewProperty(NameConstants.JCR_PRIMARYTYPE.toString(), new String[] { "sling:Folder" }, false,
                        PropertyType.UNDEFINED));
        DocViewNode node = new DocViewNode("{}child3", "child3", null, properties, null, "sling:Folder");
        Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps/child3", Paths.get("apps", "child2", ".content.xml"), Paths.get("")), true);

        properties = new HashMap<>();
        properties.put(NameConstants.JCR_PRIMARYTYPE.toString(),
                new DocViewProperty(NameConstants.JCR_PRIMARYTYPE.toString(), new String[] { JcrConstants.NT_UNSTRUCTURED }, false,
                        PropertyType.UNDEFINED));
        properties.put("{}attribute1", new DocViewProperty("{}attribute1", new String[] { "value1" }, false, PropertyType.UNDEFINED));
        node = new DocViewNode("{}somepath", "somepath", null, properties, null, JcrConstants.NT_UNSTRUCTURED);
        Mockito.verify(docViewXmlValidator).validate(node, new NodeContextImpl("/apps/child3/somepath", Paths.get("apps", "child2", ".content.xml"), Paths.get("")), false);

        // verify node names
        Map<String, Integer> expectedNodePathsAndLineNumber = new HashMap<>();
        expectedNodePathsAndLineNumber.put("/apps/child3", 20);
        expectedNodePathsAndLineNumber.put("/apps/child3/somepath", 23);
        Assert.assertEquals(expectedNodePathsAndLineNumber, nodePathsAndLineNumbers);
    }
}
 
Example #29
Source File: ContentSessionFactory.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
private NodeTypeTemplate createMyCollabFolderType(NodeTypeManager manager) throws RepositoryException {
    // Create content node type
    NodeTypeTemplate contentTypeTemplate = manager.createNodeTypeTemplate();

    contentTypeTemplate.setAbstract(false);
    contentTypeTemplate.setMixin(false);
    contentTypeTemplate.setName("mycollab:folder");
    contentTypeTemplate.setPrimaryItemName("folder");
    contentTypeTemplate.setDeclaredSuperTypeNames(new String[]{NodeType.NT_FOLDER});
    contentTypeTemplate.setQueryable(true);
    contentTypeTemplate.setOrderableChildNodes(false);

    PropertyDefinitionTemplate createdPropertyTemplate = manager
            .createPropertyDefinitionTemplate();
    createdPropertyTemplate.setMultiple(false);
    createdPropertyTemplate.setName("mycollab:createdUser");
    createdPropertyTemplate.setMandatory(true);
    createdPropertyTemplate.setRequiredType(PropertyType.STRING);
    contentTypeTemplate.getPropertyDefinitionTemplates().add(createdPropertyTemplate);

    PropertyDefinitionTemplate descPropertyTemplate = manager
            .createPropertyDefinitionTemplate();
    descPropertyTemplate.setMultiple(false);
    descPropertyTemplate.setName("jcr:description");
    descPropertyTemplate.setMandatory(false);
    descPropertyTemplate.setRequiredType(PropertyType.STRING);
    contentTypeTemplate.getPropertyDefinitionTemplates().add(descPropertyTemplate);

    return contentTypeTemplate;
}
 
Example #30
Source File: PageSessionFactory.java    From mycollab with GNU Affero General Public License v3.0 5 votes vote down vote up
private NodeTypeTemplate createWikiFolderType(NodeTypeManager manager) throws RepositoryException {
    // Create content node type
    NodeTypeTemplate folderTypeTemplate = manager.createNodeTypeTemplate();

    folderTypeTemplate.setAbstract(false);
    folderTypeTemplate.setMixin(false);
    folderTypeTemplate.setName("wiki:folder");
    folderTypeTemplate.setPrimaryItemName("folder");
    folderTypeTemplate.setDeclaredSuperTypeNames(new String[]{NodeType.NT_FOLDER});
    folderTypeTemplate.setQueryable(true);
    folderTypeTemplate.setOrderableChildNodes(false);

    PropertyDefinitionTemplate createdPropertyTemplate = manager.createPropertyDefinitionTemplate();
    createdPropertyTemplate.setMultiple(false);
    createdPropertyTemplate.setName("wiki:createdUser");
    createdPropertyTemplate.setMandatory(true);
    createdPropertyTemplate.setRequiredType(PropertyType.STRING);
    folderTypeTemplate.getPropertyDefinitionTemplates().add(createdPropertyTemplate);

    PropertyDefinitionTemplate namePropertyTemplate = manager.createPropertyDefinitionTemplate();
    namePropertyTemplate.setMultiple(false);
    namePropertyTemplate.setName("wiki:name");
    namePropertyTemplate.setMandatory(true);
    namePropertyTemplate.setRequiredType(PropertyType.STRING);
    folderTypeTemplate.getPropertyDefinitionTemplates().add(namePropertyTemplate);

    PropertyDefinitionTemplate descPropertyTemplate = manager.createPropertyDefinitionTemplate();
    descPropertyTemplate.setMultiple(false);
    descPropertyTemplate.setName("wiki:description");
    descPropertyTemplate.setMandatory(true);
    descPropertyTemplate.setRequiredType(PropertyType.STRING);
    folderTypeTemplate.getPropertyDefinitionTemplates().add(descPropertyTemplate);
    return folderTypeTemplate;
}