KEYCLOAK-8425 fix NPE during adapter cluster tests

This commit is contained in:
vramik 2018-09-26 12:04:04 +02:00 committed by Pavel Drozd
parent 081e9883e6
commit 723ba42264
3 changed files with 32 additions and 11 deletions

View file

@ -75,7 +75,6 @@ public class AdapterTestExecutionDecider implements TestExecutionDecider {
}
private AppServerContainer getCorrespondingAnnotation(Method method) {
String appServerContainerName = testContextInstance.get().getAppServerInfo().getArquillianContainer().getName();
AppServerContainers multipleAnnotations = method.getAnnotation(AppServerContainers.class);
@ -87,13 +86,12 @@ public class AdapterTestExecutionDecider implements TestExecutionDecider {
}
return appServerContainers.stream()
.filter(annotation -> annotation.value().equals(appServerContainerName))
.findFirst()
.orElseThrow(() -> new IllegalStateException("Not found the @AppServerContainer annotation with current app server."));
.filter(annotation -> annotation.value().equals(testContextInstance.get().getAppServerContainerName()))
.findFirst()
.orElseThrow(() -> new IllegalStateException("Not found the @AppServerContainer annotation with current app server."));
}
private AppServerContainer getCorrespondingAnnotation(Class testClass) {
String appServerContainerName = testContextInstance.get().getAppServerInfo().getArquillianContainer().getName();
Class<?> annotatedClass = AppServerTestEnricher.getNearestSuperclassWithAppServerAnnotation(testClass);
@ -105,10 +103,11 @@ public class AdapterTestExecutionDecider implements TestExecutionDecider {
} else {// single @AppServerContainer annotation
appServerContainers = Arrays.asList(annotatedClass.getAnnotation(AppServerContainer.class));
}
return appServerContainers.stream()
.filter(annotation -> annotation.value().equals(appServerContainerName))
.findFirst()
.orElseThrow(() -> new IllegalStateException("Not found the @AppServerContainer annotation with current app server."));
.filter(annotation -> annotation.value().equals(testContextInstance.get().getAppServerContainerName()))
.findFirst()
.orElseThrow(() -> new IllegalStateException("Not found the @AppServerContainer annotation with current app server."));
}
private ExecutionDecision execute(Method method, Boolean execute, String message) {

View file

@ -194,4 +194,16 @@ public final class TestContext {
customContext.put(key, value);
}
public String getAppServerContainerName() {
if (isAdapterContainerEnabled()) { //standalone app server
return getAppServerInfo().getArquillianContainer().getName();
} else if (isAdapterContainerEnabledCluster()) { //clustered app server
return getAppServerBackendsInfo().stream()
.map(ContainerInfo::getQualifier)
.collect(Collectors.joining(";"));
}
return null;
}
}

View file

@ -102,19 +102,29 @@ public class URLProvider extends URLResourceProvider {
return suiteContext.get().getAuthServerInfo().getContextRoot();
}
if (AppServerContext.class.isAssignableFrom(a.annotationType())) {
//standalone
ContainerInfo appServerInfo = testContext.get().getAppServerInfo();
if (appServerInfo != null) return appServerInfo.getContextRoot();
//cluster
List<ContainerInfo> appServerBackendsInfo = testContext.get().getAppServerBackendsInfo();
if (appServerBackendsInfo.isEmpty()) throw new IllegalStateException("Both testContext's appServerInfo and appServerBackendsInfo not set.");
return appServerBackendsInfo.get(0).getContextRoot();
}
if (AuthServerBrowserContext.class.isAssignableFrom(a.annotationType())) {
return suiteContext.get().getAuthServerInfo().getBrowserContextRoot();
}
if (AppServerBrowserContext.class.isAssignableFrom(a.annotationType())) {
return testContext.get().getAppServerInfo().getBrowserContextRoot();
//standalone
ContainerInfo appServerInfo = testContext.get().getAppServerInfo();
if (appServerInfo != null) return appServerInfo.getBrowserContextRoot();
//cluster
List<ContainerInfo> appServerBackendsInfo = testContext.get().getAppServerBackendsInfo();
if (appServerBackendsInfo.isEmpty()) throw new IllegalStateException("Both testContext's appServerInfo and appServerBackendsInfo not set.");
return appServerBackendsInfo.get(0).getBrowserContextRoot();
}
}