use of javax.naming.InitialContext in project aries by apache.
the class ServiceRegistryContextTest method checkProxyDynamism.
@Test
public void checkProxyDynamism() 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);
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();
r.run();
Skeleton.getSkeleton(t).assertCalledExactNumberOfTimes(new MethodCall(Runnable.class, "run"), 1);
Skeleton.getSkeleton(t2).assertCalledExactNumberOfTimes(new MethodCall(Runnable.class, "run"), 1);
}
use of javax.naming.InitialContext in project aries by apache.
the class ServiceRegistryContextTest method jndiLookupWithFilter.
/**
* This test checks that we can pass a filter in without things blowing up.
* Right now our mock service registry does not implement filtering, so the
* effect is the same as simpleJNDILookup, but we at least know it is not
* blowing up.
*
* @throws NamingException
*/
@Test
public void jndiLookupWithFilter() throws NamingException {
BundleMock mock = new BundleMock("scooby.doo", new Properties());
Thread.currentThread().setContextClassLoader(mock.getClassLoader());
InitialContext ctx = new InitialContext();
Object s = ctx.lookup("osgi:service/java.lang.Runnable/(rubbish=smelly)");
assertNotNull("We didn't get a service back from our lookup :(", s);
service.run();
Skeleton.getSkeleton(service).assertCalledExactNumberOfTimes(new MethodCall(Runnable.class, "run"), 1);
Skeleton.getSkeleton(mock.getBundleContext()).assertCalled(new MethodCall(BundleContext.class, "getServiceReferences", "java.lang.Runnable", "(rubbish=smelly)"));
}
use of javax.naming.InitialContext in project aries by apache.
the class BlueprintURLContextTest method testList.
/**
* Validate that list() function works for BlueprintURLContext.
* This returns an enumeration of component id -> component class name pairs
*/
@Test
public void testList() throws Exception {
InitialContext ctx = new InitialContext();
NamingEnumeration<NameClassPair> compList = ctx.list("blueprint:comp");
Set<String> expectedCompIds = new BlueprintContainerStub().getComponentIds();
while (compList.hasMore()) {
NameClassPair ncp = compList.next();
String compId = ncp.getName();
String compClass = ncp.getClassName();
if (compId.equals("comp1")) {
assertEquals("comp1 class wrong in list", SimpleComponent.class.getName(), compClass);
} else if (compId.equals("comp2")) {
assertEquals("comp2 class wrong in list", AnotherComponent.class.getName(), compClass);
}
expectedCompIds.remove(compId);
}
assertEquals("Not all expected components were found", expectedCompIds.size(), 0);
}
use of javax.naming.InitialContext in project aries by apache.
the class BlueprintURLContextTest method testListBindings.
/**
* Test BlueprintURLContext.listBindings()
* This returns an enumeration of component id -> component pairs
*/
@Test
public void testListBindings() throws Exception {
InitialContext ctx = new InitialContext();
NamingEnumeration<Binding> bindings = ctx.listBindings("blueprint:comp");
Set<String> expectedCompIds = new BlueprintContainerStub().getComponentIds();
while (bindings.hasMore()) {
Binding b = bindings.next();
String compId = b.getName();
Object component = b.getObject();
if (compId.equals("comp1")) {
SimpleComponent sc = (SimpleComponent) component;
assertEquals("comp1 message wrong", "comp1_message", sc.getIdMessage());
} else if (compId.equals("comp2")) {
AnotherComponent ac = (AnotherComponent) component;
assertEquals("comp2 message wrong", "AnotherComponent with id comp2", ac.getIdMessage());
}
expectedCompIds.remove(compId);
}
assertEquals("Not all expected components were found", expectedCompIds.size(), 0);
}
use of javax.naming.InitialContext in project aries by apache.
the class BlueprintURLContextTest method testLookupForServiceWeNeverHad.
/**
* Check that we get a NameNotFoundException if we lookup something not in the
* registry.
*
* @throws NamingException
*/
@Test(expected = NameNotFoundException.class)
public void testLookupForServiceWeNeverHad() throws NamingException {
InitialContext ctx = new InitialContext();
ctx.lookup("blueprint:comp/this.is.not.a.component");
}
Aggregations