You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by kw...@apache.org on 2019/10/02 11:28:26 UTC

svn commit: r1867884 [4/6] - in /jackrabbit/commons/filevault/trunk: ./ .mvn/ parent/ vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/ vault-core/src/main/java/org/apache/jackrabbit/vault/fs/config/ vault-core/src/main/java/org/apache/jackr...

Added: jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/filevault/validation/spi/impl/PackageTypeValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/filevault/validation/spi/impl/PackageTypeValidator.java?rev=1867884&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/filevault/validation/spi/impl/PackageTypeValidator.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/filevault/validation/spi/impl/PackageTypeValidator.java Wed Oct  2 11:28:25 2019
@@ -0,0 +1,250 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.filevault.validation.spi.impl;
+
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedList;
+import java.util.regex.Pattern;
+
+import javax.annotation.CheckForNull;
+import javax.annotation.Nonnull;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.jackrabbit.filevault.validation.spi.FilterValidator;
+import org.apache.jackrabbit.filevault.validation.spi.MetaInfPathValidator;
+import org.apache.jackrabbit.filevault.validation.spi.NodePathValidator;
+import org.apache.jackrabbit.filevault.validation.spi.PropertiesValidator;
+import org.apache.jackrabbit.filevault.validation.spi.ValidationContext;
+import org.apache.jackrabbit.filevault.validation.spi.ValidationMessage;
+import org.apache.jackrabbit.filevault.validation.spi.ValidationMessageSeverity;
+import org.apache.jackrabbit.vault.fs.api.PathFilterSet;
+import org.apache.jackrabbit.vault.fs.api.WorkspaceFilter;
+import org.apache.jackrabbit.vault.packaging.PackageProperties;
+import org.apache.jackrabbit.vault.packaging.PackageType;
+import org.apache.jackrabbit.vault.util.Constants;
+
+/** Checks if the package type is correctly set for this package
+ * 
+ * @see <a href="https://issues.apache.org/jira/browse/JCRVLT-170">JCRVLT-170</a> */
+public final class PackageTypeValidator implements NodePathValidator, FilterValidator, PropertiesValidator, MetaInfPathValidator {
+
+    protected static final String MESSAGE_FILTER_HAS_INCLUDE_EXCLUDES = "Package of type '%s' is not supposed to contain includes/excludes below any of its filters!";
+    protected static final String MESSAGE_UNSUPPORTED_SUB_PACKAGE_OF_TYPE = "Package of type '%s' must only contain sub packages of type '%s' but found sub package of type '%s'!";
+    protected static final String MESSAGE_UNSUPPORTED_SUB_PACKAGE = "Package of type '%s' is not supposed to contain any sub packages!";
+    protected static final String MESSAGE_DEPENDENCY = "Package of type '%s' must not have package dependencies but found dependencies '%s'!";
+    protected static final String MESSAGE_LEGACY_TYPE = "Package of type '%s' is legacy. Use one of the other types instead!";
+    protected static final String MESSAGE_PACKAGE_HOOKS = "Package of type '%s' must not contain package hooks but has '%s'!";
+    protected static final String MESSAGE_NO_PACKAGE_TYPE_SET = "No package type set, make sure that property 'packageType' is set in the properties.xml!";
+    protected static final String MESSAGE_OSGI_BUNDLE_OR_CONFIG = "Package of type '%s' is not supposed to contain OSGi bundles or configuration but has '%s'!";
+    protected static final String MESSAGE_NO_OSGI_BUNDLE_OR_CONFIG_OR_SUB_PACKAGE = "Package of type '%s' is not supposed to contain anything but OSGi bundles/configurations and sub packages but has '%s'!";
+    protected static final String MESSAGE_APP_CONTENT = "Package of type '%s' is not supposed to contain content inside '/libs' and '/apps' but has '%s'!";
+    protected static final String MESSAGE_NO_APP_CONTENT_FOUND = "Package of type '%s' is not supposed to contain content outside '/libs' and '/apps' but has '%s'!";
+    protected static final String MESSAGE_INDEX_DEFINITIONS = "Package of type '%s' is not supposed to contain Oak index definitions but has 'allowIndexDefinitions' set to true.";
+
+    protected static final Path PATH_HOOKS = Paths.get(Constants.VAULT_DIR, Constants.HOOKS_DIR);
+    private final PackageType type;
+    private final ValidationMessageSeverity severity;
+    private final ValidationMessageSeverity severityForLegacyType;
+    private final Pattern jcrInstallerNodePathRegex;
+    private final ValidationContext containerValidationContext;
+
+    public PackageTypeValidator(@Nonnull ValidationMessageSeverity severity, @Nonnull ValidationMessageSeverity severityForLegacyType,
+            PackageType type, @Nonnull Pattern jcrInstallerNodePathRegex,
+            ValidationContext containerValidationContext) {
+        this.type = type;
+        this.severity = severity;
+        this.severityForLegacyType = severityForLegacyType;
+        this.jcrInstallerNodePathRegex = jcrInstallerNodePathRegex;
+        this.containerValidationContext = containerValidationContext;
+    }
+
+    boolean isOsgiBundleOrConfiguration(String nodePath) {
+        return jcrInstallerNodePathRegex.matcher(nodePath).matches();
+    }
+
+    static boolean isSubPackage(String nodePath) {
+        return (nodePath.endsWith(".zip"));
+    }
+
+    static boolean isAppContent(String nodePath) {
+        return "/apps".equals(nodePath) || nodePath.startsWith("/apps/") || "/libs".equals(nodePath) || nodePath.startsWith("/libs/");
+    }
+
+    @Override
+    public @CheckForNull Collection<ValidationMessage> done() {
+        return null;
+    }
+
+    @Override
+    public @CheckForNull Collection<ValidationMessage> validate(String nodePath) {
+        if (type == null) {
+            return null;
+        }
+        Collection<ValidationMessage> messages = new LinkedList<>();
+        switch (type) {
+        case CONTENT:
+            if (isAppContent(nodePath)) {
+                messages.add(new ValidationMessage(severity, String.format(MESSAGE_APP_CONTENT, type, nodePath)));
+            }
+            if (isOsgiBundleOrConfiguration(nodePath)) {
+                messages.add(new ValidationMessage(severity, String.format(MESSAGE_OSGI_BUNDLE_OR_CONFIG, type, nodePath)));
+            }
+            break;
+        case APPLICATION:
+            if (!isAppContent(nodePath)) {
+                messages.add(new ValidationMessage(severity, String.format(MESSAGE_NO_APP_CONTENT_FOUND, type, nodePath)));
+            }
+            if (isOsgiBundleOrConfiguration(nodePath)) {
+                messages.add(new ValidationMessage(severity, String.format(MESSAGE_OSGI_BUNDLE_OR_CONFIG, type, nodePath)));
+            }
+            // sub packages are detected via validate(Properties) on the sub package
+            break;
+        case CONTAINER:
+            if (!isOsgiBundleOrConfiguration(nodePath) && !isSubPackage(nodePath)) {
+                messages.add(
+                        new ValidationMessage(severity, String.format(MESSAGE_NO_OSGI_BUNDLE_OR_CONFIG_OR_SUB_PACKAGE, type, nodePath)));
+            }
+
+            break;
+        case MIXED:
+            // no validations currently as most relaxed type
+            break;
+        }
+        return messages;
+    }
+
+    @Override
+    public Collection<ValidationMessage> validate(WorkspaceFilter filter) {
+        if (type == null) {
+            return null;
+        }
+        switch (type) {
+        case APPLICATION:
+            if (hasIncludesOrExcludes(filter)) {
+                return Collections.singleton(new ValidationMessage(severity, String.format(MESSAGE_FILTER_HAS_INCLUDE_EXCLUDES, type)));
+            }
+            break;
+        case CONTENT:
+        case CONTAINER:
+        case MIXED:
+            break;
+        }
+        return null;
+    }
+
+    static boolean hasIncludesOrExcludes(WorkspaceFilter filter) {
+        for (PathFilterSet set : filter.getFilterSets()) {
+            if (!set.getEntries().isEmpty()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public Collection<ValidationMessage> validate(PackageProperties properties) {
+        if (properties.getPackageType() == null) {
+            return Collections.singleton(new ValidationMessage(severityForLegacyType, MESSAGE_NO_PACKAGE_TYPE_SET));
+        }
+        Collection<ValidationMessage> messages = new LinkedList<>();
+        // is sub package?
+        if (containerValidationContext != null) {
+            messages.add(new ValidationMessage(ValidationMessageSeverity.DEBUG, "Found sub package"));
+            ValidationMessage message = validateSubPackageType(properties.getPackageType(), containerValidationContext.getPackageType());
+            if (message != null) {
+                messages.add(message);
+            }
+        }
+
+        switch (properties.getPackageType()) {
+        case APPLICATION:
+            // must not contain hooks (this detects external hooks)
+            if (!properties.getExternalHooks().isEmpty()) {
+                messages.add(new ValidationMessage(severity,
+                        String.format(MESSAGE_PACKAGE_HOOKS, properties.getPackageType(), properties.getExternalHooks())));
+            }
+            // must not include oak:index
+            if (OakIndexDefinitionValidatorFactory.areIndexDefinitionsAllowed(properties)) {
+                messages.add(new ValidationMessage(severity, String.format(MESSAGE_INDEX_DEFINITIONS, properties.getPackageType())));
+            }
+            break;
+        case CONTENT:
+            break;
+        case CONTAINER:
+            // no dependencies
+            if (properties.getDependencies() != null && properties.getDependencies().length > 0) {
+                messages.add(new ValidationMessage(severity,
+                        String.format(MESSAGE_DEPENDENCY, properties.getPackageType(), StringUtils.join(properties.getDependencies()))));
+            }
+            break;
+        case MIXED:
+            messages.add(
+                    new ValidationMessage(severityForLegacyType, String.format(MESSAGE_LEGACY_TYPE, properties.getPackageType())));
+            break;
+        }
+        return messages;
+    }
+
+    private ValidationMessage validateSubPackageType(PackageType packageType, PackageType containerPackageType) {
+        ValidationMessage message = null;
+        if (containerPackageType == null) {
+            return null;
+        }
+        switch (containerPackageType) {
+        case APPLICATION:
+            // no sub packages allowed
+            message = new ValidationMessage(severity, String.format(MESSAGE_UNSUPPORTED_SUB_PACKAGE, containerPackageType));
+            break;
+        case CONTENT:
+            if (packageType != PackageType.CONTENT) {
+                message = new ValidationMessage(severity, String.format(MESSAGE_UNSUPPORTED_SUB_PACKAGE_OF_TYPE, containerPackageType,
+                        PackageType.CONTENT.toString(), packageType));
+            }
+            break;
+        case CONTAINER:
+            if (packageType != PackageType.APPLICATION) {
+                message = new ValidationMessage(severity, String.format(MESSAGE_UNSUPPORTED_SUB_PACKAGE_OF_TYPE, containerPackageType,
+                        PackageType.APPLICATION.toString(), packageType));
+            }
+            break;
+        case MIXED:
+            break;
+        }
+        return message;
+    }
+
+    
+    @Override
+    public Collection<ValidationMessage> validateMetaInfPath(Path filePath) {
+        if (type == null) {
+            return null;
+        }
+        switch (type) {
+            case APPLICATION:
+                if (filePath.startsWith(PATH_HOOKS))
+                    // must not contain hooks (this detects internal hooks)
+                    return Collections.singleton(new ValidationMessage(severity, String.format(MESSAGE_PACKAGE_HOOKS, type, filePath)));
+            default:
+                break;
+        }
+        return null;
+    }
+
+}

Added: jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/filevault/validation/spi/impl/PackageTypeValidatorFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/filevault/validation/spi/impl/PackageTypeValidatorFactory.java?rev=1867884&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/filevault/validation/spi/impl/PackageTypeValidatorFactory.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/filevault/validation/spi/impl/PackageTypeValidatorFactory.java Wed Oct  2 11:28:25 2019
@@ -0,0 +1,70 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.filevault.validation.spi.impl;
+
+import java.util.regex.Pattern;
+
+import javax.annotation.CheckForNull;
+
+import org.apache.jackrabbit.filevault.validation.spi.ValidationContext;
+import org.apache.jackrabbit.filevault.validation.spi.ValidationMessageSeverity;
+import org.apache.jackrabbit.filevault.validation.spi.Validator;
+import org.apache.jackrabbit.filevault.validation.spi.ValidatorFactory;
+import org.apache.jackrabbit.filevault.validation.spi.ValidatorSettings;
+import org.kohsuke.MetaInfServices;
+
+@MetaInfServices
+public final class PackageTypeValidatorFactory implements ValidatorFactory {
+
+    /**
+     * The option to specify the regex of the node paths which all OSGi bundles and configuration within packages must match
+     * @see <a href="https://sling.apache.org/documentation/bundles/jcr-installer-provider.html">JCR Installer</a>
+     */
+    public static final String OPTION_JCR_INSTALLER_NODE_PATH_REGEX = "jcrInstallerNodePathRegex";
+
+    public static final Pattern DEFAULT_JCR_INSTALLER_NODE_PATH_REGEX = Pattern.compile("/([^/]*/){0,4}?(install|config)(\\.[^/]*)*/(\\d{1,3}/)?.+?\\.(jar|config|cfg|cfg\\.json|xml)$");
+
+    @Override
+    public @CheckForNull Validator createValidator(ValidationContext context, ValidatorSettings settings) {
+        // evaluate options
+        final Pattern jcrInstallerNodePathRegex;
+        if (settings.getOptions().containsKey(OPTION_JCR_INSTALLER_NODE_PATH_REGEX)) {
+            String optionValue = settings.getOptions().get(OPTION_JCR_INSTALLER_NODE_PATH_REGEX);
+            jcrInstallerNodePathRegex = Pattern.compile(optionValue);
+        } else {
+            jcrInstallerNodePathRegex = DEFAULT_JCR_INSTALLER_NODE_PATH_REGEX;
+        }
+        return new PackageTypeValidator(settings.getDefaultSeverity(), ValidationMessageSeverity.WARN, context.getProperties().getPackageType(), jcrInstallerNodePathRegex, context.getContainerValidationContext());
+    }
+
+    @Override
+    public boolean shouldValidateSubpackages() {
+        return true; // sub packages also have constraints derived from the application type of the container package
+    }
+
+    @Override
+    public String getId() {
+        return ValidatorFactory.PREFIX_JACKRABBIT + "packagetype";
+    }
+
+    @Override
+    public int getServiceRanking() {
+        return 0;
+    }
+
+    
+}

Added: jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/filevault/validation/spi/impl/PrimaryNodeTypeValidator.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/filevault/validation/spi/impl/PrimaryNodeTypeValidator.java?rev=1867884&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/filevault/validation/spi/impl/PrimaryNodeTypeValidator.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/filevault/validation/spi/impl/PrimaryNodeTypeValidator.java Wed Oct  2 11:28:25 2019
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.filevault.validation.spi.impl;
+
+import java.nio.file.Path;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.jackrabbit.filevault.validation.spi.DocumentViewXmlValidator;
+import org.apache.jackrabbit.filevault.validation.spi.ValidationMessage;
+import org.apache.jackrabbit.filevault.validation.spi.ValidationMessageSeverity;
+import org.apache.jackrabbit.vault.fs.api.WorkspaceFilter;
+import org.apache.jackrabbit.vault.util.DocViewNode;
+
+/**
+ * Makes sure that each node in a docview file containing at least one other property defines the primary type
+ */
+public class PrimaryNodeTypeValidator implements DocumentViewXmlValidator {
+
+    protected static final String MESSAGE_MISSING_PRIMARY_TYPE = "Mandatory jcr:primaryType missing on node '%s'";
+    private final ValidationMessageSeverity severity;
+    private final WorkspaceFilter filter;
+
+    public PrimaryNodeTypeValidator(ValidationMessageSeverity severity, WorkspaceFilter filter) {
+        super();
+        this.severity = severity;
+        this.filter = filter;
+    }
+
+    @Override
+    public Collection<ValidationMessage> done() {
+        return null;
+    }
+
+    @Override
+    public Collection<ValidationMessage> validate(DocViewNode node, String nodePath, Path filePath, boolean isRoot) {
+        if (node.primary == null) {
+            // only an issue if contained in the filter
+            // if other properties are set this node is not only used for ordering purposes
+            if (filter.contains(nodePath) && !node.props.isEmpty()) {
+                return Collections.singleton(new ValidationMessage(severity,  String.format(MESSAGE_MISSING_PRIMARY_TYPE, nodePath)));
+            }
+        }
+        return null;
+    }
+
+}

Added: jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/filevault/validation/spi/impl/PrimaryNodeTypeValidatorFactory.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/filevault/validation/spi/impl/PrimaryNodeTypeValidatorFactory.java?rev=1867884&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/filevault/validation/spi/impl/PrimaryNodeTypeValidatorFactory.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/filevault/validation/spi/impl/PrimaryNodeTypeValidatorFactory.java Wed Oct  2 11:28:25 2019
@@ -0,0 +1,51 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.filevault.validation.spi.impl;
+
+import javax.annotation.CheckForNull;
+
+import org.apache.jackrabbit.filevault.validation.spi.ValidationContext;
+import org.apache.jackrabbit.filevault.validation.spi.Validator;
+import org.apache.jackrabbit.filevault.validation.spi.ValidatorFactory;
+import org.apache.jackrabbit.filevault.validation.spi.ValidatorSettings;
+import org.kohsuke.MetaInfServices;
+
+@MetaInfServices
+public final class PrimaryNodeTypeValidatorFactory implements ValidatorFactory {
+
+    @Override
+    public @CheckForNull Validator createValidator(ValidationContext context, ValidatorSettings settings) {
+        return new PrimaryNodeTypeValidator(settings.getDefaultSeverity(), context.getFilter());
+    }
+
+    @Override
+    public boolean shouldValidateSubpackages() {
+        return false;
+    }
+
+    @Override
+    public String getId() {
+        return ValidatorFactory.PREFIX_JACKRABBIT + "primarynodetype";
+    }
+
+    @Override
+    public int getServiceRanking() {
+        return 0;
+    }
+
+    
+}

Copied: jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/filevault/validation/spi/package-info.java (from r1867026, jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/package-info.java)
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/filevault/validation/spi/package-info.java?p2=jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/filevault/validation/spi/package-info.java&p1=jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/package-info.java&r1=1867026&r2=1867884&rev=1867884&view=diff
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-core/src/main/java/org/apache/jackrabbit/vault/fs/api/package-info.java (original)
+++ jackrabbit/commons/filevault/trunk/vault-validation/src/main/java/org/apache/jackrabbit/filevault/validation/spi/package-info.java Wed Oct  2 11:28:25 2019
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-@Version("2.6.1")
-package org.apache.jackrabbit.vault.fs.api;
+@Version("1.0.0")
+package org.apache.jackrabbit.filevault.validation.spi;
 
 import org.osgi.annotation.versioning.Version;
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-validation/src/main/resources/filter.xsd
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-validation/src/main/resources/filter.xsd?rev=1867884&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-validation/src/main/resources/filter.xsd (added)
+++ jackrabbit/commons/filevault/trunk/vault-validation/src/main/resources/filter.xsd Wed Oct  2 11:28:25 2019
@@ -0,0 +1,60 @@
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one or more
+  contributor license agreements.  See the NOTICE file distributed with
+  this work for additional information regarding copyright ownership.
+  The ASF licenses this file to You under the Apache License, Version 2.0
+  (the "License"); you may not use this file except in compliance with
+  the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+  -->
+<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
+  <xs:complexType name="includeExcludeType">
+    <xs:simpleContent>
+      <xs:extension base="xs:string">
+        <xs:attribute type="xs:string" name="pattern" use="required"/>
+        <xs:attribute type="xs:boolean" name="matchProperties" />
+      </xs:extension>
+    </xs:simpleContent>
+  </xs:complexType>
+  <xs:attribute name="type">
+    <xs:simpleType>
+        <xs:restriction base="xs:string">
+            <xs:pattern value="(|cleanup)"/>
+        </xs:restriction>
+    </xs:simpleType>
+  </xs:attribute>
+  <xs:attribute name="mode">
+    <xs:simpleType>
+        <xs:restriction base="xs:string">
+          <xs:enumeration value="replace"/>
+          <xs:enumeration value="merge"/>
+          <xs:enumeration value="update"/>
+        </xs:restriction>
+    </xs:simpleType>
+  </xs:attribute>
+  <xs:element name="workspaceFilter">
+    <xs:complexType>
+      <xs:sequence minOccurs="0" maxOccurs="unbounded">
+        <xs:element name="filter">
+          <xs:complexType>
+            <xs:choice maxOccurs="unbounded" minOccurs="0">
+              <xs:element type="includeExcludeType" name="exclude"/>
+              <xs:element type="includeExcludeType" name="include"/>
+            </xs:choice>
+            <xs:attribute type="xs:string" name="root" use="required"/>
+            <xs:attribute ref="type"/>
+            <xs:attribute type="xs:string" name="mode"/>
+          </xs:complexType>
+        </xs:element>
+      </xs:sequence>
+      <xs:attribute type="xs:float" name="version"/>
+    </xs:complexType>
+  </xs:element>
+</xs:schema>
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/AnyValidationMessageMatcher.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/AnyValidationMessageMatcher.java?rev=1867884&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/AnyValidationMessageMatcher.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/AnyValidationMessageMatcher.java Wed Oct  2 11:28:25 2019
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.filevault.validation;
+
+import org.apache.jackrabbit.filevault.validation.spi.ValidationMessage;
+import org.apache.jackrabbit.filevault.validation.spi.ValidationMessageSeverity;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.Matchers;
+import org.hamcrest.TypeSafeMatcher;
+
+public class AnyValidationMessageMatcher extends TypeSafeMatcher<ValidationMessage> {
+
+    @Override
+    public void describeTo(Description description) {
+        description.appendText("ValidationMessage with severity ERROR or WARN");
+    }
+
+    @Override
+    protected boolean matchesSafely(ValidationMessage item) {
+        if (item.getSeverity().ordinal() >= ValidationMessageSeverity.WARN.ordinal()) {
+            return true;
+        }
+        return false;
+    }
+    
+    public static Matcher<Iterable<? super ValidationMessage>> noValidationInCollection() {
+        return Matchers.not(Matchers.hasItem(new AnyValidationMessageMatcher()));
+    }
+}

Added: jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/AnyValidationViolationMatcher.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/AnyValidationViolationMatcher.java?rev=1867884&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/AnyValidationViolationMatcher.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/AnyValidationViolationMatcher.java Wed Oct  2 11:28:25 2019
@@ -0,0 +1,43 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.filevault.validation;
+
+import org.apache.jackrabbit.filevault.validation.spi.ValidationMessageSeverity;
+import org.hamcrest.Description;
+import org.hamcrest.Matcher;
+import org.hamcrest.Matchers;
+import org.hamcrest.TypeSafeMatcher;
+
+public class AnyValidationViolationMatcher extends TypeSafeMatcher<ValidationViolation> {
+
+    @Override
+    public void describeTo(Description description) {
+        description.appendText("ValidationMessage with severity ERROR or WARN");
+    }
+
+    @Override
+    protected boolean matchesSafely(ValidationViolation item) {
+        if (item.getSeverity().ordinal() >= ValidationMessageSeverity.WARN.ordinal()) {
+            return true;
+        }
+        return false;
+    }
+    
+    public static Matcher<Iterable<? super ValidationViolation>> noValidationInCollection() {
+        return Matchers.not(Matchers.hasItem(new AnyValidationViolationMatcher()));
+    }
+}

Added: jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/CapturingInputStreamFromArgumentAnswer.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/CapturingInputStreamFromArgumentAnswer.java?rev=1867884&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/CapturingInputStreamFromArgumentAnswer.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/CapturingInputStreamFromArgumentAnswer.java Wed Oct  2 11:28:25 2019
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.filevault.validation;
+
+import java.io.InputStream;
+import java.nio.charset.Charset;
+
+import org.apache.commons.io.IOUtils;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+/** Captures an input stream from the argument with the given index and exposes that via
+ * {@link CapturingInputStreamFromArgumentAnswer#getValue()} as String.
+ * In addition returns the given value.
+ * It does not close the given input stream nor reset it.
+ *
+ * @param <T> */
+public final class CapturingInputStreamFromArgumentAnswer<T> implements Answer<T> {
+    private String value;
+    private final int argumentPositionOfInputStream;
+    private final Charset encoding;
+    private final T returnValue;
+
+    public CapturingInputStreamFromArgumentAnswer(Charset encoding, int argumentPositionOfInputStream, T returnValue) {
+        this.encoding = encoding;
+        this.argumentPositionOfInputStream = argumentPositionOfInputStream;
+        this.returnValue = returnValue;
+    }
+
+    @Override
+    public T answer(InvocationOnMock invocation) throws Throwable {
+        InputStream input = InputStream.class.cast(invocation.getArguments()[argumentPositionOfInputStream]);
+        value = IOUtils.toString(input, encoding);
+        return returnValue;
+    }
+
+    public String getValue() {
+        return value;
+    }
+}
\ No newline at end of file

Added: jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/DocumentViewParserValidatorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/DocumentViewParserValidatorTest.java?rev=1867884&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/DocumentViewParserValidatorTest.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/DocumentViewParserValidatorTest.java Wed Oct  2 11:28:25 2019
@@ -0,0 +1,202 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.filevault.validation;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.nio.file.Paths;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.jcr.NamespaceException;
+import javax.jcr.PropertyType;
+import javax.xml.XMLConstants;
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.parsers.SAXParserFactory;
+
+import org.apache.jackrabbit.filevault.validation.impl.util.DocumentViewXmlContentHandler;
+import org.apache.jackrabbit.filevault.validation.spi.DocumentViewXmlValidator;
+import org.apache.jackrabbit.filevault.validation.spi.ValidationMessage;
+import org.apache.jackrabbit.filevault.validation.spi.ValidationMessageSeverity;
+import org.apache.jackrabbit.filevault.validation.spi.impl.DocumentViewParserValidator;
+import org.apache.jackrabbit.spi.commons.name.NameConstants;
+import org.apache.jackrabbit.vault.util.DocViewNode;
+import org.apache.jackrabbit.vault.util.DocViewProperty;
+import org.apache.jackrabbit.vault.util.JcrConstants;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.xml.sax.SAXException;
+
+@RunWith(MockitoJUnitRunner.class)
+public class DocumentViewParserValidatorTest {
+
+    private DocumentViewParserValidator validator;
+    private Map<String, Integer> nodePathsAndLineNumbers;
+
+    @Mock
+    private DocumentViewXmlValidator docViewXmlValidator;
+
+    @Before
+    public void setUp() throws ParserConfigurationException, SAXException {
+        SAXParserFactory spf = SAXParserFactory.newInstance();
+        spf.setNamespaceAware(true);
+        spf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
+        validator = new DocumentViewParserValidator(spf.newSAXParser(), ValidationMessageSeverity.ERROR);
+        nodePathsAndLineNumbers = new HashMap<>();
+        validator.setDocumentViewXmlValidators(Collections.singletonMap("docviewid", docViewXmlValidator));
+    }
+
+    @Test
+    public void testShouldValidate() {
+        Assert.assertTrue(validator.shouldValidateJcrData(Paths.get("some", "file.xml")));
+        Assert.assertFalse(validator.shouldValidateJcrData(Paths.get("some", "other", "file.json")));
+    }
+
+    @Test
+    public void testDocViewDotContentXml()
+            throws ParserConfigurationException, SAXException, URISyntaxException, IOException, NamespaceException {
+        Mockito.when(docViewXmlValidator.validate(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.anyBoolean())).thenReturn(Collections.singleton(new ValidationMessage(ValidationMessageSeverity.ERROR, "startDocView")));
+        try (InputStream input = this.getClass().getResourceAsStream("/simple-package/jcr_root/apps/.content.xml")) {
+            Collection<ValidationMessage> messages = validator.validateJcrData(input, Paths.get("apps", ".content.xml"), nodePathsAndLineNumbers);
+            // filter
+            ValidationExecutorTest.assertViolation(messages,
+                    new ValidationViolation("docviewid", ValidationMessageSeverity.ERROR, "startDocView", Paths.get("apps/.content.xml"), Paths.get(""), "/apps", 19, 36, null
+                            ),
+                    new ValidationViolation("docviewid", ValidationMessageSeverity.ERROR,
+                            "startDocView", Paths.get("apps/.content.xml"), Paths.get(""), "/apps/somepath", 22, 6, null));
+
+            // verify node names
+            Map<String, Integer> expectedNodePathsAndLineNumber = new HashMap<>();
+            expectedNodePathsAndLineNumber.put("/apps", 19);
+            expectedNodePathsAndLineNumber.put("/apps/somepath", 22);
+            Assert.assertEquals(expectedNodePathsAndLineNumber, nodePathsAndLineNumbers);
+            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("apps", "apps", null, properties, null, "sling:Folder");
+            Mockito.verify(docViewXmlValidator).validate(node, "/apps", Paths.get("apps", ".content.xml"), 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, "/apps/somepath", Paths.get("apps", ".content.xml"), false);
+        }
+    }
+
+    @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"), 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", "child1", null, properties, null, "sling:Folder");
+            Mockito.verify(docViewXmlValidator).validate(node, "/apps/child1", Paths.get("apps", "child1.xml"), 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, "/apps/child1/somepath", Paths.get("apps", "child1.xml"), 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);
+        }
+    }
+
+    @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"), 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, "/apps/child3", Paths.get("apps", "child2", ".content.xml"), 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, "/apps/child3/somepath", Paths.get("apps", "child2", ".content.xml"), 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);
+        }
+    }
+
+    @Test
+    public void testDocViewWithRegularFileNameWithRootElementDifferentThanJcrRoot() throws IOException {
+        // https://issues.apache.org/jira/browse/JCRVLT-358"
+        try (InputStream input = this.getClass().getResourceAsStream("/simple-package/jcr_root/apps/child2/child1.xml")) {
+            Collection<ValidationMessage> messages = validator.validateJcrData(input, Paths.get("apps", "child2", "child1.xml"), nodePathsAndLineNumbers);
+            Assert.assertThat(messages, AnyValidationMessageMatcher.noValidationInCollection());
+
+            Mockito.verifyZeroInteractions(docViewXmlValidator);
+
+            // verify node names
+            Map<String, Integer> expectedNodePathsAndLineNumber = new HashMap<>();
+            expectedNodePathsAndLineNumber.put("/apps/child2/child1.xml", 0);
+            Assert.assertEquals(expectedNodePathsAndLineNumber, nodePathsAndLineNumbers);
+        }
+    }
+
+    @Test
+    public void testDocViewWithInvalidType() throws ParserConfigurationException, SAXException, URISyntaxException, IOException {
+        try (InputStream input = this.getClass().getResourceAsStream("/simple-package/jcr_root/apps/invalid/wrongtype.xml")) {
+            Collection<ValidationMessage> messages = validator.validateJcrData(input, Paths.get("apps", "invalid","wrongtype.xml"), nodePathsAndLineNumbers);
+
+           ValidationExecutorTest.assertViolation(messages,
+                    new ValidationViolation(ValidationMessageSeverity.ERROR,
+                            String.format(DocumentViewXmlContentHandler.PARSE_VIOLATION_MESSAGE_STRING, "somepath",
+                                    "unknown type: Invalid"), Paths.get("apps/invalid/wrongtype.xml"), Paths.get(""), "/apps/invalid/wrongtype/somepath", 24, 6,
+                            new IllegalArgumentException("unknown type: Invalid")));
+        }
+    }
+
+}

