MgcpEndpointManager implements MgcpEndpointObserver, MgcpMessageObserver, MgcpMessageSubject { public void installProvider(MgcpEndpointProvider<?> provider) throws IllegalArgumentException { MgcpEndpointProvider<?> old = this.providers.putIfAbsent(provider.getNamespace(), provider); if (old != null) { throw new IllegalArgumentException("Provider for namespace " + provider.getNamespace() + "already exists."); } else { if (log.isInfoEnabled()) { log.info("Installed MGCP Endpoint Provider for namespace " + provider.getNamespace()); } } } MgcpEndpointManager(); void installProvider(MgcpEndpointProvider<?> provider); void uninstallProvider(String namespace); boolean supportsNamespace(String namespace); MgcpEndpoint registerEndpoint(String namespace); MgcpEndpoint getEndpoint(String endpointId); void unregisterEndpoint(String endpointId); @Override void onMessage(InetSocketAddress from, InetSocketAddress to, MgcpMessage message, MessageDirection direction); @Override void observe(MgcpMessageObserver observer); @Override void forget(MgcpMessageObserver observer); @Override void notify(Object originator, InetSocketAddress from, InetSocketAddress to, MgcpMessage message, MessageDirection direction); @Override void onEndpointStateChanged(MgcpEndpoint endpoint, MgcpEndpointState state);  }
@Test public void testInstallProvider() { MgcpEndpointManager endpointManager = new MgcpEndpointManager(); AbstractMgcpEndpointProvider<?> bridgeProvider = mock(AbstractMgcpEndpointProvider.class); AbstractMgcpEndpointProvider<?> ivrProvider = mock(AbstractMgcpEndpointProvider.class); when(bridgeProvider.getNamespace()).thenReturn(NAMESPACE_BRIDGE); when(ivrProvider.getNamespace()).thenReturn(NAMESPACE_IVR); endpointManager.installProvider(bridgeProvider); endpointManager.installProvider(ivrProvider); assertTrue(endpointManager.supportsNamespace(NAMESPACE_BRIDGE)); assertTrue(endpointManager.supportsNamespace(NAMESPACE_IVR)); assertFalse(endpointManager.supportsNamespace(NAMESPACE_CNF)); }
@Test(expected = IllegalArgumentException.class) public void testInstallDuplicateProvider() { MgcpEndpointManager endpointManager = new MgcpEndpointManager(); AbstractMgcpEndpointProvider<?> bridgeProvider1 = mock(AbstractMgcpEndpointProvider.class); AbstractMgcpEndpointProvider<?> bridgeProvider2 = mock(AbstractMgcpEndpointProvider.class); when(bridgeProvider1.getNamespace()).thenReturn(NAMESPACE_BRIDGE); when(bridgeProvider2.getNamespace()).thenReturn(NAMESPACE_BRIDGE); endpointManager.installProvider(bridgeProvider1); endpointManager.installProvider(bridgeProvider2); }