public void testDisposeInvoked()
throws Exception
{
final RepositoryTypeRegistry repositoryTypeRegistry = lookup(RepositoryTypeRegistry.class);
final RepositoryRegistry repositoryRegistry = lookup(RepositoryRegistry.class);
final NexusConfiguration nexusConfiguration = lookup(NexusConfiguration.class);
final TemplateManager templateManager = lookup(TemplateManager.class);
// register this
repositoryTypeRegistry.registerRepositoryTypeDescriptors(new RepositoryTypeDescriptor(Repository.class,
Nexus4807RepositoryImpl.ID, "foo"));
// load config
nexusConfiguration.loadConfiguration();
// assert we have peter not present
try {
repositoryRegistry.getRepository("peter");
Assert.fail("Peter should not be present!");
}
catch (NoSuchRepositoryException e) {
// good, it should be not present
}
// create this new repo type
final RepositoryTemplate template =
(RepositoryTemplate) templateManager.getTemplates().getTemplateById("nexus4807");
template.getConfigurableRepository().setId("peter");
template.getConfigurableRepository().setName("We all love Peter!");
final Repository repository = template.create();
// do some simple assertion
assertThat(repository.getId(), equalTo("peter"));
assertThat(repository.getName(), equalTo("We all love Peter!"));
// assert peter is here simply, by having this below not throw any exception and returning non-null
// note: by interface contract, this method never returns null: either returns value or throws exception
assertThat(repositoryRegistry.getRepository("peter"), notNullValue());
// now drop it
nexusConfiguration.deleteRepository(repository.getId());
// assert peter left the building
try {
repositoryRegistry.getRepository("peter");
Assert.fail("Peter should not be present, he just left!");