Added: jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/ValidationExecutorFactoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/ValidationExecutorFactoryTest.java?rev=1867884&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/ValidationExecutorFactoryTest.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/ValidationExecutorFactoryTest.java Wed Oct  2 11:28:25 2019
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.filevault.validation;
+
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.jackrabbit.filevault.validation.impl.util.ValidatorSettingsImpl;
+import org.apache.jackrabbit.filevault.validation.spi.ValidationContext;
+import org.apache.jackrabbit.filevault.validation.spi.ValidationMessageSeverity;
+import org.apache.jackrabbit.filevault.validation.spi.Validator;
+import org.apache.jackrabbit.filevault.validation.spi.ValidatorFactory;
+import org.apache.jackrabbit.filevault.validation.spi.ValidatorSettings;
+import org.hamcrest.Matchers;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.xml.sax.SAXException;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ValidationExecutorFactoryTest {
+
+    private ValidationExecutorFactory executorFactory;
+
+    @Mock
+    private Validator validator1;
+    @Mock
+    private Validator validator2;
+    @Mock
+    private Validator validator3;
+    @Mock
+    private ValidatorFactory validatorFactory1;
+    @Mock
+    private ValidatorFactory validatorFactory2;
+    @Mock
+    private ValidatorFactory validatorFactory3;
+    @Mock
+    private ValidationContext context;
+    
+    private Map<String, ValidatorSettings> validatorsSettings;
+    List<ValidatorFactory> validatorFactories;
+
+    @Before
+    public void setUp() {
+        validatorFactories = new LinkedList<>();
+        Mockito.when(validatorFactory1.getId()).thenReturn("id1");
+        Mockito.when(validatorFactory1.getServiceRanking()).thenReturn(3);
+        Mockito.when(validatorFactory1.createValidator(Mockito.any(ValidationContext.class), Mockito.any())).thenReturn(validator1);
+        validatorFactories.add(validatorFactory1);
+        Mockito.when(validatorFactory2.getId()).thenReturn("id2");
+        Mockito.when(validatorFactory2.getServiceRanking()).thenReturn(2);
+        Mockito.when(validatorFactory2.createValidator(Mockito.any(ValidationContext.class), Mockito.any())).thenReturn(validator2);
+        validatorFactories.add(validatorFactory2);
+        Mockito.when(validatorFactory3.getId()).thenReturn("id3");
+        Mockito.when(validatorFactory3.getServiceRanking()).thenReturn(0);
+        Mockito.when(validatorFactory3.createValidator(Mockito.any(ValidationContext.class), Mockito.any())).thenReturn(validator3);
+        validatorFactories.add(validatorFactory3);
+       
+        executorFactory = new ValidationExecutorFactory(validatorFactories);
+        validatorsSettings = new HashMap<>();
+    }
+
+    @Test
+    public void testOrderOfValidators() throws ParserConfigurationException, SAXException {
+        // first validate order
+        ValidationExecutor executor =  executorFactory.createValidationExecutor(context, true, true, validatorsSettings);
+        Map<String, Validator> actualValidators = executor.getAllValidatorsById();
+        Map<String, Validator> expectedValidators = new LinkedHashMap<>();
+        expectedValidators.put("id1", validator1);
+        expectedValidators.put("id2", validator2);
+        expectedValidators.put("id3", validator3);
+        Assert.assertEquals(expectedValidators.toString(), actualValidators.toString());
+        Assert.assertThat(actualValidators.keySet(), Matchers.contains("id1", "id2", "id3"));
+        // the reinstantiate with a different order
+        Collections.shuffle(validatorFactories);
+        executorFactory = new ValidationExecutorFactory(validatorFactories);
+        executor =  executorFactory.createValidationExecutor(context, true, true, validatorsSettings);
+        actualValidators = executor.getAllValidatorsById();
+        // the returned validators should still have the same order
+        Assert.assertEquals(expectedValidators.toString(), actualValidators.toString());
+        Assert.assertThat(actualValidators.keySet(), Matchers.contains("id1", "id2", "id3"));
+    }
+
+    @Test
+    public void testOrderOfValidatorFactories()  {
+        Assert.assertThat(executorFactory.validatorFactories, Matchers.contains(validatorFactory1, validatorFactory2, validatorFactory3));
+        Collections.shuffle(validatorFactories);
+        executorFactory = new ValidationExecutorFactory(validatorFactories);
+        Assert.assertThat(executorFactory.validatorFactories, Matchers.contains(validatorFactory1, validatorFactory2, validatorFactory3));
+    }
+
+    @Test
+    public void testOrderOfValidatorsWithSameRanking() {
+        Mockito.when(validatorFactory2.getServiceRanking()).thenReturn(3);
+        Mockito.when(validatorFactory3.getServiceRanking()).thenReturn(3);
+        executorFactory = new ValidationExecutorFactory(validatorFactories);
+        Assert.assertThat(executorFactory.validatorFactories, Matchers.containsInAnyOrder(validatorFactory1, validatorFactory2, validatorFactory3));
+    }
+
+    @Test
+    public void testValidatorSettings() throws ParserConfigurationException, SAXException {
+        ValidatorSettings settings1 = new ValidatorSettingsImpl("option1", "value1");
+        validatorsSettings.put("id1", settings1);
+        ValidatorSettings settings2 = new ValidatorSettingsImpl(true);
+        validatorsSettings.put("id2", settings2);
+        ValidatorSettings settings3 = new ValidatorSettingsImpl(ValidationMessageSeverity.INFO);
+        validatorsSettings.put("id3", settings3);
+        executorFactory.createValidationExecutor(context, true, true, validatorsSettings);
+        Mockito.verify(validatorFactory1).createValidator(context, settings1);
+        Mockito.verify(validatorFactory2, Mockito.never()).createValidator(Mockito.any(), Mockito.any());
+        Mockito.verify(validatorFactory3).createValidator(context, settings3);
+    }
+}

