blob: b957ea7d0837a54aed49a2d763d8a2d5ed1ce24a (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.application;
import com.yahoo.jdisc.test.TestDriver;
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.osgi.framework.ServiceReference;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/**
* @author <a href="mailto:simon@yahoo-inc.com">Simon Thoresen Hult</a>
*/
public class BundleActivatorIntegrationTest {
@Test
public void requireThatBundleActivatorHasAccessToCurrentContainer() throws Exception {
TestDriver driver = TestDriver.newSimpleApplicationInstance();
OsgiFramework osgi = driver.osgiFramework();
BundleInstaller installer = new BundleInstaller(driver.osgiFramework());
Bundle bundle = installer.installAndStart("my-bundle-activator.jar").get(0);
Class<?> serviceClass = bundle.loadClass("com.yahoo.jdisc.bundle.MyService");
assertNotNull(serviceClass);
BundleContext ctx = osgi.bundleContext();
ServiceReference<?> serviceRef = ctx.getServiceReference(serviceClass.getName());
assertNotNull(serviceRef);
Object service = ctx.getService(serviceRef);
assertNotNull(service);
assertTrue(serviceClass.isInstance(service));
assertTrue(driver.close());
}
@Test
public void requireThatApplicationBundleActivatorHasAccessToCurrentContainer() throws Exception {
TestDriver driver = TestDriver.newApplicationBundleInstance("app-g-act.jar", false);
OsgiFramework osgi = driver.osgiFramework();
Class<?> serviceClass = osgi.bundles().get(1).loadClass("com.yahoo.jdisc.bundle.MyService");
assertNotNull(serviceClass);
BundleContext ctx = osgi.bundleContext();
ServiceReference<?> serviceRef = ctx.getServiceReference(serviceClass.getName());
assertNotNull(serviceRef);
Object service = ctx.getService(serviceRef);
assertNotNull(service);
assertTrue(serviceClass.isInstance(service));
assertTrue(driver.close());
}
}
|