BlueprintURLContext implements Context { @Override public NamingEnumeration<Binding> listBindings(Name name) throws NamingException { return listBindings(name.toString()); } @SuppressWarnings("unchecked")  BlueprintURLContext(Bundle callersBundle, Hashtable<?, ?> env); private  BlueprintURLContext(Bundle callersBundle, BlueprintName parentName, Map<String, Object> env); static int getGracePeriod(Bundle b); @Override Object addToEnvironment(String propName, Object propVal); @Override void bind(Name n, Object o); @Override void bind(String s, Object o); @Override void close(); @Override Name composeName(Name name, Name prefix); @Override String composeName(String name, String prefix); @Override Context createSubcontext(Name n); @Override Context createSubcontext(String s); @Override void destroySubcontext(Name n); @Override void destroySubcontext(String s); @Override Hashtable<?, ?> getEnvironment(); @Override String getNameInNamespace(); @Override NameParser getNameParser(Name n); @Override NameParser getNameParser(String s); @Override NamingEnumeration<NameClassPair> list(Name name); @Override NamingEnumeration<NameClassPair> list(String s); @Override NamingEnumeration<Binding> listBindings(Name name); @Override NamingEnumeration<Binding> listBindings(String name); @Override Object lookup(Name name); @Override Object lookup(String name); @Override Object lookupLink(Name n); @Override Object lookupLink(String s); @Override void rebind(Name n, Object o); @Override void rebind(String s, Object o); @Override Object removeFromEnvironment(String propName); @Override void rename(Name nOld, Name nNew); @Override void rename(String sOld, String sNew); @Override void unbind(Name n); @Override void unbind(String s);  }
@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); }