}
}
public void testRegisterUnregister() throws Exception
{
FileDeploymentManager fdm = new FileDeploymentManager(Long.MAX_VALUE);
fdm.start();
String filename1 = "fdm_test_file.xml1";
String filename2 = "fdm_test_file.xml2";
String filename3 = "fdm_test_file.xml3";
File file1 = new File("tests/tmpfiles/" + filename1);
File file2 = new File("tests/tmpfiles/" + filename2);
File file3 = new File("tests/tmpfiles/" + filename3);
file1.createNewFile();
file2.createNewFile();
file3.createNewFile();
FakeDeployer deployer1 = new FakeDeployer(filename1);
FakeDeployer deployer2 = new FakeDeployer(filename2);
FakeDeployer deployer3 = new FakeDeployer(filename3);
FakeDeployer deployer4 = new FakeDeployer(filename3); // Can have multiple deployers on the same file
try
{
URL url1 = file1.toURI().toURL();
deployer1.deploy(url1);
URL url2 = file2.toURI().toURL();
deployer2.deploy(url2);
URL url3 = file3.toURI().toURL();
deployer3.deploy(url3);
deployer4.deploy(url3);
fdm.registerDeployer(deployer1);
fdm.registerDeployer(deployer2);
fdm.registerDeployer(deployer3);
fdm.registerDeployer(deployer4);
Assert.assertEquals(4, fdm.getDeployers().size());
Assert.assertTrue(fdm.getDeployers().contains(deployer1));
Assert.assertTrue(fdm.getDeployers().contains(deployer2));
Assert.assertTrue(fdm.getDeployers().contains(deployer3));
Assert.assertTrue(fdm.getDeployers().contains(deployer4));
Assert.assertEquals(4, fdm.getDeployed().size());
Assert.assertEquals(file1.toURI().toURL(), deployer1.deployedUrl);
Assert.assertEquals(file2.toURI().toURL(), deployer2.deployedUrl);
Assert.assertEquals(file3.toURI().toURL(), deployer3.deployedUrl);
Assert.assertEquals(file3.toURI().toURL(), deployer4.deployedUrl);
// Registering same again should do nothing
fdm.registerDeployer(deployer1);
Assert.assertEquals(4, fdm.getDeployers().size());
Assert.assertTrue(fdm.getDeployers().contains(deployer1));
Assert.assertTrue(fdm.getDeployers().contains(deployer2));
Assert.assertTrue(fdm.getDeployers().contains(deployer3));
Assert.assertTrue(fdm.getDeployers().contains(deployer4));
Assert.assertEquals(4, fdm.getDeployed().size());
fdm.unregisterDeployer(deployer1);
Assert.assertEquals(3, fdm.getDeployers().size());
Assert.assertTrue(fdm.getDeployers().contains(deployer2));
Assert.assertTrue(fdm.getDeployers().contains(deployer3));
Assert.assertTrue(fdm.getDeployers().contains(deployer4));
Assert.assertEquals(3, fdm.getDeployed().size());
fdm.unregisterDeployer(deployer2);
fdm.unregisterDeployer(deployer3);
Assert.assertEquals(1, fdm.getDeployers().size());
Assert.assertTrue(fdm.getDeployers().contains(deployer4));
Assert.assertEquals(1, fdm.getDeployed().size());
fdm.unregisterDeployer(deployer4);
Assert.assertEquals(0, fdm.getDeployers().size());
Assert.assertEquals(0, fdm.getDeployed().size());
// Now unregister again - should do nothing
fdm.unregisterDeployer(deployer1);
Assert.assertEquals(0, fdm.getDeployers().size());
Assert.assertEquals(0, fdm.getDeployed().size());
}
finally
{
file1.delete();
file2.delete();
file3.delete();
}
fdm.stop();
}