use of org.apache.aries.mocks.BundleMock in project aries by apache.
the class BlueprintURLContextTest method setup.
@BeforeClass
public static void setup() {
bundle = Skeleton.newMock(new BundleMock("aBundle", new Hashtable<String, String>()), Bundle.class);
BundleContext bc = bundle.getBundleContext();
new org.apache.aries.jndi.startup.Activator().start(bc);
Activator a = new Activator();
a.start(bc);
a.serviceFound();
// Register a BlueprintContainer mock that will answer getComponentInstance(String id) calls
BlueprintContainer bpc = Skeleton.newMock(new BlueprintContainerStub(), BlueprintContainer.class);
bc.registerService("org.osgi.service.blueprint.container.BlueprintContainer", bpc, new Hashtable<String, String>());
}
use of org.apache.aries.mocks.BundleMock in project aries by apache.
the class FragmentUtilsTest method makeBundleWithExports.
private Bundle makeBundleWithExports(String symbolicName, String version, String exports) {
Hashtable<String, Object> headers = new Hashtable<String, Object>();
headers.put(Constants.BUNDLE_VERSION, version);
headers.put(Constants.EXPORT_PACKAGE, exports);
Bundle exportBundle = Skeleton.newMock(new BundleMock(symbolicName, headers), Bundle.class);
return exportBundle;
}
use of org.apache.aries.mocks.BundleMock in project aries by apache.
the class ServiceRegistryContextTest method testLookupWhenServiceHasBeenRemoved.
/**
* Check that we get a NameNotFoundException if we lookup after the service
* has been unregistered.
*
* @throws NamingException
*/
@Test(expected = NameNotFoundException.class)
public void testLookupWhenServiceHasBeenRemoved() throws NamingException {
reg.unregister();
BundleMock mock = new BundleMock("scooby.doo", new Properties());
Thread.currentThread().setContextClassLoader(mock.getClassLoader());
InitialContext ctx = new InitialContext();
ctx.lookup("osgi:service/java.lang.Runnable");
}
use of org.apache.aries.mocks.BundleMock in project aries by apache.
the class ServiceRegistryContextTest method checkServiceOrderObserved.
@Test
public void checkServiceOrderObserved() throws NamingException {
BundleMock mock = new BundleMock("scooby.doo", new Properties());
Thread.currentThread().setContextClassLoader(mock.getClassLoader());
InitialContext ctx = new InitialContext();
String className = Runnable.class.getName();
Runnable t = Skeleton.newMock(Runnable.class);
Runnable t2 = Skeleton.newMock(Runnable.class);
// we don't want the default service
reg.unregister();
ServiceRegistration reg = bc.registerService(className, t, null);
ServiceRegistration reg2 = bc.registerService(className, t2, null);
Runnable r = (Runnable) ctx.lookup("osgi:service/java.lang.Runnable");
r.run();
Skeleton.getSkeleton(t).assertCalledExactNumberOfTimes(new MethodCall(Runnable.class, "run"), 1);
Skeleton.getSkeleton(t2).assertNotCalled(new MethodCall(Runnable.class, "run"));
reg.unregister();
reg2.unregister();
Hashtable<String, Object> props = new Hashtable<String, Object>();
props.put(Constants.SERVICE_RANKING, 55);
t = Skeleton.newMock(Runnable.class);
t2 = Skeleton.newMock(Runnable.class);
bc.registerService(className, t, null);
bc.registerService(className, t2, props);
r = (Runnable) ctx.lookup("osgi:service/java.lang.Runnable");
r.run();
Skeleton.getSkeleton(t).assertNotCalled(new MethodCall(Runnable.class, "run"));
Skeleton.getSkeleton(t2).assertCalledExactNumberOfTimes(new MethodCall(Runnable.class, "run"), 1);
}
use of org.apache.aries.mocks.BundleMock in project aries by apache.
the class ServiceRegistryContextTest method checkServiceListLookup.
@Test
public void checkServiceListLookup() throws NamingException {
BundleMock mock = new BundleMock("scooby.doo", new Properties());
Thread.currentThread().setContextClassLoader(mock.getClassLoader());
InitialContext ctx = new InitialContext();
String className = Runnable.class.getName();
Runnable t = Skeleton.newMock(Runnable.class);
// we don't want the default service
reg.unregister();
ServiceRegistration reg = bc.registerService(className, t, null);
ServiceRegistration reg2 = bc.registerService("java.lang.Thread", new Thread(), null);
Context ctx2 = (Context) ctx.lookup("osgi:servicelist/java.lang.Runnable");
Runnable r = (Runnable) ctx2.lookup(String.valueOf(reg.getReference().getProperty(Constants.SERVICE_ID)));
r.run();
Skeleton.getSkeleton(t).assertCalled(new MethodCall(Runnable.class, "run"));
reg.unregister();
try {
r.run();
fail("Should have received a ServiceException");
} catch (ServiceException e) {
assertEquals("service exception has the wrong type", ServiceException.UNREGISTERED, e.getType());
}
try {
ctx2.lookup(String.valueOf(reg2.getReference().getProperty(Constants.SERVICE_ID)));
fail("Expected a NameNotFoundException");
} catch (NameNotFoundException e) {
}
}
Aggregations