KEYCLOAK-1678 Fixed app-server containers' handling.

This commit is contained in:
Tomas Kyjovsky 2016-02-05 01:07:40 +01:00
parent 3a51b3530d
commit 58084d5ee5
7 changed files with 225 additions and 135 deletions

View file

@ -4,7 +4,7 @@ import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import org.jboss.arquillian.container.spi.Container; import org.jboss.arquillian.container.spi.event.container.BeforeDeploy;
import org.jboss.arquillian.container.test.api.ContainerController; import org.jboss.arquillian.container.test.api.ContainerController;
import org.jboss.arquillian.core.api.Instance; import org.jboss.arquillian.core.api.Instance;
import org.jboss.arquillian.core.api.InstanceProducer; import org.jboss.arquillian.core.api.InstanceProducer;
@ -34,16 +34,15 @@ public class AppServerTestEnricher {
private InstanceProducer<TestContext> testContextProducer; private InstanceProducer<TestContext> testContextProducer;
private TestContext testContext; private TestContext testContext;
@Inject
private Instance<ContainerController> containerController;
public static String getAppServerQualifier(Class testClass) { public static String getAppServerQualifier(Class testClass) {
Class<? extends AuthServerTestEnricher> annotatedClass = getNearestSuperclassWithAnnotation(testClass, AppServerContainer.class); Class<? extends AuthServerTestEnricher> annotatedClass = getNearestSuperclassWithAnnotation(testClass, AppServerContainer.class);
String appServerQ = (annotatedClass == null ? null String appServerQ = (annotatedClass == null ? null
: annotatedClass.getAnnotation(AppServerContainer.class).value()); : annotatedClass.getAnnotation(AppServerContainer.class).value());
return appServerQ; return appServerQ == null || appServerQ.isEmpty()
? getAuthServerQualifier() // app server == auth server
: appServerQ;
} }
public static String getAppServerContextRoot() { public static String getAppServerContextRoot() {
@ -60,12 +59,26 @@ public class AppServerTestEnricher {
: "http://localhost:" + (httpPort + clusterPortOffset); : "http://localhost:" + (httpPort + clusterPortOffset);
} }
private ContainerInfo initializeAppServerInfo(Container appServerContainer) { public void updateTestContextWithAppServerInfo(@Observes(precedence = 1) BeforeClass event) {
return initializeAppServerInfo(appServerContainer, 0); testContext = testContextProducer.get();
String appServerQualifier = getAppServerQualifier(testContext.getTestClass());
for (ContainerInfo container : testContext.getSuiteContext().getContainers()) {
if (container.getQualifier().equals(appServerQualifier)) {
testContext.setAppServerInfo(updateWithAppServerInfo(container));
}
}
// validate app server
if (appServerQualifier != null && testContext.getAppServerInfo() == null) {
throw new RuntimeException(String.format("No app server container matching '%s' was activated. Check if defined and enabled in arquillian.xml.", appServerQualifier));
}
log.info("\n\n" + testContext);
} }
private ContainerInfo initializeAppServerInfo(Container appServerContainer, int clusterPortOffset) { private ContainerInfo updateWithAppServerInfo(ContainerInfo appServerInfo) {
ContainerInfo appServerInfo = new ContainerInfo(appServerContainer); return updateWithAppServerInfo(appServerInfo, 0);
}
private ContainerInfo updateWithAppServerInfo(ContainerInfo appServerInfo, int clusterPortOffset) {
try { try {
String appServerContextRootStr = isRelative(testContext.getTestClass()) String appServerContextRootStr = isRelative(testContext.getTestClass())
@ -80,39 +93,34 @@ public class AppServerTestEnricher {
return appServerInfo; return appServerInfo;
} }
public void updateTestContextWithAppServerInfo(@Observes BeforeClass event) { @Inject
testContext = testContextProducer.get(); private Instance<ContainerController> containerConrollerInstance;
String appServerQualifier = getAppServerQualifier(testContext.getTestClass());
for (Container container : testContext.getSuiteContext().getArquillianContainers()) {
if (container.getContainerConfiguration().getContainerName().equals(appServerQualifier)) {
testContext.setAppServerInfo(initializeAppServerInfo(container));
}
}
// validate app server
if (appServerQualifier != null && testContext.getAppServerInfo() == null) {
throw new RuntimeException(String.format("No app server container matching '%s' was activated. Check if defined and enabled in arquillian.xml.", appServerQualifier));
}
log.info("\n\n" + testContext);
}
public void startAppServer(@Observes(precedence = -1) BeforeClass event) throws MalformedURLException, InterruptedException, IOException { public void startAppServer(@Observes(precedence = -1) BeforeClass event) throws MalformedURLException, InterruptedException, IOException {
ContainerController controller = containerController.get();
if (testContext.isAdapterTest()) { if (testContext.isAdapterTest()) {
String appServerQualifier = testContext.getAppServerInfo().getQualifier(); ContainerController controller = containerConrollerInstance.get();
if (!controller.isStarted(appServerQualifier)) { if (!controller.isStarted(testContext.getAppServerInfo().getQualifier())) {
controller.start(appServerQualifier); controller.start(testContext.getAppServerInfo().getQualifier());
} }
log.info("\n\n\nAPP SERVER STARTED\n\n\n"); }
}
public void installAdapterLibs(@Observes BeforeDeploy event) {
log.info("BEFORE DEPLOY");
if (testContext.isAdapterTest()) {
// install adapter libs on JBoss-based container via CLI // install adapter libs on JBoss-based container via CLI
// if (testContext.getAppServerInfo().isJBossBased()) { if (testContext.getAppServerInfo().isJBossBased()) {
try {
installAdapterLibsUsingJBossCLIClient(testContext.getAppServerInfo()); installAdapterLibsUsingJBossCLIClient(testContext.getAppServerInfo());
// } } catch (InterruptedException | IOException ex) {
throw new RuntimeException("Failed to install adapter libs.", ex);
}
}
} }
} }
private void installAdapterLibsUsingJBossCLIClient(ContainerInfo appServerInfo) throws InterruptedException, IOException { private void installAdapterLibsUsingJBossCLIClient(ContainerInfo appServerInfo) throws InterruptedException, IOException {
if (!appServerInfo.isAdapterLibsInstalled()) {
log.info("Installing adapter via CLI client");
if (!appServerInfo.isJBossBased()) { if (!appServerInfo.isJBossBased()) {
throw new IllegalArgumentException("App server must be JBoss-based to run jboss-cli-client."); throw new IllegalArgumentException("App server must be JBoss-based to run jboss-cli-client.");
@ -121,7 +129,16 @@ public class AppServerTestEnricher {
String jbossHomePath = appServerInfo.getProperties().get("jbossHome"); String jbossHomePath = appServerInfo.getProperties().get("jbossHome");
File bin = new File(jbossHomePath + "/bin"); File bin = new File(jbossHomePath + "/bin");
String command = "java -jar " + jbossHomePath + "/bin/client/jboss-cli-client.jar";
File clientJar = new File(jbossHomePath + "/bin/client/jboss-cli-client.jar");
if (!clientJar.exists()) {
clientJar = new File(jbossHomePath + "/bin/client/jboss-client.jar"); // AS7
}
if (!clientJar.exists()) {
throw new IOException("JBoss CLI client JAR not found.");
}
String command = "java -jar " + clientJar.getAbsolutePath();
String adapterScript = "adapter-install.cli"; String adapterScript = "adapter-install.cli";
String samlAdapterScript = "adapter-install-saml.cli"; String samlAdapterScript = "adapter-install-saml.cli";
String managementPort = appServerInfo.getProperties().get("managementPort"); String managementPort = appServerInfo.getProperties().get("managementPort");
@ -142,6 +159,9 @@ public class AppServerTestEnricher {
pause(5000); pause(5000);
LogChecker.checkJBossServerLog(jbossHomePath); LogChecker.checkJBossServerLog(jbossHomePath);
} }
appServerInfo.setAdapterLibsInstalled(true);
}
} }
/** /**

View file

@ -19,7 +19,8 @@ package org.keycloak.testsuite.arquillian;
import java.io.IOException; import java.io.IOException;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.ArrayList; import java.util.LinkedHashSet;
import java.util.Set;
import org.jboss.arquillian.container.spi.Container; import org.jboss.arquillian.container.spi.Container;
import org.jboss.arquillian.container.spi.ContainerRegistry; import org.jboss.arquillian.container.spi.ContainerRegistry;
@ -93,7 +94,13 @@ public class AuthServerTestEnricher {
} }
public void initializeSuiteContext(@Observes(precedence = 2) BeforeSuite event) { public void initializeSuiteContext(@Observes(precedence = 2) BeforeSuite event) {
suiteContext = new SuiteContext(new ArrayList<>(containerRegistry.get().getContainers()));
Set<ContainerInfo> containers = new LinkedHashSet<>();
for (Container c : containerRegistry.get().getContainers()) {
containers.add(new ContainerInfo(c));
}
suiteContext = new SuiteContext(containers);
String authServerQualifier = getAuthServerQualifier(); String authServerQualifier = getAuthServerQualifier();
String migratedAuthServerQualifier = getMigratedAuthServerQualifier(); String migratedAuthServerQualifier = getMigratedAuthServerQualifier();
@ -109,14 +116,16 @@ public class AuthServerTestEnricher {
: authServerQualifier; // single-node mode : authServerQualifier; // single-node mode
String authServerBackend = "auth-server-" + authServerType + "-backend"; String authServerBackend = "auth-server-" + authServerType + "-backend";
int backends = 0; int backends = 0;
for (Container container : suiteContext.getArquillianContainers()) { for (ContainerInfo container : suiteContext.getContainers()) {
// frontend // frontend
if (container.getContainerConfiguration().getContainerName().equals(authServerFrontend)) { if (container.getQualifier().equals(authServerFrontend)) {
suiteContext.setAuthServerInfo(initializeAuthServerInfo(container)); updateWithAuthServerInfo(container);
suiteContext.setAuthServerInfo(container);
} }
// backends // backends
if (container.getContainerConfiguration().getContainerName().startsWith(authServerBackend)) { if (container.getQualifier().startsWith(authServerBackend)) {
suiteContext.getAuthServerBackendsInfo().add(initializeAuthServerInfo(container, ++backends)); updateWithAuthServerInfo(container, ++backends);
suiteContext.getAuthServerBackendsInfo().add(container);
} }
} }
@ -135,10 +144,11 @@ public class AuthServerTestEnricher {
if (migratedAuthServerQualifier != null) { if (migratedAuthServerQualifier != null) {
// init migratedAuthServerInfo // init migratedAuthServerInfo
if (migratedAuthServerQualifier.startsWith("migrated-auth-server-")) { if (migratedAuthServerQualifier.startsWith("migrated-auth-server-")) {
for (Container container : suiteContext.getArquillianContainers()) { for (ContainerInfo container : suiteContext.getContainers()) {
// migrated auth server // migrated auth server
if (container.getContainerConfiguration().getContainerName().equals(migratedAuthServerQualifier)) { if (container.getQualifier().equals(migratedAuthServerQualifier)) {
suiteContext.setMigratedAuthServerInfo(initializeAuthServerInfo(container)); updateWithAuthServerInfo(container);
suiteContext.setMigratedAuthServerInfo(container);
} }
} }
} else { } else {
@ -155,17 +165,11 @@ public class AuthServerTestEnricher {
log.info("\n\n" + suiteContext); log.info("\n\n" + suiteContext);
} }
public void initializeTestContext(@Observes(precedence = 1) BeforeClass event) { private ContainerInfo updateWithAuthServerInfo(ContainerInfo authServerInfo) {
TestContext testContext = new TestContext(suiteContext, event.getTestClass().getJavaClass()); return updateWithAuthServerInfo(authServerInfo, 0);
testContextProducer.set(testContext);
} }
private ContainerInfo initializeAuthServerInfo(Container authServerContainer) { private ContainerInfo updateWithAuthServerInfo(ContainerInfo authServerInfo, int clusterPortOffset) {
return initializeAuthServerInfo(authServerContainer, 0);
}
private ContainerInfo initializeAuthServerInfo(Container authServerContainer, int clusterPortOffset) {
ContainerInfo authServerInfo = new ContainerInfo(authServerContainer);
try { try {
authServerInfo.setContextRoot(new URL(getAuthServerContextRoot(clusterPortOffset))); authServerInfo.setContextRoot(new URL(getAuthServerContextRoot(clusterPortOffset)));
} catch (MalformedURLException ex) { } catch (MalformedURLException ex) {
@ -195,4 +199,9 @@ public class AuthServerTestEnricher {
} }
} }
public void initializeTestContext(@Observes(precedence = 2) BeforeClass event) {
TestContext testContext = new TestContext(suiteContext, event.getTestClass().getJavaClass());
testContextProducer.set(testContext);
}
} }

View file

@ -2,6 +2,7 @@ package org.keycloak.testsuite.arquillian;
import java.net.URL; import java.net.URL;
import java.util.Map; import java.util.Map;
import java.util.Objects;
import org.jboss.arquillian.container.spi.Container; import org.jboss.arquillian.container.spi.Container;
/** /**
@ -12,6 +13,7 @@ public class ContainerInfo {
private URL contextRoot; private URL contextRoot;
private Container arquillianContainer; private Container arquillianContainer;
private boolean adapterLibsInstalled;
public ContainerInfo(Container arquillianContainer) { public ContainerInfo(Container arquillianContainer) {
if (arquillianContainer == null) { if (arquillianContainer == null) {
@ -41,15 +43,15 @@ public class ContainerInfo {
} }
public boolean isAS7() { public boolean isAS7() {
return getQualifier().contains("as7"); return getQualifier().toLowerCase().contains("as7");
} }
public boolean isWildfly() { public boolean isWildfly() {
return getQualifier().contains("Wildfly"); return getQualifier().toLowerCase().contains("wildfly");
} }
public boolean isEAP() { public boolean isEAP() {
return getQualifier().contains("eap"); return getQualifier().toLowerCase().contains("eap");
} }
public boolean isJBossBased() { public boolean isJBossBased() {
@ -61,4 +63,33 @@ public class ContainerInfo {
return getQualifier(); return getQualifier();
} }
public boolean isAdapterLibsInstalled() {
return adapterLibsInstalled;
}
public void setAdapterLibsInstalled(boolean adapterLibsInstalled) {
this.adapterLibsInstalled = adapterLibsInstalled;
}
@Override
public int hashCode() {
int hash = 7;
hash = 97 * hash + Objects.hashCode(this.arquillianContainer);
return hash;
}
@Override
public boolean equals(Object obj) {
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final ContainerInfo other = (ContainerInfo) obj;
return Objects.equals(
this.arquillianContainer.getContainerConfiguration().getContainerName(),
other.arquillianContainer.getContainerConfiguration().getContainerName());
}
} }

View file

@ -20,7 +20,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.jboss.arquillian.container.spi.Container; import java.util.Set;
import static org.keycloak.testsuite.util.MailServerConfiguration.*; import static org.keycloak.testsuite.util.MailServerConfiguration.*;
/** /**
@ -29,7 +29,7 @@ import static org.keycloak.testsuite.util.MailServerConfiguration.*;
*/ */
public final class SuiteContext { public final class SuiteContext {
private final List<Container> arquillianContainers; private final Set<ContainerInfo> container;
private ContainerInfo authServerInfo; private ContainerInfo authServerInfo;
private final List<ContainerInfo> authServerBackendsInfo = new ArrayList<>(); private final List<ContainerInfo> authServerBackendsInfo = new ArrayList<>();
@ -39,8 +39,8 @@ public final class SuiteContext {
private boolean adminPasswordUpdated; private boolean adminPasswordUpdated;
private final Map<String, String> smtpServer = new HashMap<>(); private final Map<String, String> smtpServer = new HashMap<>();
public SuiteContext(List<Container> arquillianContainers) { public SuiteContext(Set<ContainerInfo> arquillianContainers) {
this.arquillianContainers = arquillianContainers; this.container = arquillianContainers;
this.adminPasswordUpdated = false; this.adminPasswordUpdated = false;
smtpServer.put("from", FROM); smtpServer.put("from", FROM);
smtpServer.put("host", HOST); smtpServer.put("host", HOST);
@ -87,8 +87,8 @@ public final class SuiteContext {
return migratedAuthServerInfo != null; return migratedAuthServerInfo != null;
} }
public List<Container> getArquillianContainers() { public Set<ContainerInfo> getContainers() {
return arquillianContainers; return container;
} }
@Override @Override

View file

@ -25,7 +25,6 @@ import org.keycloak.representations.idm.ClientRepresentation;
import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.representations.idm.RealmRepresentation;
import org.keycloak.testsuite.AbstractAuthTest; import org.keycloak.testsuite.AbstractAuthTest;
import org.keycloak.testsuite.adapter.page.AppServerContextRoot; import org.keycloak.testsuite.adapter.page.AppServerContextRoot;
import org.keycloak.testsuite.arquillian.AuthServerTestEnricher;
import org.keycloak.testsuite.arquillian.annotation.AppServerContainer; import org.keycloak.testsuite.arquillian.annotation.AppServerContainer;
import java.io.IOException; import java.io.IOException;

View file

@ -286,13 +286,6 @@
</build> </build>
</profile> </profile>
<profile>
<id>auth-server-wildfly</id>
<modules>
<module>wildfly-relative</module>
</modules>
</profile>
<profile> <profile>
<id>app-server-eap6</id> <id>app-server-eap6</id>
<modules> <modules>
@ -311,6 +304,12 @@
<module>wildfly</module> <module>wildfly</module>
</modules> </modules>
</profile> </profile>
<profile>
<id>app-server-wildfly-relative</id>
<modules>
<module>wildfly-relative</module>
</modules>
</profile>
<profile> <profile>
<id>app-server-wildfly8</id> <id>app-server-wildfly8</id>
<modules> <modules>

View file

@ -54,7 +54,39 @@
</dependency> </dependency>
</dependencies> </dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<executions>
<execution>
<id>enforce-auth-server-wildfly-profile</id>
<goals>
<goal>enforce</goal>
</goals>
<configuration>
<rules>
<requireActiveProfile>
<profiles>auth-server-wildfly</profiles>
</requireActiveProfile>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
<profiles> <profiles>
<profile>
<id>auth-server-wildfly</id>
<!--dummy profile for the enforcer plugin to work-->
</profile>
<profile> <profile>
<id>adapter-libs-bundled</id> <id>adapter-libs-bundled</id>
<activation> <activation>