use of org.apache.aries.unittest.mocks.MethodCall 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) {
}
}
use of org.apache.aries.unittest.mocks.MethodCall in project aries by apache.
the class InitialContextTest method testLookupWithICF.
@Test
public void testLookupWithICF() throws NamingException {
InitialContextFactory icf = Skeleton.newMock(InitialContextFactory.class);
bc.registerService(new String[] { InitialContextFactory.class.getName(), icf.getClass().getName() }, icf, (Dictionary) new Properties());
Skeleton.getSkeleton(icf).setReturnValue(new MethodCall(Context.class, "lookup", "/"), Skeleton.newMock(Context.class));
Properties props = new Properties();
props.put(Context.INITIAL_CONTEXT_FACTORY, icf.getClass().getName());
props.put(JNDIConstants.BUNDLE_CONTEXT, bc);
InitialContext ctx = new InitialContext(props);
Context namingCtx = (Context) ctx.lookup("/");
assertTrue("Context returned isn't the raw naming context: " + namingCtx, Skeleton.isSkeleton(namingCtx));
}
use of org.apache.aries.unittest.mocks.MethodCall in project aries by apache.
the class InitialContextTest method testLookupWithoutICFButWithURLLookup.
@Test
public void testLookupWithoutICFButWithURLLookup() throws NamingException {
ObjectFactory factory = Skeleton.newMock(ObjectFactory.class);
Context ctx = Skeleton.newMock(Context.class);
Skeleton.getSkeleton(factory).setReturnValue(new MethodCall(ObjectFactory.class, "getObjectInstance", Object.class, Name.class, Context.class, Hashtable.class), ctx);
Skeleton.getSkeleton(ctx).setReturnValue(new MethodCall(Context.class, "lookup", String.class), "someText");
Properties props = new Properties();
props.put(JNDIConstants.JNDI_URLSCHEME, "testURL");
bc.registerService(ObjectFactory.class.getName(), factory, (Dictionary) props);
props = new Properties();
props.put(JNDIConstants.BUNDLE_CONTEXT, bc);
InitialContext initialCtx = new InitialContext(props);
Object someObject = initialCtx.lookup("testURL:somedata");
assertEquals("Expected to be given a string, but got something else.", "someText", someObject);
}
use of org.apache.aries.unittest.mocks.MethodCall in project aries by apache.
the class RecursiveBundleTrackerTest method composite.
private CompositeBundle composite(String symbolicName, String version) {
CompositeBundle cb = Skeleton.newMock(CompositeBundle.class);
Skeleton cbSkel = Skeleton.getSkeleton(cb);
cbSkel.setReturnValue(new MethodCall(CompositeBundle.class, "getSymbolicName"), symbolicName);
cbSkel.setReturnValue(new MethodCall(CompositeBundle.class, "getVersion"), new Version(version));
return cb;
}
use of org.apache.aries.unittest.mocks.MethodCall in project aries by apache.
the class RecursiveBundleTrackerTest method setup.
@Before
public void setup() {
context = Skeleton.newMock(BundleContext.class);
Skeleton.getSkeleton(context).setReturnValue(new MethodCall(BundleContext.class, "getServiceReference", "org.osgi.service.framework.CompositeBundleFactory"), Skeleton.newMock(ServiceReference.class));
}
Aggregations