use of org.apache.sling.validation.model.ValidationModel in project sling by apache.
the class ValidationModelRetrieverImpl method fillTrieForResourceType.
@Nonnull
private PatriciaTrie<ValidationModel> fillTrieForResourceType(@Nonnull String resourceType) {
// create a new (empty) trie
PatriciaTrie<ValidationModel> modelsForResourceType = new PatriciaTrie<ValidationModel>();
// lowest ranked model provider inserts first (i.e. higher ranked should overwrite)
for (ValidationModelProvider modelProvider : modelProviders) {
LOG.debug("Retrieving validation models with resource type {} from provider {}...", resourceType, modelProvider.getClass().getName());
List<ValidationModel> models = modelProvider.getValidationModels(resourceType);
for (ValidationModel model : models) {
for (String applicablePath : model.getApplicablePaths()) {
LOG.debug("Found validation model for resource type {} for applicable path {}", resourceType, applicablePath);
modelsForResourceType.put(applicablePath, model);
}
}
if (models.isEmpty()) {
LOG.debug("Found no validation model with resource type {} from provider {}", resourceType, modelProvider.getClass().getName());
}
}
return modelsForResourceType;
}
use of org.apache.sling.validation.model.ValidationModel in project sling by apache.
the class MergedValidationModelTest method testLessSpecificApplicationPathInModelToMerge.
@Test
public void testLessSpecificApplicationPathInModelToMerge() {
modelBuilder.addApplicablePath("/base/path").addApplicablePath("/base/path2");
ValidationModel baseValidationModel = modelBuilder.build("base", "some source");
modelBuilder.setApplicablePath("/base");
ValidationModel mergedModel = new MergedValidationModel(baseValidationModel, modelBuilder.build("superType", "some source"));
Assert.assertThat(mergedModel.getApplicablePaths(), Matchers.contains("/base/path", "/base/path2"));
}
use of org.apache.sling.validation.model.ValidationModel in project sling by apache.
the class MergedValidationModelTest method testValidatedResourceTypes.
@Test
public void testValidatedResourceTypes() {
ValidationModel mergedModel = new MergedValidationModel(modelBuilder.build("base", "some source"), modelBuilder.build("superType", "some source"));
Assert.assertThat(mergedModel.getValidatingResourceType(), Matchers.equalTo("base"));
}
use of org.apache.sling.validation.model.ValidationModel in project sling by apache.
the class ResourceValidationModelProviderImplTest method testGetValidationModelsWithInvalidValidatorArguments2.
@Test(expected = IllegalStateException.class)
public void testGetValidationModelsWithInvalidValidatorArguments2() throws Exception {
// create a model with neither children nor properties
ValidationModel model1 = modelBuilder.build("sling/validation/test", libsValidatorsRoot.getPath() + "/testValidationModel1");
// create valid model first
Resource modelResource = createValidationModelResource(rr, libsValidatorsRoot.getPath(), "testValidationModel1", model1);
// and make parametrization of validator invalid afterwards
Resource validatorResource = modelResource.getChild("properties/field1/validators/validatorId");
ModifiableValueMap validatorArguments = validatorResource.adaptTo(ModifiableValueMap.class);
// starting with "="
validatorArguments.put("validatorArguments", "=value2");
Collection<ValidationModel> models = modelProvider.getValidationModels("sling/validation/test");
Assert.assertThat(models, Matchers.contains(model1));
}
use of org.apache.sling.validation.model.ValidationModel in project sling by apache.
the class ValidationModelRetrieverImplTest method testGetModel.
@Test
public void testGetModel() {
applicablePathPerResourceType.put("test/type", "/content/site1");
applicablePathPerResourceType.put("test/type", "/content/site1/subnode/test");
applicablePathPerResourceType.put("test/type", "/content/site1/subnode");
applicablePathPerResourceType.put("test/type", "/content/site1/subnode/test/somepage/within");
applicablePathPerResourceType.put("test/type", "/content/site1/subnode/test/testoutside");
ValidationModel model = validationModelRetriever.getValidationModel("test/type", "/content/site1/subnode/test/somepage", false);
Assert.assertNotNull(model);
Assert.assertThat(model.getApplicablePaths(), Matchers.contains("/content/site1/subnode/test"));
}
Aggregations