RabbitMqClientFactory implements IMessagingClientFactory { public void setConfiguration( Dictionary<?,?> properties ) { final List<String> propertiesToSkip = Arrays.asList( "component", "felix.fileinstall.filename" ); Map<String,String> map = new LinkedHashMap<> (); for( Enumeration<?> en = properties.keys(); en.hasMoreElements(); ) { Object key = en.nextElement(); String keyAsString = String.valueOf( key ); if( propertiesToSkip.contains( keyAsString )) continue; Object value = properties.get( key ); map.put( keyAsString, String.valueOf( value )); } map.put( MessagingConstants.MESSAGING_TYPE_PROPERTY, FACTORY_RABBITMQ ); setConfiguration( map ); }  void reconfigure(); void stop(); @Override String getType(); @Override IMessagingClient createClient( final ReconfigurableClient<?> parent ); void setConfiguration( Dictionary<?,?> properties ); @Override boolean setConfiguration( final Map<String,String> configuration );  }
@Test public void testSetConfiguration() { Map<String,String> map = new HashMap<>( 0 ); Assert.assertFalse( this.factory.setConfiguration( map )); map.put( MessagingConstants.MESSAGING_TYPE_PROPERTY, "whatever" ); Assert.assertFalse( this.factory.setConfiguration( map )); map.put( MessagingConstants.MESSAGING_TYPE_PROPERTY, FACTORY_RABBITMQ ); Assert.assertTrue( this.factory.setConfiguration( map )); Assert.assertEquals( DEFAULT_IP, this.factory.configuration.get( RABBITMQ_SERVER_IP )); Assert.assertEquals( GUEST, this.factory.configuration.get( RABBITMQ_SERVER_USERNAME )); Assert.assertEquals( GUEST, this.factory.configuration.get( RABBITMQ_SERVER_PASSWORD )); map.put( RABBITMQ_SERVER_IP, "127.0.0.1" ); map.put( RABBITMQ_SERVER_USERNAME, "bob" ); map.put( RABBITMQ_SERVER_PASSWORD, "2" ); Assert.assertTrue( this.factory.setConfiguration( map )); Assert.assertEquals( "127.0.0.1", this.factory.configuration.get( RABBITMQ_SERVER_IP )); Assert.assertEquals( "bob", this.factory.configuration.get( RABBITMQ_SERVER_USERNAME )); Assert.assertEquals( "2", this.factory.configuration.get( RABBITMQ_SERVER_PASSWORD )); }
@Test @SuppressWarnings({ "rawtypes", "unchecked" }) public void testSetConfiguration_dictionary() { Dictionary dictionary = new Hashtable(); this.factory.setConfiguration( dictionary ); dictionary.put( MessagingConstants.MESSAGING_TYPE_PROPERTY, "whatever" ); this.factory.setConfiguration( dictionary ); dictionary.put( MessagingConstants.MESSAGING_TYPE_PROPERTY, FACTORY_RABBITMQ ); this.factory.setConfiguration( dictionary ); Assert.assertEquals( DEFAULT_IP, this.factory.configuration.get( RABBITMQ_SERVER_IP )); Assert.assertEquals( GUEST, this.factory.configuration.get( RABBITMQ_SERVER_USERNAME )); Assert.assertEquals( GUEST, this.factory.configuration.get( RABBITMQ_SERVER_PASSWORD )); dictionary.put( RABBITMQ_SERVER_IP, "127.0.0.1" ); dictionary.put( RABBITMQ_SERVER_USERNAME, "bob" ); dictionary.put( RABBITMQ_SERVER_PASSWORD, "2" ); dictionary.put( "felix.fileinstall.filename", "sth" ); this.factory.setConfiguration( dictionary ); Assert.assertEquals( "127.0.0.1", this.factory.configuration.get( RABBITMQ_SERVER_IP )); Assert.assertEquals( "bob", this.factory.configuration.get( RABBITMQ_SERVER_USERNAME )); Assert.assertEquals( "2", this.factory.configuration.get( RABBITMQ_SERVER_PASSWORD )); Assert.assertFalse( this.factory.configuration.containsKey( "felix.fileinstall.filename" )); }