Search in sources :

Example 1 with ChildResourceInjector

use of org.apache.sling.models.impl.injectors.ChildResourceInjector in project sling by apache.

the class InjectorSpecificAnnotationTest 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);
    osgiInjector = new OSGiServiceInjector();
    osgiInjector.activate(componentCtx);
    BindingsInjector bindingsInjector = new BindingsInjector();
    ValueMapInjector valueMapInjector = new ValueMapInjector();
    ChildResourceInjector childResourceInjector = new ChildResourceInjector();
    RequestAttributeInjector requestAttributeInjector = new RequestAttributeInjector();
    factory.bindInjector(bindingsInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 1L));
    factory.bindInjector(valueMapInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 2L));
    factory.bindInjector(childResourceInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 3L));
    factory.bindInjector(requestAttributeInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 4L));
    factory.bindInjector(osgiInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 5L));
    factory.bindStaticInjectAnnotationProcessorFactory(bindingsInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 1L));
    factory.bindInjectAnnotationProcessorFactory(valueMapInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 2L));
    factory.bindInjectAnnotationProcessorFactory2(childResourceInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 3L));
    factory.bindStaticInjectAnnotationProcessorFactory(requestAttributeInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 4L));
    factory.bindStaticInjectAnnotationProcessorFactory(osgiInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 5L));
    factory.bindViaProvider(new BeanPropertyViaProvider(), null);
    SlingBindings bindings = new SlingBindings();
    bindings.setLog(log);
    Mockito.when(request.getAttribute(SlingBindings.class.getName())).thenReturn(bindings);
    factory.adapterImplementations.addClassesAsAdapterAndImplementation(InjectorSpecificAnnotationModel.class, org.apache.sling.models.testmodels.classes.constructorinjection.InjectorSpecificAnnotationModel.class);
}
Also used : BindingsInjector(org.apache.sling.models.impl.injectors.BindingsInjector) ValueMapInjector(org.apache.sling.models.impl.injectors.ValueMapInjector) ChildResourceInjector(org.apache.sling.models.impl.injectors.ChildResourceInjector) SlingBindings(org.apache.sling.api.scripting.SlingBindings) OSGiServiceInjector(org.apache.sling.models.impl.injectors.OSGiServiceInjector) RequestAttributeInjector(org.apache.sling.models.impl.injectors.RequestAttributeInjector) BeanPropertyViaProvider(org.apache.sling.models.impl.via.BeanPropertyViaProvider) Before(org.junit.Before)

Example 2 with ChildResourceInjector

use of org.apache.sling.models.impl.injectors.ChildResourceInjector in project sling by apache.

the class InvalidAdaptationsTest 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(1, 1));
    factory.bindInjector(new ChildResourceInjector(), new ServicePropertiesMap(2, 0));
    factory.adapterImplementations.addClassesAsAdapterAndImplementation(NonModel.class, RequestModel.class);
}
Also used : ValueMapInjector(org.apache.sling.models.impl.injectors.ValueMapInjector) ChildResourceInjector(org.apache.sling.models.impl.injectors.ChildResourceInjector) Before(org.junit.Before)

Example 3 with ChildResourceInjector

use of org.apache.sling.models.impl.injectors.ChildResourceInjector in project sling by apache.

the class OptionalPrimitivesTest 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(2, 2));
    factory.bindInjector(new ChildResourceInjector(), new ServicePropertiesMap(1, 1));
    factory.adapterImplementations.addClassesAsAdapterAndImplementation(org.apache.sling.models.testmodels.classes.OptionalPrimitivesModel.class, org.apache.sling.models.testmodels.interfaces.OptionalPrimitivesModel.class, org.apache.sling.models.testmodels.classes.constructorinjection.OptionalPrimitivesModel.class);
}
Also used : ValueMapInjector(org.apache.sling.models.impl.injectors.ValueMapInjector) ChildResourceInjector(org.apache.sling.models.impl.injectors.ChildResourceInjector) Before(org.junit.Before)

Example 4 with ChildResourceInjector

use of org.apache.sling.models.impl.injectors.ChildResourceInjector in project sling by apache.

the class ResourceModelConstructorTest 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(2, 2));
    factory.bindInjector(new ChildResourceInjector(), new ServicePropertiesMap(1, 1));
    factory.adapterImplementations.addClassesAsAdapterAndImplementation(ParentModel.class, ChildModel.class);
}
Also used : ValueMapInjector(org.apache.sling.models.impl.injectors.ValueMapInjector) ChildResourceInjector(org.apache.sling.models.impl.injectors.ChildResourceInjector) Before(org.junit.Before)

Example 5 with ChildResourceInjector

use of org.apache.sling.models.impl.injectors.ChildResourceInjector in project sling by apache.

the class ResourceModelInterfacesTest 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(2, 2));
    factory.bindInjector(new ChildResourceInjector(), new ServicePropertiesMap(1, 1));
    factory.adapterImplementations.addClassesAsAdapterAndImplementation(SimplePropertyModel.class, ResourceModelWithRequiredField.class, ChildResourceModel.class, ChildValueMapModel.class, ParentModel.class, ChildModel.class);
}
Also used : ValueMapInjector(org.apache.sling.models.impl.injectors.ValueMapInjector) ChildResourceInjector(org.apache.sling.models.impl.injectors.ChildResourceInjector) Before(org.junit.Before)

Aggregations

ChildResourceInjector (org.apache.sling.models.impl.injectors.ChildResourceInjector)6 ValueMapInjector (org.apache.sling.models.impl.injectors.ValueMapInjector)6 Before (org.junit.Before)6 SlingBindings (org.apache.sling.api.scripting.SlingBindings)1 BindingsInjector (org.apache.sling.models.impl.injectors.BindingsInjector)1 OSGiServiceInjector (org.apache.sling.models.impl.injectors.OSGiServiceInjector)1 RequestAttributeInjector (org.apache.sling.models.impl.injectors.RequestAttributeInjector)1 BeanPropertyViaProvider (org.apache.sling.models.impl.via.BeanPropertyViaProvider)1