Search in sources :

Example 1 with SampleServiceInterface

use of org.apache.sling.models.testmodels.classes.implextend.SampleServiceInterface in project sling by apache.

the class ImplementsExtendsTest method testImplementsInterfaceModel.

/**
     * Try to adapt to interface, with an different implementation class that has the @Model annotation
     */
@Test
public void testImplementsInterfaceModel() {
    Resource res = getMockResourceWithProps();
    SampleServiceInterface model = factory.getAdapter(res, SampleServiceInterface.class);
    assertNotNull(model);
    assertEquals(ImplementsInterfacePropertyModel.class, model.getClass());
    assertEquals("first-value|null|third-value", model.getAllProperties());
    assertTrue(factory.canCreateFromAdaptable(res, SampleServiceInterface.class));
}
Also used : Resource(org.apache.sling.api.resource.Resource) SampleServiceInterface(org.apache.sling.models.testmodels.classes.implextend.SampleServiceInterface) InvalidSampleServiceInterface(org.apache.sling.models.testmodels.classes.implextend.InvalidSampleServiceInterface) Test(org.junit.Test)

Example 2 with SampleServiceInterface

use of org.apache.sling.models.testmodels.classes.implextend.SampleServiceInterface in project sling by apache.

the class ImplementsExtendsTest method testImplementsNoPickerWithAdapterEqualsImplementation.

/**
     * Try to adapt in a case where there is no picker available.
     * This causes the extend adaptation to fail.
     */
@Test
public void testImplementsNoPickerWithAdapterEqualsImplementation() {
    factory.unbindImplementationPicker(firstImplementationPicker, firstImplementationPickerProps);
    Resource res = getMockResourceWithProps();
    SampleServiceInterface model = factory.getAdapter(res, ImplementsInterfacePropertyModel.class);
    assertNotNull(model);
    assertEquals("first-value|null|third-value", model.getAllProperties());
    assertTrue(factory.canCreateFromAdaptable(res, ImplementsInterfacePropertyModel.class));
}
Also used : Resource(org.apache.sling.api.resource.Resource) SampleServiceInterface(org.apache.sling.models.testmodels.classes.implextend.SampleServiceInterface) InvalidSampleServiceInterface(org.apache.sling.models.testmodels.classes.implextend.InvalidSampleServiceInterface) ImplementsInterfacePropertyModel(org.apache.sling.models.testmodels.classes.implextend.ImplementsInterfacePropertyModel) InvalidImplementsInterfacePropertyModel(org.apache.sling.models.testmodels.classes.implextend.InvalidImplementsInterfacePropertyModel) Test(org.junit.Test)

Example 3 with SampleServiceInterface

use of org.apache.sling.models.testmodels.classes.implextend.SampleServiceInterface in project sling by apache.

the class ImplementsExtendsTest method testImplementsInterfaceModelWithPickLastImplementationPicker.

/**
     * Try to adapt to interface, with an different implementation class that has the @Model annotation
     */
@Test
public void testImplementsInterfaceModelWithPickLastImplementationPicker() {
    factory.bindImplementationPicker(new AdapterImplementationsTest.LastImplementationPicker(), new ServicePropertiesMap(3, 1));
    Resource res = getMockResourceWithProps();
    SampleServiceInterface model = factory.getAdapter(res, SampleServiceInterface.class);
    assertNotNull(model);
    assertEquals(ImplementsInterfacePropertyModel2.class, model.getClass());
    assertEquals("first-value|null|third-value", model.getAllProperties());
    assertTrue(factory.canCreateFromAdaptable(res, SampleServiceInterface.class));
}
Also used : Resource(org.apache.sling.api.resource.Resource) SampleServiceInterface(org.apache.sling.models.testmodels.classes.implextend.SampleServiceInterface) InvalidSampleServiceInterface(org.apache.sling.models.testmodels.classes.implextend.InvalidSampleServiceInterface) Test(org.junit.Test)

Aggregations

Resource (org.apache.sling.api.resource.Resource)3 InvalidSampleServiceInterface (org.apache.sling.models.testmodels.classes.implextend.InvalidSampleServiceInterface)3 SampleServiceInterface (org.apache.sling.models.testmodels.classes.implextend.SampleServiceInterface)3 Test (org.junit.Test)3 ImplementsInterfacePropertyModel (org.apache.sling.models.testmodels.classes.implextend.ImplementsInterfacePropertyModel)1 InvalidImplementsInterfacePropertyModel (org.apache.sling.models.testmodels.classes.implextend.InvalidImplementsInterfacePropertyModel)1