GBeanData gbean = buildGBeanData("name", "test", MockGBean.getGBeanInfo());
gbean.setAttribute("name", "Test");
gbean.setAttribute("finalInt", new Integer(123));
kernel.loadGBean(gbean, myCl);
kernel.startGBean(gbean.getAbstractName());
ProxyManager mgr = kernel.getProxyManager();
Object test = mgr.createProxy(gbean.getAbstractName(), myCl);
assertTrue(test instanceof MockEndpoint);
assertTrue(test instanceof MockParentInterface1);
assertTrue(test instanceof MockParentInterface2);
assertTrue(test instanceof MockChildInterface1);
assertTrue(test instanceof MockChildInterface2);
assertFalse(test instanceof Comparable);
((MockEndpoint)test).doNothing();
assertEquals("Foo", ((MockEndpoint)test).echo("Foo"));
((MockParentInterface1)test).setValue("Foo");
assertEquals("Foo", ((MockParentInterface1)test).getValue());
((MockParentInterface1)test).setMutableInt(6);
assertEquals(6, ((MockParentInterface1)test).getMutableInt());
((MockParentInterface2)test).doNothing();
assertEquals("Foo", ((MockParentInterface2)test).echo("Foo"));
((MockParentInterface2)test).setValue("Foo");
assertEquals("Foo", ((MockParentInterface2)test).getValue());
((MockChildInterface1)test).getFinalInt();
((MockChildInterface2)test).doNothing();
assertEquals("Foo", ((MockChildInterface2)test).doSomething("Foo"));
test = mgr.createProxy(gbean.getAbstractName(), MockEndpoint.class);
assertTrue(test instanceof MockEndpoint);
assertTrue(test instanceof MockParentInterface1);
assertTrue(test instanceof MockParentInterface2);
assertTrue(test instanceof MockChildInterface1);
assertTrue(test instanceof MockChildInterface2);
assertFalse(test instanceof Comparable);
ProxyFactory proxyFactory;
proxyFactory = mgr.createProxyFactory(new Class[]{MockEndpoint.class, MockParentInterface2.class, MockChildInterface2.class}, myCl);
test = proxyFactory.createProxy(gbean.getAbstractName());
assertTrue(test instanceof MockEndpoint);
assertTrue(test instanceof MockParentInterface1);
assertTrue(test instanceof MockParentInterface2);
assertTrue(test instanceof MockChildInterface1);
assertTrue(test instanceof MockChildInterface2);
assertFalse(test instanceof Comparable);
proxyFactory = mgr.createProxyFactory(new Class[]{MockEndpoint.class, MockParentInterface1.class, MockChildInterface1.class}, myCl);
test = proxyFactory.createProxy(gbean.getAbstractName());
assertTrue(test instanceof MockEndpoint);
assertTrue(test instanceof MockParentInterface1);
assertFalse(test instanceof MockParentInterface2);
assertTrue(test instanceof MockChildInterface1);
assertFalse(test instanceof MockChildInterface2);
assertFalse(test instanceof Comparable);
proxyFactory = mgr.createProxyFactory(new Class[]{MockEndpoint.class, MockParentInterface1.class, MockChildInterface1.class, Comparable.class}, myCl);
test = proxyFactory.createProxy(gbean.getAbstractName());
assertTrue(test instanceof MockEndpoint);
assertTrue(test instanceof MockParentInterface1);
assertFalse(test instanceof MockParentInterface2);
assertTrue(test instanceof MockChildInterface1);
assertFalse(test instanceof MockChildInterface2);
proxyFactory = mgr.createProxyFactory(new Class[]{MockParentInterface1.class, MockChildInterface1.class, Comparable.class}, myCl);
test = proxyFactory.createProxy(gbean.getAbstractName());
assertFalse(test instanceof MockEndpoint);
assertTrue(test instanceof MockParentInterface1);
assertFalse(test instanceof MockParentInterface2);
assertTrue(test instanceof MockChildInterface1);
assertFalse(test instanceof MockChildInterface2);
proxyFactory = mgr.createProxyFactory(new Class[]{MockEndpoint.class, Comparable.class}, myCl);
test = proxyFactory.createProxy(gbean.getAbstractName());
assertTrue(test instanceof MockEndpoint);
assertFalse(test instanceof MockParentInterface1);
assertFalse(test instanceof MockParentInterface2);
assertFalse(test instanceof MockChildInterface1);
assertFalse(test instanceof MockChildInterface2);
proxyFactory = mgr.createProxyFactory(new Class[]{Comparable.class}, myCl);
test = proxyFactory.createProxy(gbean.getAbstractName());
try {
proxyFactory = mgr.createProxyFactory(null, myCl);
fail();
} catch (NullPointerException e) {
}
try {
proxyFactory = mgr.createProxyFactory(new Class[0], myCl);
fail();
} catch (IllegalArgumentException e) {
}
try {
// two non-assibnable classes
test = mgr.createProxyFactory(new Class[]{MockGBean.class, String.class}, cl).createProxy(gbean.getAbstractName());
fail();
} catch (IllegalArgumentException e) {
}
}