OakIndexDefinitionValidator implements FilterValidator, DocumentViewXmlValidator { @Override public @Nullable Collection<ValidationMessage> validate(@NotNull WorkspaceFilter filter) { Collection<ValidationMessage> violations = new LinkedList<>(); violations.addAll(collectIndexPaths(filter.getFilterSets())); return violations; } OakIndexDefinitionValidator(Path path, ValidationMessageSeverity defaultMessageSeverity); @Override @Nullable Collection<ValidationMessage> validate(@NotNull WorkspaceFilter filter); Collection<ValidationMessage> collectIndexPaths(List<PathFilterSet> pathFilters); @Override @Nullable Collection<ValidationMessage> validate(@NotNull DocViewNode node, @NotNull String nodePath, @NotNull Path filePath, boolean isRoot); @Override @Nullable Collection<ValidationMessage> done();  }
@Test public void test_filter() throws Exception { try (InputStream input = this.getClass().getResourceAsStream("/oak-index/filter.xml")) { DefaultWorkspaceFilter filter = new DefaultWorkspaceFilter(); filter.load(input); Collection<ValidationMessage> messages = validator.validate(filter); ValidationExecutorTest.assertViolation(messages, new ValidationMessage(ValidationMessageSeverity.ERROR, String.format(OakIndexDefinitionValidator.MESSAGE_POTENTIAL_INDEX_IN_FILTER, rootPackagePath,"/oak:index/ccProfile")), new ValidationMessage(ValidationMessageSeverity.ERROR, String .format(OakIndexDefinitionValidator.MESSAGE_POTENTIAL_INDEX_IN_FILTER, rootPackagePath, "/apps/project/oak:index/indexDef")), new ValidationMessage(ValidationMessageSeverity.ERROR, String .format(OakIndexDefinitionValidator.MESSAGE_POTENTIAL_INDEX_IN_FILTER, rootPackagePath, "/apps/anotherproject/oak:index"))); } }
@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"))); }
@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"))); }
@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()); }