use of org.apache.aries.mocks.BundleMock in project aries by apache.
the class ServiceRegistryContextTest method checkServiceListList.
@Test
public void checkServiceListList() 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(className, new Thread(), null);
NamingEnumeration<NameClassPair> ne = ctx.list("osgi:servicelist/" + className);
assertTrue(ne.hasMoreElements());
NameClassPair ncp = ne.nextElement();
assertEquals(String.valueOf(reg.getReference().getProperty(Constants.SERVICE_ID)), ncp.getName());
assertTrue("Class name not correct. Was: " + ncp.getClassName(), ncp.getClassName().contains("Proxy"));
assertTrue(ne.hasMoreElements());
ncp = ne.nextElement();
assertEquals(String.valueOf(reg2.getReference().getProperty(Constants.SERVICE_ID)), ncp.getName());
assertEquals("Class name not correct.", Thread.class.getName(), ncp.getClassName());
assertFalse(ne.hasMoreElements());
}
use of org.apache.aries.mocks.BundleMock in project aries by apache.
the class ServiceRegistryContextTest method testBaseLookup.
@Test
public void testBaseLookup() throws NamingException {
BundleMock mock = new BundleMock("scooby.doo", new Properties());
Thread.currentThread().setContextClassLoader(mock.getClassLoader());
InitialContext ctx = new InitialContext();
Context ctx2 = (Context) ctx.lookup("osgi:service");
Runnable r1 = (Runnable) ctx2.lookup("java.lang.Runnable");
assertNotNull(r1);
assertTrue("expected proxied service class", r1 != service);
Runnable r2 = (Runnable) ctx.lookup("aries:services/java.lang.Runnable");
assertNotNull(r2);
assertTrue("expected non-proxied service class", r2 == service);
}
Aggregations