use of org.apache.sling.models.impl.injectors.SelfInjector in project sling by apache.
the class ConstructorTest method setup.
@Before
public void setup() {
when(componentCtx.getBundleContext()).thenReturn(bundleContext);
when(componentCtx.getProperties()).thenReturn(new Hashtable<String, Object>());
when(request.getAttribute("attribute")).thenReturn(INT_VALUE);
when(request.getAttribute("attribute2")).thenReturn(STRING_VALUE);
factory = new ModelAdapterFactory();
factory.activate(componentCtx);
factory.bindInjector(new RequestAttributeInjector(), new ServicePropertiesMap(1, 1));
factory.bindInjector(new SelfInjector(), new ServicePropertiesMap(2, 2));
factory.adapterImplementations.addClassesAsAdapterAndImplementation(WithOneConstructorModel.class, WithThreeConstructorsModel.class, WithTwoConstructorsModel.class, SuperclassConstructorModel.class, InvalidConstructorModel.class, WithThreeConstructorsOneInjectModel.class, NoNameModel.class);
}
use of org.apache.sling.models.impl.injectors.SelfInjector in project sling by apache.
the class AdapterFactoryTest method setup.
@Before
public void setup() {
when(componentCtx.getBundleContext()).thenReturn(bundleContext);
when(componentCtx.getProperties()).thenReturn(new Hashtable<String, Object>());
factory = new ModelAdapterFactory();
factory.activate(componentCtx);
factory.bindInjector(new ValueMapInjector(), new ServicePropertiesMap(0, 0));
factory.bindInjector(new SelfInjector(), new ServicePropertiesMap(1, 1));
factory.adapterImplementations.addClassesAsAdapterAndImplementation(DefaultStringModel.class, ConstructorWithExceptionModel.class, NestedModel.class, NestedModelWithInvalidAdaptable.class, NestedModelWithInvalidAdaptable2.class, ResourceModelWithRequiredField.class);
}
use of org.apache.sling.models.impl.injectors.SelfInjector in project sling by apache.
the class SelfDependencyTest method setup.
@SuppressWarnings("unchecked")
@Before
public void setup() {
when(componentCtx.getBundleContext()).thenReturn(bundleContext);
when(componentCtx.getProperties()).thenReturn(new Hashtable<String, Object>());
when(request.adaptTo(any(Class.class))).then(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Class<?> clazz = (Class<?>) invocation.getArguments()[0];
return factory.getAdapter(request, clazz);
}
});
factory = new ModelAdapterFactory();
factory.activate(componentCtx);
factory.bindInjector(new SelfInjector(), new ServicePropertiesMap(1, 1));
factory.adapterImplementations.addClassesAsAdapterAndImplementation(SelfDependencyModelA.class, SelfDependencyModelB.class, DirectCyclicSelfDependencyModel.class, IndirectCyclicSelfDependencyModelA.class, IndirectCyclicSelfDependencyModelB.class);
}
use of org.apache.sling.models.impl.injectors.SelfInjector 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);
}
Aggregations