@Test
public void testFindScriptResourcesForAgent() throws Exception {

	// Precondition: all the right scripts were copied in the target directory.
	// Prepare our resources
	Properties props = new Properties();
	props.setProperty( "id", "tid1" );
	props.setProperty( "handler", "h" );
	File propsFile = this.folder.newFile( "my-target.properties" );
	Utils.writePropertiesFile( props, propsFile );
	TestApplication app = new TestApplication();
	String targetId1 = this.mngr.createTarget( propsFile, app.getTemplate());
	String targetId2 = this.mngr.createTarget( "id: tid2\nhandler: h" );
	File dir1 = new File( this.configurationMngr.getWorkingDirectory(), ConfigurationUtils.TARGETS + "/" + targetId1 + "/" + Constants.PROJECT_SUB_DIR_SCRIPTS );
	File dir2 = new File( this.configurationMngr.getWorkingDirectory(), ConfigurationUtils.TARGETS + "/" + targetId2 + "/" + Constants.PROJECT_SUB_DIR_SCRIPTS );
	Assert.assertTrue( new File( dir1, "sub" ).mkdirs());
	Assert.assertTrue( new File( dir2, "sub" ).mkdirs());
	Utils.writeStringInto( "#!/bin/bash\necho Bonjour le monde cruel > toto.txt", new File( dir1, Constants.SCOPED_SCRIPT_AT_AGENT_SUFFIX + "sh" ));
	Utils.writeStringInto( "#!/bin/bash\necho Bonjour le monde cruel > toto.txt", new File( dir1, "sub/whatever.sh" ));
	Utils.writeStringInto( "#!/bin/bash\necho Bonjour le monde cruel > toto.txt", new File( dir1, "sub/" + Constants.LOCAL_RESOURCE_PREFIX + "whatever.sh" ));
	Utils.writeStringInto( "#!/bin/bash\necho Bonjour le monde cruel > toto.txt", new File( dir1, "some-properties-for-whatever.properties" ));
	Utils.writeStringInto( "#!/bin/bash\necho Bonjour le monde cruel > toto.txt", new File( dir1, "sub/properties-for-whatever.properties" ));
	Utils.writeStringInto( "#!/bin/bash\necho touch toto.txt", new File( dir2, "toto-script.py" ));
	// Associate the application with the first target ID
	this.mngr.associateTargetWith( targetId1, app, null );
	Map<String,byte[]> resources = this.mngr.findScriptResourcesForAgent( targetId1 );
	Assert.assertEquals( 4, resources.size());
	Assert.assertTrue( resources.containsKey( Constants.SCOPED_SCRIPT_AT_AGENT_SUFFIX + "sh" ));
	Assert.assertTrue( resources.containsKey( "sub/whatever.sh" ));
	Assert.assertTrue( resources.containsKey( "some-properties-for-whatever.properties" ));
	Assert.assertTrue( resources.containsKey( "sub/properties-for-whatever.properties" ));
	Map<String,byte[]> resourcesByInst = this.mngr.findScriptResourcesForAgent( app, app.getMySqlVm());
	Assert.assertEquals( resources.keySet(), resourcesByInst.keySet());
	// Change the target for the scoped instance
	this.mngr.associateTargetWith( targetId2, app, InstanceHelpers.computeInstancePath( app.getMySqlVm()));
	resources = this.mngr.findScriptResourcesForAgent( targetId1 );
	Assert.assertEquals( 4, resources.size());
	Assert.assertTrue( resources.containsKey( Constants.SCOPED_SCRIPT_AT_AGENT_SUFFIX + "sh" ));
	Assert.assertTrue( resources.containsKey( "sub/whatever.sh" ));
	Assert.assertTrue( resources.containsKey( "some-properties-for-whatever.properties" ));
	Assert.assertTrue( resources.containsKey( "sub/properties-for-whatever.properties" ));
	resourcesByInst = this.mngr.findScriptResourcesForAgent( app, app.getMySqlVm());
	Assert.assertEquals( 1, resourcesByInst.size());
	Assert.assertTrue( resourcesByInst.containsKey( "toto-script.py" ));
}