use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class ResourcePathInjectionTest method setup.
@Before
public void setup() {
Map<String, Object> map = new HashMap<String, Object>();
map.put("propertyContainingAPath", "/some/other/path");
map.put("anotherPropertyContainingAPath", "/some/other/path2");
String[] paths = new String[2];
paths[0] = "/some/other/path";
paths[1] = "/some/other/path2";
String[] invalidPaths = new String[3];
invalidPaths[0] = "/does/not/exist";
invalidPaths[1] = "/does/not/exist2";
invalidPaths[2] = "/some/other/path";
map.put("propertyWithSeveralPaths", paths);
map.put("propertyWithMissingPaths", invalidPaths);
ValueMap properties = new ValueMapDecorator(map);
when(componentCtx.getBundleContext()).thenReturn(bundleContext);
when(componentCtx.getProperties()).thenReturn(new Hashtable<String, Object>());
when(adaptable.getResourceResolver()).thenReturn(resourceResolver);
when(adaptable.adaptTo(ValueMap.class)).thenReturn(properties);
when(resourceResolver.getResource("/some/path")).thenReturn(byPathResource);
when(resourceResolver.getResource("/some/path2")).thenReturn(byPathResource2);
when(resourceResolver.getResource("/some/other/path")).thenReturn(byPropertyValueResource);
when(resourceResolver.getResource("/some/other/path2")).thenReturn(byPropertyValueResource2);
factory = new ModelAdapterFactory();
factory.activate(componentCtx);
factory.bindInjector(new SelfInjector(), new ServicePropertiesMap(1, Integer.MAX_VALUE));
factory.bindInjector(new ValueMapInjector(), new ServicePropertiesMap(2, 2000));
factory.bindInjector(new ResourcePathInjector(), new ServicePropertiesMap(3, 2500));
factory.bindStaticInjectAnnotationProcessorFactory(new ResourcePathInjector(), new ServicePropertiesMap(3, 2500));
factory.adapterImplementations.addClassesAsAdapterAndImplementation(ResourcePathModel.class, ResourcePathPartialModel.class, ResourcePathAllOptionalModel.class, ResourcePathModelWrapping.class);
}
use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class DefaultTest method testDefaultWrappersField.
@Test
public void testDefaultWrappersField() {
ValueMap vm = new ValueMapDecorator(Collections.<String, Object>emptyMap());
Resource res = mock(Resource.class);
when(res.adaptTo(ValueMap.class)).thenReturn(vm);
DefaultWrappersModel model = factory.getAdapter(res, DefaultWrappersModel.class);
assertNotNull(model);
assertEquals(Boolean.valueOf(true), model.getBooleanWrapperProperty());
// we need to wait for JUnit 4.12 for this assertArrayEquals to be working on primitive boolean arrays, https://github.com/junit-team/junit/issues/86!
assertTrue(Arrays.equals(new Boolean[] { Boolean.TRUE, Boolean.TRUE }, model.getBooleanWrapperArrayProperty()));
assertEquals(Long.valueOf(1L), model.getLongWrapperProperty());
assertArrayEquals(new Long[] { Long.valueOf(1L), Long.valueOf(1L) }, model.getLongWrapperArrayProperty());
}
use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class DefaultTest method testDefaultStringValueField.
@Test
public void testDefaultStringValueField() {
ValueMap vm = new ValueMapDecorator(Collections.<String, Object>emptyMap());
Resource res = mock(Resource.class);
when(res.adaptTo(ValueMap.class)).thenReturn(vm);
DefaultStringModel model = factory.getAdapter(res, DefaultStringModel.class);
assertNotNull(model);
assertEquals("firstDefault", model.getFirstProperty());
assertEquals(2, model.getSecondProperty().length);
}
use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class DefaultTest method testDefaultStringValueConstructor.
@Test
public void testDefaultStringValueConstructor() {
ValueMap vm = new ValueMapDecorator(Collections.<String, Object>emptyMap());
Resource res = mock(Resource.class);
when(res.adaptTo(ValueMap.class)).thenReturn(vm);
org.apache.sling.models.testmodels.classes.constructorinjection.DefaultStringModel model = factory.getAdapter(res, org.apache.sling.models.testmodels.classes.constructorinjection.DefaultStringModel.class);
assertNotNull(model);
assertEquals("firstDefault", model.getFirstProperty());
assertEquals(2, model.getSecondProperty().length);
}
use of org.apache.sling.api.wrappers.ValueMapDecorator in project sling by apache.
the class DefaultTest method testDefaultPrimitivesField.
@Test
public void testDefaultPrimitivesField() {
ValueMap vm = new ValueMapDecorator(Collections.<String, Object>emptyMap());
Resource res = mock(Resource.class);
when(res.adaptTo(ValueMap.class)).thenReturn(vm);
DefaultPrimitivesModel model = factory.getAdapter(res, DefaultPrimitivesModel.class);
assertNotNull(model);
assertEquals(true, model.getBooleanProperty());
// we need to wait for JUnit 4.12 for this assertArrayEquals to be working on primitive boolean arrays, https://github.com/junit-team/junit/issues/86!
assertTrue(Arrays.equals(new boolean[] { true, true }, model.getBooleanArrayProperty()));
assertEquals(1L, model.getLongProperty());
assertArrayEquals(new long[] { 1L, 1L }, model.getLongArrayProperty());
}
Aggregations