@Test
 public void testBeanNameAttrToServiceBeanNameProperty() throws Exception {
   OsgiServiceProxyFactoryBean factory =
       (OsgiServiceProxyFactoryBean) appContext.getBean("&importerWithBeanName");
   Object obj = TestUtils.getFieldValue(factory, "serviceBeanName");
   assertEquals("bean-name attr hasn't been properly parsed", "someBean", obj);
 }
  @Test
  public void testMultipleInterfaces() throws Exception {
    OsgiServiceProxyFactoryBean factory =
        (OsgiServiceProxyFactoryBean) appContext.getBean("&multi-interfaces");
    Class<?>[] intfs = (Class[]) TestUtils.getFieldValue(factory, "interfaces");
    assertNotNull(intfs);
    assertEquals(2, intfs.length);

    assertTrue(Arrays.equals(new Class<?>[] {Serializable.class, Externalizable.class}, intfs));
  }
  @Test
  public void testSimpleReference() throws Exception {
    Object factoryBean = appContext.getBean("&serializable");

    assertTrue(factoryBean instanceof OsgiServiceProxyFactoryBean);
    OsgiServiceProxyFactoryBean proxyFactory = (OsgiServiceProxyFactoryBean) factoryBean;

    Class<?>[] intfs = (Class[]) TestUtils.getFieldValue(proxyFactory, "interfaces");

    assertEquals(1, intfs.length);
    assertSame(Serializable.class, intfs[0]);

    // get the factory product
    Object bean = appContext.getBean("serializable");
    assertTrue(bean instanceof Serializable);
    assertTrue(Proxy.isProxyClass(bean.getClass()));
  }
  @Test
  public void testFullReference() throws Exception {
    OsgiServiceProxyFactoryBean factory =
        (OsgiServiceProxyFactoryBean) appContext.getBean("&full-options");
    factory.getObject(); // required to initialise proxy and hook
    // listeners into the binding process

    OsgiServiceLifecycleListener[] listeners =
        (OsgiServiceLifecycleListener[]) TestUtils.getFieldValue(factory, "listeners");
    assertNotNull(listeners);
    assertEquals(5, listeners.length);

    assertEquals(
        "already registered service should have been discovered", 4, DummyListener.BIND_CALLS);
    assertEquals(0, DummyListener.UNBIND_CALLS);

    listeners[1].bind(null, null);

    assertEquals(6, DummyListener.BIND_CALLS);

    listeners[1].unbind(null, null);
    assertEquals(2, DummyListener.UNBIND_CALLS);

    assertEquals(1, DummyListenerServiceSignature.BIND_CALLS);
    listeners[4].bind(null, null);
    assertEquals(2, DummyListenerServiceSignature.BIND_CALLS);

    assertEquals(0, DummyListenerServiceSignature.UNBIND_CALLS);
    listeners[4].unbind(null, null);
    assertEquals(1, DummyListenerServiceSignature.UNBIND_CALLS);

    assertEquals(1, DummyListenerServiceSignature2.BIND_CALLS);
    listeners[3].bind(null, null);
    assertEquals(2, DummyListenerServiceSignature2.BIND_CALLS);

    assertEquals(0, DummyListenerServiceSignature2.UNBIND_CALLS);
    listeners[3].unbind(null, null);
    assertEquals(1, DummyListenerServiceSignature2.UNBIND_CALLS);
  }