public void testSerialization() throws Exception { final BeanContextServicesSupport ctx = new BeanContextServicesSupport( null, Locale.FRANCE, false, false); final BeanContextServicesSupport ctx2 = new BeanContextServicesSupport( ctx, Locale.ITALY, true, true); BeanContextEvent event = new MockBeanContextEvent(ctx2); event.setPropagatedFrom(ctx); SerializationTest.verifySelf(event, new SerializableAssert(){ public void assertDeserialized(Serializable arg0, Serializable arg1) { BeanContextEvent e1 = (BeanContextEvent)arg0; BeanContextEvent e2 = (BeanContextEvent)arg1; assertNull((BeanContextServicesSupport)e2.getSource()); assertNotNull((BeanContextServicesSupport)e1.getSource()); assertEqualsSerially((BeanContextServicesSupport)e1.getPropagatedFrom(), (BeanContextServicesSupport)e2.getPropagatedFrom()); assertEqualsSerially(ctx, (BeanContextServicesSupport)e2.getPropagatedFrom()); } }); }
public void testSerializationComptibility() throws Exception { final BeanContextServicesSupport ctx = new BeanContextServicesSupport( null, Locale.ITALY, true, true); final BeanContextServicesSupport ctx2 = new BeanContextServicesSupport( null, Locale.CHINA, true, true); BeanContextEvent event = new MockBeanContextEvent(ctx); event.setPropagatedFrom(ctx2); SerializationTest.verifyGolden(this, event, new SerializableAssert(){ public void assertDeserialized(Serializable arg0, Serializable arg1) { BeanContextEvent e1 = (BeanContextEvent)arg0; BeanContextEvent e2 = (BeanContextEvent)arg1; assertNull((BeanContextServicesSupport)e2.getSource()); assertNotNull((BeanContextServicesSupport)e1.getSource()); assertEqualsSerially((BeanContextServicesSupport)e1.getPropagatedFrom(), (BeanContextServicesSupport)e2.getPropagatedFrom()); assertEqualsSerially(ctx2, (BeanContextServicesSupport)e2.getPropagatedFrom()); } }); }
public void testSerialization() throws IOException, ClassNotFoundException { BeanContextServicesSupport support = new BeanContextServicesSupport( null, Locale.ITALY, true, true); support .addBeanContextServicesListener(new MockBeanContextServicesListener()); support .addBeanContextServicesListener(new MockBeanContextServicesListenerS( "l2")); support .addBeanContextServicesListener(new MockBeanContextServicesListenerS( "l3")); support .addBeanContextServicesListener(new MockBeanContextServicesListener()); support.addService(Collection.class, new MockBeanContextServiceProvider()); support.addService(List.class, new MockBeanContextServiceProviderS("p1")); support .addService(Set.class, new MockBeanContextServiceProviderS("p2")); support.addService(Map.class, new MockBeanContextServiceProvider()); assertEqualsSerially(support, (BeanContextServicesSupport) SerializationTester .getDeserilizedObject(support)); }
public void test_serviceRevoked_LBeanContextServiceRevokedEvent() { BeanContextServicesSupport support = new BeanContextServicesSupport(); support.add(new MySupport()); support.addBeanContextServicesListener(new MyListener()); Class c = Object.class; support.addService(c, new MyProvider()); BeanContextServiceRevokedEvent revokeEvent = new BeanContextServiceRevokedEvent( support, c, false); support.serviceRevoked(revokeEvent); assertEquals(0, serviceRevoked); assertEquals(2, serviceAvailable); }
public void test_serviceAvailable_LBeanContextServiceRevokedEvent() { BeanContextServicesSupport support = new BeanContextServicesSupport(); support.add(new MySupport()); support.addBeanContextServicesListener(new MyListener()); Class c = Object.class; support.addService(c, new MyProvider()); BeanContextServiceAvailableEvent availableEvent = new BeanContextServiceAvailableEvent( support, c); support.serviceAvailable(availableEvent); assertEquals(0, serviceRevoked); assertEquals(2, serviceAvailable); }
/** * @see java.beans.beancontext.BeanContextServicesSupport#getBeanContextServicesPeer() */ public Result testGetBeanContextServicesPeer() throws Exception { context = new BeanContextServicesSupport(); serviceBean = new ServiceBean(); // Adding the component context.add(serviceBean); // Add service to the context if ((context.getBeanContextServicesPeer() instanceof BeanContextServicesSupport)) return passed(); else return failed("method testGetBeanContextServicesPeer"); }
/** * @see java.beans.beancontext.BeanContextServicesSupport#getCurrentServiceSelectors() */ public Result testGetCurrentServiceSelectors() throws Exception { context = new BeanContextServicesSupport(); serviceBean = new ServiceBean(); // Adding the component context.add(serviceBean); // Listen for new services context.addBeanContextServicesListener(serviceBean); TestServiceProvider provider = new TestServiceProvider(); // Add service to the context context.addService(TestCounter.class, provider); if ((context.getCurrentServiceSelectors(TestCounter.class) instanceof Iterator)) return passed(); else return failed("method testGetCurrentServiceSelectors"); }
/** * @see java.beans.beancontext.BeanContextServicesSupport#getService() */ public Result testGetService() throws Exception { context = new BeanContextServicesSupport(); serviceBean = new ServiceBean(); // Adding the component context.add(serviceBean); // Listen for new services context.addBeanContextServicesListener(serviceBean); TestServiceProvider provider = new TestServiceProvider(); // Add service to the context context.addService(TestCounter.class, provider); if ((serviceBean.service instanceof TestCounter)) return passed(); else return failed("method testGetService"); }
/** * @see java.beans.beancontext.BeanContextServicesSupport#addBeanContextServicesListener() */ public Result testAddBeanContextServicesListenerException() throws Exception { context = new BeanContextServicesSupport(); serviceBean = null; try { // Listen for new service context.addBeanContextServicesListener(serviceBean); } catch (NullPointerException e) { return passed(); } return failed("testAddBeanContextServicesListenerException"); }
/** * @see java.beans.beancontext.BeanContextServicesSupport#getService() */ public Result testGetServiceException() throws Exception { BeanContextChild child = null; Object requestor = null; Class serviceClass = null; Object serviceSelector = null; BeanContextServiceRevokedListener bcsrl = null; BeanContextServicesSupport context = new BeanContextServicesSupport(); serviceBean = null; try { context.getService(child, requestor ,serviceClass,serviceSelector,bcsrl); } catch (NullPointerException e) { return passed(); } return failed("testGetServiceException"); }
/** * @see java.beans.beancontext.BeanContextServicesSupport#releaseService() */ public Result testReleaseServiceException() throws Exception { BeanContextChild child = null; Object requestor = null; Object service = null; BeanContextServicesSupport context = new BeanContextServicesSupport(); serviceBean = null; try { context.releaseService(child, requestor ,service); } catch (NullPointerException e) { return passed(); } return failed("testGetServiceException"); }
/** * @see java.beans.beancontext.BeanContextServiceAvailableEvent#getCurrentServiceSelectors() * @see java.beans.beancontext.BeanContextServicesSupport#hasService() */ public Result testGetCurrentServiceSelectors() throws Exception { context = new BeanContextServicesSupport(); serviceBean = new ServiceBean(); // Add service to the context context.add(serviceBean); // Listen for new services context.addBeanContextServicesListener(serviceBean); TestServiceProvider provider = new TestServiceProvider(); // Add service to the context context.addService(TestCounter.class, provider); if ((context.hasService(TestCounter.class)) || (serviceBean.bcsae.getCurrentServiceSelectors() instanceof java.util.Iterator)) return passed(); else return failed("method getCurrentServiceSelectors"); }
public static void main(String[] args) { for (int i = 0; i < 10; i++) { BeanContextServices container = new BeanContextServicesSupport(); BeanContextChild ms1 = new MyService1(); BeanContextServices ms2 = new MyService2(); BeanContextChild mb = new MyBean(); container.add(ms1); container.add(ms2); ms2.add(mb); // exception thrown here container.remove(ms2); } }
protected void initializeBeanContextResources() { super.initializeBeanContextResources(); BeanContextServicesSupport bcs = (BeanContextServicesSupport) getBeanContext(); try { bcs.getService(this, this, MyService1.class, null, this); } catch (Exception exception) { exception.printStackTrace(); } bcs.addService(this.getClass(), this); }
public void test() { BeanContextServiceProvider bcsp = new BCSP(); BCSS serviceSupport = new BCSS(new BeanContextServicesSupport()); assertTrue("Expected first addService to return true", serviceSupport .addService(Boolean.TYPE, bcsp, false)); assertFalse("Expected second addService to return false", serviceSupport .addService(Boolean.TYPE, bcsp, false)); }
public void testServiceRevoked() { MockChildBeanContextServicesSupport mockChildBeanContextServicesSupport = new MockChildBeanContextServicesSupport(); BeanContextServicesSupport beanContextServicesSupport = new BeanContextServicesSupport(); beanContextServicesSupport.add(mockChildBeanContextServicesSupport); BeanContextServiceRevokedEvent beanContextServiceRevokedEvent = new BeanContextServiceRevokedEvent(new BeanContextServicesSupport(), Collection.class,false); beanContextServicesSupport.serviceRevoked(beanContextServiceRevokedEvent); assertTrue(mockChildBeanContextServicesSupport.revokeCalled); }