platform = discoverPlatform();
}
protected void testUpgrade(String testMethod, ApacheTestConfiguration testConfiguration) throws Throwable {
String testId = this.getClass().getSimpleName() + "#" + testMethod;
final ApacheTestSetup setup = new ApacheTestSetup(testId, testConfiguration.configurationName, context,
apacheResourceTypes);
boolean testFailed = false;
try {
String[] configFiles = Arrays.copyOf(testConfiguration.apacheConfigurationFiles, testConfiguration.apacheConfigurationFiles.length + 1);
configFiles[testConfiguration.apacheConfigurationFiles.length] = "/snmpd.conf";
setup.withInventoryFrom(testConfiguration.inventoryFile)
.withPlatformResource(platform).withDefaultExpectations().withDefaultOverrides(testConfiguration.defaultOverrides)
.withApacheSetup().withConfigurationFiles(configFiles)
.withServerRoot(testConfiguration.serverRoot).withExePath(testConfiguration.binPath);
testConfiguration.beforeTestSetup(setup);
LOG.debug("---------------------------------------------------------- Starting the upgrade test for: "
+ testId);
LOG.debug("Deployment configuration: " + setup.getDeploymentConfig());
setup.setup();
testConfiguration.beforePluginContainerStart(setup);
startConfiguredPluginContainer();
testConfiguration.beforeTests(setup);
//ok, now we should see the resources upgraded in the fake server inventory.
ResourceType serverResourceType = apacheResourceTypes.findByName("Apache HTTP Server");
ResourceType vhostResourceType = apacheResourceTypes.findByName("Apache Virtual Host");
Set<Resource> servers = setup.getFakeInventory().findResourcesByTypeAndStatus(serverResourceType, InventoryStatus.COMMITTED);
assertEquals(servers.size(), 1, "There should be exactly one apache server discovered.");
Resource server = servers.iterator().next();
String expectedResourceKey = ApacheServerDiscoveryComponent.formatResourceKey(testConfiguration.serverRoot, testConfiguration.serverRoot
+ "/conf/httpd.conf");
assertEquals(server.getResourceKey(), expectedResourceKey,
"The server resource key doesn't seem to be upgraded.");
Set<Resource> vhosts = setup.getFakeInventory().findResourcesByTypeAndStatus(vhostResourceType, InventoryStatus.COMMITTED);
String[] expectedRKs = testConfiguration.getExpectedResourceKeysAfterUpgrade(setup);
assertEquals(vhosts.size(), expectedRKs.length, "Unexpected number of vhosts discovered found");
List<String> expectedResourceKeys = Arrays.asList(expectedRKs);
for (Resource vhost : vhosts) {
assertTrue(expectedResourceKeys.contains(vhost.getResourceKey()),
"Unexpected virtual host resource key: '" + vhost.getResourceKey() + "'. Only expecting " + expectedResourceKeys);
}
String[] expectedFailureRKs = testConfiguration.getExpectedResourceKeysWithFailures(setup);
if (expectedFailureRKs != null && expectedFailureRKs.length > 0) {
Set<Resource> failingResources = new HashSet<Resource>();
for(String rk : expectedFailureRKs) {
for(Resource r : vhosts) {
if (rk.equals(r.getResourceKey())) {
failingResources.add(r);
break;
}
}
}
assertEquals(failingResources.size(), expectedFailureRKs.length, "Couldn't find all the resources that should have failed.");
for(Resource failingResource : failingResources) {
List<ResourceError> errors = failingResource.getResourceErrors(ResourceErrorType.UPGRADE);
assertNotNull(errors, "The main vhost doesn't have any upgrade errors.");
assertEquals(errors.size(), 1, "There should be exactly one upgrade error on the main vhost.");
}
//check that all other vhosts were not upgraded but have no errors
for(Resource r : vhosts) {
if (failingResources.contains(r)) {
continue;
}
assertEquals(r.getResourceErrors(ResourceErrorType.UPGRADE).size(), 0, "Unexpected number of resource upgrade errors on vhost " + r);
}
} else {
for(Resource r : vhosts) {
assertEquals(r.getResourceErrors(ResourceErrorType.UPGRADE).size(), 0, "Unexpected number of resource upgrade errors on vhost " + r);
}
}
} catch (AssertionError e) {
throw e;
} catch (Throwable t) {
testFailed = true;
LOG.error("Error during test upgrade execution.", t);
throw t;
} finally {
try {
setup.withApacheSetup().stopApache();
} catch (Exception e) {
if (testFailed) {
LOG.error("Failed to stop apache.", e);
} else {
throw e;