Search in sources :

Example 1 with IndexedOsgiResourceLocator

use of org.ops4j.pax.web.resources.extender.internal.IndexedOsgiResourceLocator in project org.ops4j.pax.web by ops4j.

the class IndexedOsgiResourceLocaterTests method setUp.

@Before
public void setUp() throws Exception {
    context = mock(BundleContext.class);
    resourceBundleOne = new BundleBuilder().withBundleId(100).withSymbolicName("resourcebundle-one").buildWithResources("template.html", "base.css");
    resourceBundleTwo = new BundleBuilder().withBundleId(100).withSymbolicName("resourcebundle-two").buildWithResources("footer.html", "js/some.js", "folder/subfolder/a.js", "folder/subfolder/b.js", "folder/bla/a.js", "en/libraryname/test.css/2_4.css");
    sut = new IndexedOsgiResourceLocator(context);
    sut.register(resourceBundleOne);
    sut.register(resourceBundleTwo);
}
Also used : IndexedOsgiResourceLocator(org.ops4j.pax.web.resources.extender.internal.IndexedOsgiResourceLocator) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 2 with IndexedOsgiResourceLocator

use of org.ops4j.pax.web.resources.extender.internal.IndexedOsgiResourceLocator in project org.ops4j.pax.web by ops4j.

the class AbstractWarJsfResourcehandlerIntegrationTest method testServiceOverride.

/**
 * The default implementation {@link IndexedOsgiResourceLocator} is
 * registered with {@link Constants#SERVICE_RANKING} of -1, so when
 * registering a new implementation, this new class must be served.
 */
@Test
public void testServiceOverride() throws Exception {
    OsgiResourceLocatorForTest expectedService = new OsgiResourceLocatorForTest();
    bundleContext.registerService(OsgiResourceLocator.class, new OsgiResourceLocatorForTest(), null);
    ServiceReference<OsgiResourceLocator> ref = bundleContext.getServiceReference(OsgiResourceLocator.class);
    if (ref != null) {
        OsgiResourceLocator service = bundleContext.getService(ref);
        if (service != null) {
            assertThat("'OsgiResourceLocatorForTest' must be found due to higher service-ranking!", service.getClass().getName(), serviceName -> expectedService.getClass().getName().equals(serviceName));
        } else {
            fail("Service could not be retrieved");
        }
    } else {
        fail("Service-Reference could not be retrieved");
    }
}
Also used : IndexedOsgiResourceLocator(org.ops4j.pax.web.resources.extender.internal.IndexedOsgiResourceLocator) OsgiResourceLocator(org.ops4j.pax.web.resources.api.OsgiResourceLocator) Test(org.junit.Test)

Aggregations

IndexedOsgiResourceLocator (org.ops4j.pax.web.resources.extender.internal.IndexedOsgiResourceLocator)2 Before (org.junit.Before)1 Test (org.junit.Test)1 OsgiResourceLocator (org.ops4j.pax.web.resources.api.OsgiResourceLocator)1 BundleContext (org.osgi.framework.BundleContext)1