Search in sources :

Example 6 with ValueMapInjector

use of org.apache.sling.models.impl.injectors.ValueMapInjector 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 7 with ValueMapInjector

use of org.apache.sling.models.impl.injectors.ValueMapInjector 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 8 with ValueMapInjector

use of org.apache.sling.models.impl.injectors.ValueMapInjector 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)

Example 9 with ValueMapInjector

use of org.apache.sling.models.impl.injectors.ValueMapInjector 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);
}
Also used : ValueMapInjector(org.apache.sling.models.impl.injectors.ValueMapInjector) HashMap(java.util.HashMap) ValueMap(org.apache.sling.api.resource.ValueMap) ValueMapDecorator(org.apache.sling.api.wrappers.ValueMapDecorator) SelfInjector(org.apache.sling.models.impl.injectors.SelfInjector) ResourcePathInjector(org.apache.sling.models.impl.injectors.ResourcePathInjector) Before(org.junit.Before)

Example 10 with ValueMapInjector

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

the class ResourceModelClassesTest 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);
    ValueMapInjector valueMapInjector = new ValueMapInjector();
    factory.bindInjector(valueMapInjector, new ServicePropertiesMap(2, 2));
    factory.bindInjector(new ChildResourceInjector(), new ServicePropertiesMap(1, 1));
    factory.bindInjectAnnotationProcessorFactory(valueMapInjector, Collections.<String, Object>singletonMap(Constants.SERVICE_ID, 2L));
    factory.adapterImplementations.addClassesAsAdapterAndImplementation(SimplePropertyModel.class, ArrayWrappersModel.class, ResourceModelWithRequiredField.class, ChildValueMapModel.class, ArrayPrimitivesModel.class, ChildResourceModel.class, ResourceModelWithRequiredFieldOptionalStrategy.class, ParentModel.class, ChildModel.class, ListModel.class);
}
Also used : ValueMapInjector(org.apache.sling.models.impl.injectors.ValueMapInjector) ChildResourceInjector(org.apache.sling.models.impl.injectors.ChildResourceInjector) Before(org.junit.Before)

Aggregations

ValueMapInjector (org.apache.sling.models.impl.injectors.ValueMapInjector)12 Before (org.junit.Before)12 ChildResourceInjector (org.apache.sling.models.impl.injectors.ChildResourceInjector)6 SelfInjector (org.apache.sling.models.impl.injectors.SelfInjector)2 BeanPropertyViaProvider (org.apache.sling.models.impl.via.BeanPropertyViaProvider)2 URL (java.net.URL)1 Dictionary (java.util.Dictionary)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Vector (java.util.Vector)1 ValueMap (org.apache.sling.api.resource.ValueMap)1 SlingBindings (org.apache.sling.api.scripting.SlingBindings)1 ValueMapDecorator (org.apache.sling.api.wrappers.ValueMapDecorator)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 ResourcePathInjector (org.apache.sling.models.impl.injectors.ResourcePathInjector)1 ChildResourceViaProvider (org.apache.sling.models.impl.via.ChildResourceViaProvider)1 ExtendsClassPropertyModel (org.apache.sling.models.testmodels.classes.implextend.ExtendsClassPropertyModel)1 ImplementsInterfacePropertyModel (org.apache.sling.models.testmodels.classes.implextend.ImplementsInterfacePropertyModel)1