@Test
public void testReconfigureMessaging_withAgentConfigurationFile() throws IOException {

	// Prepare
	File karafEtc =  this.folder.newFolder();
	final File msgConf = new File( karafEtc, "net.roboconf.messaging.rabbitmq.cfg" );
	final File agentConf = new File( karafEtc, Constants.KARAF_CFG_FILE_AGENT );
	Properties props = new Properties();
	props.setProperty( "key", "value" );
	props.setProperty( "something", "else" );
	props.setProperty( Constants.MESSAGING_TYPE, "http" );
	Utils.writePropertiesFile( props, agentConf );
	// Execute
	Map<String,String> msgData = new HashMap<> ();
	msgData.put( MessagingConstants.MESSAGING_TYPE_PROPERTY, "rabbitmq" );
	msgData.put("net.roboconf.messaging.rabbitmq.server.ip", "rabbit-server");
	msgData.put("net.roboconf.messaging.rabbitmq.server.username", "user1");
	msgData.put("net.roboconf.messaging.rabbitmq.server.password", "password1");
	msgData.put("test", "issue #779");
	Assert.assertFalse( msgConf.exists());
	Assert.assertTrue( agentConf.exists());
	this.userDataHelper.reconfigureMessaging( karafEtc.getAbsolutePath(), msgData);
	// Check
	Assert.assertTrue( msgConf.exists());
	Assert.assertTrue( agentConf.exists());
	Properties p = Utils.readPropertiesFile( msgConf );
	Assert.assertEquals( 4, p.keySet().size());
	String val = p.getProperty("net.roboconf.messaging.rabbitmq.server.ip");
	Assert.assertEquals(val, "rabbit-server");
	val = p.getProperty("net.roboconf.messaging.rabbitmq.server.username");
	Assert.assertEquals(val, "user1");
	val = p.getProperty("net.roboconf.messaging.rabbitmq.server.password");
	Assert.assertEquals(val, "password1");
	val = p.getProperty("test");
	Assert.assertEquals(val, "issue #779");
	p = Utils.readPropertiesFile( agentConf );
	Assert.assertEquals( 3, p.size());
	Assert.assertEquals( "rabbitmq", p.get( Constants.MESSAGING_TYPE ));
	Assert.assertEquals( "else", p.get( "something" ));
	Assert.assertEquals( "value", p.get( "key" ));
	// Verify we do not remove all the properties when we write new ones (#779)
	msgData.remove( "test" );
	msgData.put("net.roboconf.messaging.rabbitmq.server.username", "user2");
	this.userDataHelper.reconfigureMessaging( karafEtc.getAbsolutePath(), msgData);
	p = Utils.readPropertiesFile( msgConf );
	Assert.assertEquals( 4, p.keySet().size());
	val = p.getProperty("net.roboconf.messaging.rabbitmq.server.ip");
	Assert.assertEquals(val, "rabbit-server");
	val = p.getProperty("net.roboconf.messaging.rabbitmq.server.username");
	Assert.assertEquals(val, "user2");
	val = p.getProperty("net.roboconf.messaging.rabbitmq.server.password");
	Assert.assertEquals(val, "password1");
	val = p.getProperty("test");
	Assert.assertEquals(val, "issue #779");
}