use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class ValidationServiceImplTest method testValueMapWithEmptyOptionalValue.
@Test()
public void testValueMapWithEmptyOptionalValue() throws Exception {
propertyBuilder.optional();
propertyBuilder.validator(REGEX_VALIDATOR_ID, null, RegexValidator.REGEX_PARAM, "abc");
modelBuilder.resourceProperty(propertyBuilder.build("field1"));
ValidationModel vm = modelBuilder.build("sling/validation/test", "some source");
HashMap<String, Object> hashMap = new HashMap<String, Object>();
hashMap.put("field1", "");
ValidationResult vr = validationService.validate(new ValueMapDecorator(hashMap), vm);
Assert.assertFalse(vr.isValid());
Assert.assertThat(vr.getFailures(), Matchers.<ValidationFailure>contains(new DefaultValidationFailure("field1", 10, defaultResourceBundle, RegexValidator.I18N_KEY_PATTERN_DOES_NOT_MATCH, "abc")));
}
use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class ValidationServiceImplTest method testValueMapWithMissingField.
@Test()
public void testValueMapWithMissingField() throws Exception {
modelBuilder.resourceProperty(propertyBuilder.build("field1"));
modelBuilder.resourceProperty(propertyBuilder.build("field2"));
modelBuilder.resourceProperty(propertyBuilder.build("field3"));
modelBuilder.resourceProperty(propertyBuilder.build("field4"));
ValidationModel vm = modelBuilder.build("sling/validation/test", "some source");
// this should not be detected as missing property
HashMap<String, Object> hashMap = new HashMap<String, Object>();
hashMap.put("field1", new String[] {});
hashMap.put("field2", new String[] { "null" });
hashMap.put("field3", "");
ValidationResult vr = validationService.validate(new ValueMapDecorator(hashMap), vm);
Assert.assertThat(vr.getFailures(), Matchers.<ValidationFailure>contains(new DefaultValidationFailure("", 20, defaultResourceBundle, ValidationServiceImpl.I18N_KEY_MISSING_REQUIRED_PROPERTY_WITH_NAME, "field4")));
}
use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class MergedResourceTest method testResourceTypeMixed.
@Test
public void testResourceTypeMixed() throws Exception {
final ValueMap vm1 = new ValueMapDecorator(Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object) "vma"));
final MockResource r1 = new MockResource("/a", vm1, null) {
@Override
public String getResourceType() {
return "a";
}
};
final ValueMap vm2 = new ValueMapDecorator(Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object) "vmb"));
final MockResource r2 = new MockResource("/b", vm2, null) {
@Override
public String getResourceType() {
return "b";
}
};
final ValueMap vm3 = new ValueMapDecorator(Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object) "vmc"));
final MockResource r3 = new MockResource("/c", vm3, null) {
@Override
public String getResourceType() {
return "c";
}
};
final List<Resource> resources = new ArrayList<Resource>();
resources.add(r1);
resources.add(r2);
resources.add(r3);
final List<ValueMap> valueMaps = new ArrayList<ValueMap>();
valueMaps.add(vm1);
valueMaps.add(vm2);
valueMaps.add(vm3);
final MergedResource mr1 = new MergedResource(null, "/a", "a", resources, valueMaps);
assertEquals("c", mr1.getResourceType());
assertEquals("vmc", mr1.getResourceSuperType());
final MergedResource mr2 = new MergedResource(null, "/a", "a", resources, Collections.singletonList(vm2));
assertEquals("c", mr2.getResourceType());
assertEquals("vmb", mr2.getResourceSuperType());
}
use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class MergedResourceTest method testToString.
@Test
public void testToString() throws Exception {
final ValueMap vm = new ValueMapDecorator(Collections.singletonMap(ResourceResolver.PROPERTY_RESOURCE_TYPE, (Object) "vm"));
final Resource r = new MockResource("/innerResourcePath", vm, null) {
@Override
public String getResourceType() {
return "innerResource";
}
};
final Resource mr = new MergedResource(null, "/merged", "merged", Collections.singletonList(r), Collections.singletonList(vm));
assertTrue(mr.toString().contains("/innerResourcePath"));
}
use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class ConfigurationDataImpl method getValues.
@Override
public ValueMap getValues() {
if (valuesCache == null) {
Map<String, Object> props = new HashMap<>();
if (writebackConfigurationResource != null) {
props.putAll(ResourceUtil.getValueMap(writebackConfigurationResource));
}
PropertiesFilterUtil.removeIgnoredProperties(props, configurationManagementSettings);
resolveNestedConfigs(props);
valuesCache = new ValueMapDecorator(props);
}
return valuesCache;
}
Aggregations