Added: jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/ValidationExecutorTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/ValidationExecutorTest.java?rev=1867884&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/ValidationExecutorTest.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/ValidationExecutorTest.java Wed Oct  2 11:28:25 2019
@@ -0,0 +1,227 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.filevault.validation;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.apache.jackrabbit.filevault.validation.spi.DocumentViewXmlValidator;
+import org.apache.jackrabbit.filevault.validation.spi.GenericJcrDataValidator;
+import org.apache.jackrabbit.filevault.validation.spi.GenericMetaInfDataValidator;
+import org.apache.jackrabbit.filevault.validation.spi.JcrPathValidator;
+import org.apache.jackrabbit.filevault.validation.spi.MetaInfPathValidator;
+import org.apache.jackrabbit.filevault.validation.spi.NodePathValidator;
+import org.apache.jackrabbit.filevault.validation.spi.PropertiesValidator;
+import org.apache.jackrabbit.filevault.validation.spi.ValidationContext;
+import org.apache.jackrabbit.filevault.validation.spi.ValidationMessage;
+import org.apache.jackrabbit.filevault.validation.spi.ValidationMessageSeverity;
+import org.apache.jackrabbit.filevault.validation.spi.Validator;
+import org.apache.jackrabbit.vault.fs.config.ConfigurationException;
+import org.hamcrest.Matchers;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.xml.sax.SAXException;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ValidationExecutorTest {
+
+    @Mock
+    private DocumentViewXmlValidator docViewXmlValidator;
+    @Mock
+    private PropertiesValidator propertiesValidator;
+    @Mock
+    private NodePathValidator nodePathValidator;
+    @Mock
+    private GenericJcrDataValidator genericJcrDataValidator;
+    @Mock
+    private GenericJcrDataValidator genericJcrDataValidator2;
+    @Mock
+    private GenericMetaInfDataValidator genericMetaInfDataValidator;
+    @Mock
+    private GenericMetaInfDataValidator genericMetaInfDataValidator2;
+    @Mock
+    private JcrPathValidator jcrPathValidator;
+    @Mock
+    private MetaInfPathValidator metaInfPathValidator;
+    @Mock
+    private Validator unusedValidator;
+    @Mock
+    private ValidationContext context;
+    
+    private ValidationExecutor executor;
+
+    @Before
+    public void setUp() throws ParserConfigurationException, SAXException {
+        Map<String, Validator> validators = new LinkedHashMap<>();
+        validators.put("docviewid", docViewXmlValidator);
+        validators.put("propertiesid", propertiesValidator);
+        validators.put("genericmetadataid", genericMetaInfDataValidator);
+        validators.put("genericmetadataid2", genericMetaInfDataValidator2);
+        validators.put("genericjcrdataid", genericJcrDataValidator);
+        validators.put("genericjcrdataid2", genericJcrDataValidator2);
+        validators.put("jcrpathid", jcrPathValidator);
+        validators.put("metainfpathid", metaInfPathValidator);
+        validators.put("nodepathid", nodePathValidator);
+        validators.put("unusedid", unusedValidator);
+        executor = new ValidationExecutor(validators);
+    }
+
+    @Test
+    public void testUnusedValidators() throws ParserConfigurationException, SAXException {
+        Assert.assertThat(executor.getUnusedValidatorsById(), Matchers.hasEntry("unusedid", unusedValidator));
+        Assert.assertThat(executor.getUnusedValidatorsById(), Matchers.aMapWithSize(1));
+    }
+
+    @Test
+    public void testValidateNodePath() throws ParserConfigurationException, SAXException, IOException, URISyntaxException {
+        Mockito.when(nodePathValidator.validate("/apps/invalid/wrongtype.xml")).thenReturn(Collections.singletonList(new ValidationMessage(ValidationMessageSeverity.ERROR, "Invalid node path")));
+        try (InputStream input = this.getClass().getResourceAsStream("/simple-package/jcr_root/apps/invalid/wrongtype.xml")) {
+            Collection<ValidationViolation> messages = validate(input, executor, Paths.get(""), "apps/invalid/wrongtype.xml", false);
+
+            ValidationExecutorTest.assertViolation(messages,
+                    new ValidationViolation("nodepathid", ValidationMessageSeverity.ERROR, "Invalid node path", Paths.get("apps/invalid/wrongtype.xml"), Paths.get(""), "/apps/invalid/wrongtype.xml", 0, 0, null));
+        }
+    }
+
+    @Test
+    public void testGenericMetaInfData()
+            throws URISyntaxException, IOException, SAXException, ParserConfigurationException, ConfigurationException {
+        Mockito.when(genericMetaInfDataValidator.shouldValidateMetaInfData(Mockito.any())).thenReturn(true);
+        Mockito.when(genericMetaInfDataValidator2.shouldValidateMetaInfData(Mockito.any())).thenReturn(true);
+        CapturingInputStreamFromArgumentAnswer<Void> answer = new CapturingInputStreamFromArgumentAnswer<>(StandardCharsets.US_ASCII, 0, null);
+        Mockito.when(genericMetaInfDataValidator.validateMetaInfData(Mockito.any(), Mockito.any())).thenAnswer(answer);
+        CapturingInputStreamFromArgumentAnswer<Collection<ValidationMessage>> answer2 = new CapturingInputStreamFromArgumentAnswer<>(StandardCharsets.US_ASCII, 0, Collections.singleton(new ValidationMessage(ValidationMessageSeverity.WARN, "error1")));
+        Mockito.when(genericMetaInfDataValidator2.validateMetaInfData(Mockito.any(), Mockito.any())).thenAnswer(answer2);
+        Mockito.when(metaInfPathValidator.validateMetaInfPath(Mockito.any())).thenReturn(Collections.singleton(new ValidationMessage(ValidationMessageSeverity.ERROR, "patherror")));
+        try (InputStream input = this.getClass().getResourceAsStream("/simple-package/META-INF/vault/genericfile.txt")) {
+            Collection<ValidationViolation> messages = validate(input, executor, Paths.get(""), "vault/genericfile.txt", true);
+            assertViolation(messages, 
+                    new ValidationViolation("metainfpathid", ValidationMessageSeverity.ERROR, "patherror", Paths.get("vault","genericfile.txt"), Paths.get(""), null, 0, 0, null),
+                    new ValidationViolation("genericmetadataid2", ValidationMessageSeverity.WARN, "error1", Paths.get("vault","genericfile.txt"), Paths.get(""), null, 0, 0, null));
+            Assert.assertEquals("Test", answer.getValue());
+            Assert.assertEquals("Test", answer2.getValue());
+            Path expectedPath = Paths.get("vault/genericfile.txt");
+            Mockito.verify(metaInfPathValidator).validateMetaInfPath(expectedPath);
+            Mockito.verify(genericMetaInfDataValidator, Mockito.atLeastOnce()).shouldValidateMetaInfData(expectedPath);
+            Mockito.verify(genericMetaInfDataValidator).validateMetaInfData(Mockito.any(), Mockito.eq(expectedPath));
+            Mockito.verify(genericMetaInfDataValidator2, Mockito.atLeastOnce()).shouldValidateMetaInfData(expectedPath);
+            Mockito.verify(genericMetaInfDataValidator2).validateMetaInfData(Mockito.any(), Mockito.eq(expectedPath));
+        }
+    }
+
+    @Test
+    public void testGenericMetaInfDataWithNotInterestedValidator()
+            throws URISyntaxException, IOException, SAXException, ParserConfigurationException, ConfigurationException {
+        try (InputStream input = this.getClass().getResourceAsStream("/simple-package/META-INF/vault/genericfile.txt")) {
+            Collection<ValidationViolation> messages = validate(input, executor, Paths.get(""), "vault/genericfile.txt", true);
+            Assert.assertThat(messages, AnyValidationViolationMatcher.noValidationInCollection());
+            Mockito.verify(genericMetaInfDataValidator, Mockito.never()).validateMetaInfData(Mockito.any(), Mockito.any());
+        }
+    }
+
+    @Test
+    public void testGenericJcrData()
+            throws URISyntaxException, IOException, SAXException, ParserConfigurationException, ConfigurationException {
+        Mockito.when(genericJcrDataValidator.shouldValidateJcrData(Mockito.any())).thenReturn(true);
+        CapturingInputStreamFromArgumentAnswer<Collection<ValidationMessage>> answer = new CapturingInputStreamFromArgumentAnswer<>(StandardCharsets.US_ASCII, 0, Collections.singleton(new ValidationMessage(ValidationMessageSeverity.WARN, "error1")));
+        Mockito.when(genericJcrDataValidator.validateJcrData(Mockito.any(), Mockito.any(), Mockito.any())).thenAnswer(answer);
+        CapturingInputStreamFromArgumentAnswer<Void> answer2 = new CapturingInputStreamFromArgumentAnswer<>(StandardCharsets.US_ASCII, 0, null);
+        Mockito.when(genericJcrDataValidator2.shouldValidateJcrData(Mockito.any())).thenReturn(true);
+        Mockito.when(genericJcrDataValidator2.validateJcrData(Mockito.any(), Mockito.any(), Mockito.any())).thenAnswer(answer2);
+        Mockito.when(jcrPathValidator.validateJcrPath(Mockito.any())).thenReturn(Collections.singleton(new ValidationMessage(ValidationMessageSeverity.ERROR, "patherror")));
+        try (InputStream input = this.getClass().getResourceAsStream("/simple-package/jcr_root/apps/genericfile.xml")) {
+            Collection<ValidationViolation> messages = validate(input, executor, Paths.get(""), "apps/genericfile.xml", false);
+            assertViolation(messages, 
+                    new ValidationViolation("jcrpathid", ValidationMessageSeverity.ERROR, "patherror", Paths.get("apps","genericfile.xml"), Paths.get(""), null, 0, 0, null),
+                    new ValidationViolation("genericjcrdataid", ValidationMessageSeverity.WARN, "error1", Paths.get("apps","genericfile.xml"), Paths.get(""), null, 0, 0, null));
+            Assert.assertEquals("Test", answer.getValue());
+            Assert.assertEquals("Test", answer2.getValue());
+            Path expectedPath = Paths.get("apps/genericfile.xml");
+            Mockito.verify(jcrPathValidator).validateJcrPath(expectedPath);
+            Mockito.verify(genericJcrDataValidator, Mockito.atLeastOnce()).shouldValidateJcrData(expectedPath);
+            Mockito.verify(genericJcrDataValidator).validateJcrData(Mockito.any(), Mockito.eq(expectedPath), Mockito.any());
+            Mockito.verify(genericJcrDataValidator2, Mockito.atLeastOnce()).shouldValidateJcrData(expectedPath);
+            Mockito.verify(genericJcrDataValidator2).validateJcrData(Mockito.any(), Mockito.eq(expectedPath), Mockito.any());
+        }
+    }
+
+    @Test
+    public void testGenericJcrDataWithNotInterestedValidator()
+            throws URISyntaxException, IOException, SAXException, ParserConfigurationException, ConfigurationException {
+        try (InputStream input = this.getClass().getResourceAsStream("/simple-package/jcr_root/apps/genericfile.xml")) {
+            Collection<ValidationViolation> messages = validate(input, executor, Paths.get(""), "apps/genericfile.xml", false);
+            Assert.assertThat(messages, AnyValidationViolationMatcher.noValidationInCollection());
+            Mockito.verify(genericJcrDataValidator, Mockito.never()).validateJcrData(Mockito.any(), Mockito.any(), Mockito.any());
+        }
+    }
+
+    @Test
+    public void testDone() {
+        Mockito.when(genericJcrDataValidator.done()).thenReturn(Collections.singleton(new ValidationMessage(ValidationMessageSeverity.ERROR, "test1")));
+        Mockito.when(genericJcrDataValidator2.done()).thenReturn(Collections.singleton(new ValidationMessage(ValidationMessageSeverity.WARN, "test2")));
+        
+        assertViolation(executor.done(), new ValidationViolation("genericjcrdataid", ValidationMessageSeverity.ERROR, "test1"), new ValidationViolation("genericjcrdataid2", ValidationMessageSeverity.WARN, "test2")); 
+    }
+
+    private Collection<ValidationViolation> validate(InputStream input, ValidationExecutor executor, Path basePath, String resourcePath,
+            boolean isMetaInf) throws URISyntaxException, IOException, SAXException {
+        if (input == null) {
+            throw new IllegalArgumentException("Invalid input stream given");
+        }
+        final Collection<ValidationViolation> messages;
+        if (isMetaInf) {
+            messages = executor.validateMetaInf(input, Paths.get(resourcePath), basePath);
+        } else {
+            messages = executor.validateJcrRoot(input, Paths.get(resourcePath), basePath);
+        }
+        return messages;
+    }
+    
+
+    @Test
+    public void testFilePathToNodePath() {
+        Assert.assertEquals("/apps/test", ValidationExecutor.filePathToNodePath(Paths.get("apps", "test")));
+        Assert.assertEquals("/some/other/path", ValidationExecutor.filePathToNodePath(Paths.get("some", "other", "path")));
+    }
+
+    public static void assertViolation(Collection<? extends ValidationMessage> messages, ValidationMessageSeverity thresholdSeverity, ValidationMessage... violations) {
+        List<ValidationMessage> filteredMessages = messages.stream()
+                .filter(m -> m.getSeverity().ordinal() >= thresholdSeverity.ordinal()).collect(Collectors.toList());
+        Assert.assertThat(filteredMessages, Matchers.contains(violations));
+    }
+
+    public static void assertViolation(Collection<? extends ValidationMessage> messages, ValidationMessage... violations) {
+        ValidationExecutorTest.assertViolation(messages, ValidationMessageSeverity.WARN, violations);
+    }
+}

