Search in sources :

Example 6 with AdapterFactory

use of org.apache.sling.api.adapter.AdapterFactory in project sling by apache.

the class SlingContextTest method prepareInitialAdapterFactory.

private void prepareInitialAdapterFactory() {
    // register "traditional" adapter factory without specific service ranking
    AdapterFactory adapterFactory = new AdapterFactory() {

        @SuppressWarnings("unchecked")
        @Override
        public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
            return (AdapterType) (((TestAdaptable) adaptable).getMessage() + "-initial");
        }
    };
    context.registerService(AdapterFactory.class, adapterFactory, ImmutableMap.<String, Object>builder().put(AdapterFactory.ADAPTABLE_CLASSES, new String[] { TestAdaptable.class.getName() }).put(AdapterFactory.ADAPTER_CLASSES, new String[] { String.class.getName() }).build());
    // test initial adapter factory
    assertEquals("testMessage1-initial", new TestAdaptable("testMessage1").adaptTo(String.class));
}
Also used : AdapterFactory(org.apache.sling.api.adapter.AdapterFactory)

Aggregations

AdapterFactory (org.apache.sling.api.adapter.AdapterFactory)6 Page (com.day.cq.wcm.api.Page)2 ArrayList (java.util.ArrayList)2 LinkedList (java.util.LinkedList)2 List (java.util.List)2 Resource (org.apache.sling.api.resource.Resource)2 AdapterFactoryDescriptor (org.apache.sling.adapter.internal.AdapterFactoryDescriptor)1 ModelAdapterFactory (org.apache.sling.models.impl.ModelAdapterFactory)1 BeforeClass (org.junit.BeforeClass)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1