Search in sources :

Example 11 with Registration

use of org.opennms.core.soa.Registration in project opennms by OpenNMS.

the class DefaultServiceRegistryTest method testRegisterUnregister.

@Test
public void testRegisterUnregister() {
    MyProvider provider = new MyProvider();
    Registration registration = m_registry.register(provider, Hello.class, Goodbye.class);
    Hook hook = new Hook();
    m_registry.addRegistrationHook(hook, true);
    assertEquals(1, hook.getCount());
    Collection<Hello> hellos = m_registry.findProviders(Hello.class);
    Collection<Goodbye> goodbyes = m_registry.findProviders(Goodbye.class);
    assertEquals(1, hellos.size());
    assertEquals(1, goodbyes.size());
    assertSame(provider, hellos.iterator().next());
    assertSame(provider, goodbyes.iterator().next());
    registration.unregister();
    assertEquals(0, hook.getCount());
    hellos = m_registry.findProviders(Hello.class);
    goodbyes = m_registry.findProviders(Goodbye.class);
    assertTrue(hellos.isEmpty());
    assertTrue(goodbyes.isEmpty());
}
Also used : RegistrationHook(org.opennms.core.soa.RegistrationHook) Registration(org.opennms.core.soa.Registration) Test(org.junit.Test)

Aggregations

Registration (org.opennms.core.soa.Registration)11 Test (org.junit.Test)9 ServiceRegistry (org.opennms.core.soa.ServiceRegistry)3 MyProvider (org.opennms.core.soa.support.MyProvider)3 DirtiesContext (org.springframework.test.annotation.DirtiesContext)3 HashMap (java.util.HashMap)2 RegistrationHook (org.opennms.core.soa.RegistrationHook)2 ServiceRegistration (org.osgi.framework.ServiceRegistration)2 LinkedHashMap (java.util.LinkedHashMap)1 RegistrationListener (org.opennms.core.soa.RegistrationListener)1 BundleContext (org.osgi.framework.BundleContext)1