Added: jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/ValidationViolationTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/ValidationViolationTest.java?rev=1867884&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/ValidationViolationTest.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/ValidationViolationTest.java Wed Oct  2 11:28:25 2019
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.filevault.validation;
+
+import java.nio.file.Paths;
+import java.util.Collection;
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.jackrabbit.filevault.validation.spi.ValidationMessage;
+import org.apache.jackrabbit.filevault.validation.spi.ValidationMessageSeverity;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ValidationViolationTest {
+
+    private List<ValidationMessage> messages;
+
+    private Throwable myThrowable1;
+    private Throwable myThrowable2;
+    
+    @Before
+    public void setUp() {
+        myThrowable1 = new Exception("myThrowable1");
+        myThrowable2 = new Exception("myThrowable2");
+        messages = new LinkedList<>();
+        messages.add(new ValidationMessage(ValidationMessageSeverity.DEBUG, "message1"));
+        messages.add(new ValidationMessage(ValidationMessageSeverity.INFO, "message2", 1, 2, myThrowable1));
+        messages.add(new ValidationViolation("myid", ValidationMessageSeverity.ERROR, "message3", Paths.get("child"), null, "nodepath1", 3, 4, myThrowable2));
+        messages.add(new ValidationViolation("myid", ValidationMessageSeverity.ERROR, "message4", Paths.get("child"), Paths.get("base"), "nodepath1", 3, 4, myThrowable2));
+    }
+
+    @Test
+    public void testWrapMessagesNoOverwrite() {
+        Collection<ValidationViolation> violations = ValidationViolation.wrapMessages(null, messages, null, null, null, 0, 0);
+        ValidationExecutorTest.assertViolation(violations, ValidationMessageSeverity.DEBUG, 
+                new ValidationViolation(ValidationMessageSeverity.DEBUG, "message1"),
+                new ValidationViolation(null, ValidationMessageSeverity.INFO, "message2", null, null, null, 1, 2, myThrowable1),
+                ValidationViolation.class.cast(messages.get(2)),
+                ValidationViolation.class.cast(messages.get(3)));
+    }
+
+    @Test
+    public void testWrapMessagesFullOverwrite() {
+        Collection<ValidationViolation> violations = ValidationViolation.wrapMessages("myid2", messages, Paths.get("child1"), Paths.get("base1"), "nodepath2", 10, 20);
+        ValidationExecutorTest.assertViolation(violations, ValidationMessageSeverity.DEBUG, 
+                new ValidationViolation("myid2", ValidationMessageSeverity.DEBUG, "message1", Paths.get("child1"), Paths.get("base1"), "nodepath2", 10, 20, null),
+                new ValidationViolation("myid2", ValidationMessageSeverity.INFO, "message2", Paths.get("child1"), Paths.get("base1"), "nodepath2", 1, 2, null),
+                new ValidationViolation("myid", ValidationMessageSeverity.ERROR, "message3", Paths.get("child"), Paths.get("base1"), "nodepath1", 3, 4, myThrowable2),
+                new ValidationViolation("myid", ValidationMessageSeverity.ERROR, "message4", Paths.get("child"), Paths.get("base"), "nodepath1", 3, 4, myThrowable2));
+    }
+
+    @Test
+    public void testValidationViolation() {
+        ValidationViolation violation = new ValidationViolation("myid2", ValidationMessageSeverity.DEBUG, "message1", Paths.get("child1"), Paths.get("base1"), "nodepath2", 10, 20, null);
+        Assert.assertEquals("myid2", violation.getValidatorId());
+        Assert.assertEquals(ValidationMessageSeverity.DEBUG, violation.getSeverity());
+        Assert.assertEquals("message1", violation.getMessage());
+        Assert.assertEquals(Paths.get("base1","child1"), violation.getFilePath());
+        Assert.assertEquals("nodepath2", violation.getNodePath());
+        Assert.assertEquals(10, violation.getLine());
+        Assert.assertEquals(20, violation.getColumn());
+    }
+}

Added: jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/impl/util/ResettableInputStreamTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/impl/util/ResettableInputStreamTest.java?rev=1867884&view=auto
==============================================================================
--- jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/impl/util/ResettableInputStreamTest.java (added)
+++ jackrabbit/commons/filevault/trunk/vault-validation/src/test/java/org/apache/jackrabbit/filevault/validation/impl/util/ResettableInputStreamTest.java Wed Oct  2 11:28:25 2019
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.filevault.validation.impl.util;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.apache.commons.io.IOUtils;
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+@RunWith(Parameterized.class)
+public class ResettableInputStreamTest {
+
+    @Parameters
+    public static Collection<Object> data() throws IOException, URISyntaxException {
+        return Arrays.asList(new Object[] {
+                ResettableInputStreamTest.class.getResourceAsStream("/dummy.txt"),
+                new FileInputStream(new File(ResettableInputStreamTest.class.getResource("/dummy.txt").toURI())),
+                Files.newInputStream(Paths.get(ResettableInputStreamTest.class.getResource("/dummy.txt").toURI()))
+        });
+    }
+
+    private final InputStream input;
+
+    public ResettableInputStreamTest(InputStream input) {
+        this.input = input;
+    }
+
+    @Test
+    public void testWithBufferedInputStream() throws IOException {
+        try (ResettableInputStream resettableInputStream = new ResettableInputStream(input)) {
+            Assert.assertTrue(resettableInputStream.markSupported());
+            Assert.assertEquals("some dummy text", IOUtils.toString(resettableInputStream, StandardCharsets.UTF_8));
+            // this one should be reset to the beginning
+            resettableInputStream.reset();
+            Assert.assertEquals("some dummy text", IOUtils.toString(resettableInputStream, StandardCharsets.UTF_8));
+        }
+    }
+
+    @After
+    public void tearDown() {
+        IOUtils.closeQuietly(input);
+    }
+}