diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/AppServerTestEnricher.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/AppServerTestEnricher.java index b47981b790..47cad7d25f 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/AppServerTestEnricher.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/AppServerTestEnricher.java @@ -4,7 +4,7 @@ import java.io.File; import java.io.IOException; import java.net.MalformedURLException; 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.core.api.Instance; import org.jboss.arquillian.core.api.InstanceProducer; @@ -34,16 +34,15 @@ public class AppServerTestEnricher { private InstanceProducer testContextProducer; private TestContext testContext; - @Inject - private Instance containerController; - public static String getAppServerQualifier(Class testClass) { Class annotatedClass = getNearestSuperclassWithAnnotation(testClass, AppServerContainer.class); String appServerQ = (annotatedClass == null ? null : annotatedClass.getAnnotation(AppServerContainer.class).value()); - return appServerQ; + return appServerQ == null || appServerQ.isEmpty() + ? getAuthServerQualifier() // app server == auth server + : appServerQ; } public static String getAppServerContextRoot() { @@ -60,12 +59,26 @@ public class AppServerTestEnricher { : "http://localhost:" + (httpPort + clusterPortOffset); } - private ContainerInfo initializeAppServerInfo(Container appServerContainer) { - return initializeAppServerInfo(appServerContainer, 0); + public void updateTestContextWithAppServerInfo(@Observes(precedence = 1) BeforeClass event) { + 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) { - ContainerInfo appServerInfo = new ContainerInfo(appServerContainer); + private ContainerInfo updateWithAppServerInfo(ContainerInfo appServerInfo) { + return updateWithAppServerInfo(appServerInfo, 0); + } + + private ContainerInfo updateWithAppServerInfo(ContainerInfo appServerInfo, int clusterPortOffset) { try { String appServerContextRootStr = isRelative(testContext.getTestClass()) @@ -80,67 +93,74 @@ public class AppServerTestEnricher { return appServerInfo; } - public void updateTestContextWithAppServerInfo(@Observes BeforeClass event) { - testContext = testContextProducer.get(); - 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); - } + @Inject + private Instance containerConrollerInstance; public void startAppServer(@Observes(precedence = -1) BeforeClass event) throws MalformedURLException, InterruptedException, IOException { - ContainerController controller = containerController.get(); if (testContext.isAdapterTest()) { - String appServerQualifier = testContext.getAppServerInfo().getQualifier(); - if (!controller.isStarted(appServerQualifier)) { - controller.start(appServerQualifier); + ContainerController controller = containerConrollerInstance.get(); + if (!controller.isStarted(testContext.getAppServerInfo().getQualifier())) { + 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 -// if (testContext.getAppServerInfo().isJBossBased()) { - installAdapterLibsUsingJBossCLIClient(testContext.getAppServerInfo()); -// } + if (testContext.getAppServerInfo().isJBossBased()) { + try { + installAdapterLibsUsingJBossCLIClient(testContext.getAppServerInfo()); + } catch (InterruptedException | IOException ex) { + throw new RuntimeException("Failed to install adapter libs.", ex); + } + } } } private void installAdapterLibsUsingJBossCLIClient(ContainerInfo appServerInfo) throws InterruptedException, IOException { - - log.info("Installing adapter via CLI client"); - - if (!appServerInfo.isJBossBased()) { - throw new IllegalArgumentException("App server must be JBoss-based to run jboss-cli-client."); - } + if (!appServerInfo.isAdapterLibsInstalled()) { - String jbossHomePath = appServerInfo.getProperties().get("jbossHome"); + if (!appServerInfo.isJBossBased()) { + throw new IllegalArgumentException("App server must be JBoss-based to run jboss-cli-client."); + } - File bin = new File(jbossHomePath + "/bin"); - String command = "java -jar " + jbossHomePath + "/bin/client/jboss-cli-client.jar"; - String adapterScript = "adapter-install.cli"; - String samlAdapterScript = "adapter-install-saml.cli"; - String managementPort = appServerInfo.getProperties().get("managementPort"); + String jbossHomePath = appServerInfo.getProperties().get("jbossHome"); - String controllerArg = " --controller=localhost:" + managementPort; - if (new File(bin, adapterScript).exists()) { - log.info("Installing adapter to app server via cli script"); - execCommand(command + " --connect --file=" + adapterScript + controllerArg, bin); - } - if (new File(bin, samlAdapterScript).exists()) { - log.info("Installing saml adapter to app server via cli script"); - execCommand(command + " --connect --file=" + samlAdapterScript + controllerArg, bin); - } - if (new File(bin, adapterScript).exists() || new File(bin, samlAdapterScript).exists()) { - log.info("Restarting container"); - execCommand(command + " --connect --command=reload" + controllerArg, bin); - log.info("Container restarted"); - pause(5000); - LogChecker.checkJBossServerLog(jbossHomePath); + File bin = new File(jbossHomePath + "/bin"); + + 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 samlAdapterScript = "adapter-install-saml.cli"; + String managementPort = appServerInfo.getProperties().get("managementPort"); + + String controllerArg = " --controller=localhost:" + managementPort; + if (new File(bin, adapterScript).exists()) { + log.info("Installing adapter to app server via cli script"); + execCommand(command + " --connect --file=" + adapterScript + controllerArg, bin); + } + if (new File(bin, samlAdapterScript).exists()) { + log.info("Installing saml adapter to app server via cli script"); + execCommand(command + " --connect --file=" + samlAdapterScript + controllerArg, bin); + } + if (new File(bin, adapterScript).exists() || new File(bin, samlAdapterScript).exists()) { + log.info("Restarting container"); + execCommand(command + " --connect --command=reload" + controllerArg, bin); + log.info("Container restarted"); + pause(5000); + LogChecker.checkJBossServerLog(jbossHomePath); + } + + appServerInfo.setAdapterLibsInstalled(true); } } diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/AuthServerTestEnricher.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/AuthServerTestEnricher.java index 86176cb820..5000e3b482 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/AuthServerTestEnricher.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/AuthServerTestEnricher.java @@ -19,7 +19,8 @@ package org.keycloak.testsuite.arquillian; import java.io.IOException; import java.net.MalformedURLException; 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.ContainerRegistry; @@ -44,79 +45,87 @@ import org.keycloak.testsuite.util.LogChecker; * @author vramik */ public class AuthServerTestEnricher { - + protected final Logger log = Logger.getLogger(this.getClass()); - + @Inject private Instance containerRegistry; - + @Inject private Instance containerController; - + @Inject private Event startContainerEvent; - + private static final String AUTH_SERVER_CONTAINER_PROPERTY = "auth.server.container"; private static final String AUTH_SERVER_CONTAINER_DEFAULT = "auth-server-undertow"; - + private static final String MIGRATED_AUTH_SERVER_CONTAINER_PROPERTY = "migrated.auth.server.container"; - + @Inject @SuiteScoped private InstanceProducer suiteContextProducer; private SuiteContext suiteContext; - + @Inject @ClassScoped private InstanceProducer testContextProducer; - + public static String getAuthServerQualifier() { return System.getProperty(AUTH_SERVER_CONTAINER_PROPERTY, AUTH_SERVER_CONTAINER_DEFAULT); } - + public static String getMigratedAuthServerQualifier() { return System.getProperty(MIGRATED_AUTH_SERVER_CONTAINER_PROPERTY); // == null if migration not enabled } - + public static String getAuthServerContextRoot() { return getAuthServerContextRoot(0); } - + public static String getAuthServerContextRoot(int clusterPortOffset) { int httpPort = Integer.parseInt(System.getProperty("auth.server.http.port")); // property must be set int httpsPort = Integer.parseInt(System.getProperty("auth.server.https.port")); // property must be set boolean sslRequired = Boolean.parseBoolean(System.getProperty("auth.server.ssl.required")); - + return sslRequired ? "https://localhost:" + (httpsPort + clusterPortOffset) : "http://localhost:" + (httpPort + clusterPortOffset); } - + public void initializeSuiteContext(@Observes(precedence = 2) BeforeSuite event) { - suiteContext = new SuiteContext(new ArrayList<>(containerRegistry.get().getContainers())); - + + Set containers = new LinkedHashSet<>(); + for (Container c : containerRegistry.get().getContainers()) { + containers.add(new ContainerInfo(c)); + } + + suiteContext = new SuiteContext(containers); + String authServerQualifier = getAuthServerQualifier(); String migratedAuthServerQualifier = getMigratedAuthServerQualifier(); // init authServerInfo and authServerBackendsInfo if (authServerQualifier.startsWith("auth-server-")) { - + boolean authServerCluster = authServerQualifier.endsWith("-cluster"); - + String authServerType = authServerQualifier.replaceAll("^auth-server-", "").replaceAll("-cluster$", ""); String authServerFrontend = authServerCluster ? "auth-server-" + authServerType + "-balancer" // in cluster mode the load-balancer container serves as auth server frontend : authServerQualifier; // single-node mode String authServerBackend = "auth-server-" + authServerType + "-backend"; int backends = 0; - for (Container container : suiteContext.getArquillianContainers()) { + for (ContainerInfo container : suiteContext.getContainers()) { // frontend - if (container.getContainerConfiguration().getContainerName().equals(authServerFrontend)) { - suiteContext.setAuthServerInfo(initializeAuthServerInfo(container)); + if (container.getQualifier().equals(authServerFrontend)) { + updateWithAuthServerInfo(container); + suiteContext.setAuthServerInfo(container); } // backends - if (container.getContainerConfiguration().getContainerName().startsWith(authServerBackend)) { - suiteContext.getAuthServerBackendsInfo().add(initializeAuthServerInfo(container, ++backends)); + if (container.getQualifier().startsWith(authServerBackend)) { + updateWithAuthServerInfo(container, ++backends); + suiteContext.getAuthServerBackendsInfo().add(container); } } @@ -127,18 +136,19 @@ public class AuthServerTestEnricher { if (authServerCluster && !suiteContext.getAuthServerBackendsInfo().isEmpty()) { throw new RuntimeException(String.format("No cluster backend nodes activated. Containers matching '%sN' need to be enabled in arquillian.xml.", authServerBackend)); } - + } else { throw new IllegalArgumentException(String.format("Value of %s should start with 'auth-server-' prefix.", AUTH_SERVER_CONTAINER_PROPERTY)); } - + if (migratedAuthServerQualifier != null) { // init migratedAuthServerInfo if (migratedAuthServerQualifier.startsWith("migrated-auth-server-")) { - for (Container container : suiteContext.getArquillianContainers()) { + for (ContainerInfo container : suiteContext.getContainers()) { // migrated auth server - if (container.getContainerConfiguration().getContainerName().equals(migratedAuthServerQualifier)) { - suiteContext.setMigratedAuthServerInfo(initializeAuthServerInfo(container)); + if (container.getQualifier().equals(migratedAuthServerQualifier)) { + updateWithAuthServerInfo(container); + suiteContext.setMigratedAuthServerInfo(container); } } } else { @@ -150,22 +160,16 @@ public class AuthServerTestEnricher { + "A container matching '%s' needs to be enabled in arquillian.xml.", migratedAuthServerQualifier)); } } - + suiteContextProducer.set(suiteContext); log.info("\n\n" + suiteContext); } - - public void initializeTestContext(@Observes(precedence = 1) BeforeClass event) { - TestContext testContext = new TestContext(suiteContext, event.getTestClass().getJavaClass()); - testContextProducer.set(testContext); + + private ContainerInfo updateWithAuthServerInfo(ContainerInfo authServerInfo) { + return updateWithAuthServerInfo(authServerInfo, 0); } - - private ContainerInfo initializeAuthServerInfo(Container authServerContainer) { - return initializeAuthServerInfo(authServerContainer, 0); - } - - private ContainerInfo initializeAuthServerInfo(Container authServerContainer, int clusterPortOffset) { - ContainerInfo authServerInfo = new ContainerInfo(authServerContainer); + + private ContainerInfo updateWithAuthServerInfo(ContainerInfo authServerInfo, int clusterPortOffset) { try { authServerInfo.setContextRoot(new URL(getAuthServerContextRoot(clusterPortOffset))); } catch (MalformedURLException ex) { @@ -173,20 +177,20 @@ public class AuthServerTestEnricher { } return authServerInfo; } - + public void startMigratedContainer(@Observes(precedence = 2) StartSuiteContainers event) { if (suiteContext.isAuthServerMigrationEnabled()) { log.info("\n\n### Starting keycloak " + System.getProperty("version", "- previous") + " ###\n"); startContainerEvent.fire(new StartContainer(suiteContext.getMigratedAuthServerInfo().getArquillianContainer())); } } - + public void stopMigratedContainer(@Observes(precedence = 1) StartSuiteContainers event) { if (suiteContext.isAuthServerMigrationEnabled()) { containerController.get().stop(suiteContext.getAuthServerInfo().getQualifier()); } } - + public void checkServerLogs(@Observes(precedence = -1) BeforeSuite event) throws IOException, InterruptedException { boolean checkLog = System.getProperty("auth.server.log.check", "true").equals("true"); if (checkLog && suiteContext.getAuthServerInfo().isJBossBased()) { @@ -194,5 +198,10 @@ public class AuthServerTestEnricher { LogChecker.checkJBossServerLog(jbossHomePath); } } - + + public void initializeTestContext(@Observes(precedence = 2) BeforeClass event) { + TestContext testContext = new TestContext(suiteContext, event.getTestClass().getJavaClass()); + testContextProducer.set(testContext); + } + } diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/ContainerInfo.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/ContainerInfo.java index 68ae059869..a6bcdc5841 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/ContainerInfo.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/ContainerInfo.java @@ -2,6 +2,7 @@ package org.keycloak.testsuite.arquillian; import java.net.URL; import java.util.Map; +import java.util.Objects; import org.jboss.arquillian.container.spi.Container; /** @@ -12,6 +13,7 @@ public class ContainerInfo { private URL contextRoot; private Container arquillianContainer; + private boolean adapterLibsInstalled; public ContainerInfo(Container arquillianContainer) { if (arquillianContainer == null) { @@ -41,15 +43,15 @@ public class ContainerInfo { } public boolean isAS7() { - return getQualifier().contains("as7"); + return getQualifier().toLowerCase().contains("as7"); } public boolean isWildfly() { - return getQualifier().contains("Wildfly"); + return getQualifier().toLowerCase().contains("wildfly"); } public boolean isEAP() { - return getQualifier().contains("eap"); + return getQualifier().toLowerCase().contains("eap"); } public boolean isJBossBased() { @@ -61,4 +63,33 @@ public class ContainerInfo { 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()); + } + } diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/SuiteContext.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/SuiteContext.java index cf58916821..c4bd23b45a 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/SuiteContext.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/SuiteContext.java @@ -20,7 +20,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import org.jboss.arquillian.container.spi.Container; +import java.util.Set; import static org.keycloak.testsuite.util.MailServerConfiguration.*; /** @@ -29,7 +29,7 @@ import static org.keycloak.testsuite.util.MailServerConfiguration.*; */ public final class SuiteContext { - private final List arquillianContainers; + private final Set container; private ContainerInfo authServerInfo; private final List authServerBackendsInfo = new ArrayList<>(); @@ -39,8 +39,8 @@ public final class SuiteContext { private boolean adminPasswordUpdated; private final Map smtpServer = new HashMap<>(); - public SuiteContext(List arquillianContainers) { - this.arquillianContainers = arquillianContainers; + public SuiteContext(Set arquillianContainers) { + this.container = arquillianContainers; this.adminPasswordUpdated = false; smtpServer.put("from", FROM); smtpServer.put("host", HOST); @@ -87,8 +87,8 @@ public final class SuiteContext { return migratedAuthServerInfo != null; } - public List getArquillianContainers() { - return arquillianContainers; + public Set getContainers() { + return container; } @Override diff --git a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/AbstractAdapterTest.java b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/AbstractAdapterTest.java index 656df2fe2c..a9ed805c3a 100644 --- a/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/AbstractAdapterTest.java +++ b/testsuite/integration-arquillian/tests/base/src/test/java/org/keycloak/testsuite/adapter/AbstractAdapterTest.java @@ -25,7 +25,6 @@ import org.keycloak.representations.idm.ClientRepresentation; import org.keycloak.representations.idm.RealmRepresentation; import org.keycloak.testsuite.AbstractAuthTest; import org.keycloak.testsuite.adapter.page.AppServerContextRoot; -import org.keycloak.testsuite.arquillian.AuthServerTestEnricher; import org.keycloak.testsuite.arquillian.annotation.AppServerContainer; import java.io.IOException; diff --git a/testsuite/integration-arquillian/tests/other/adapters/pom.xml b/testsuite/integration-arquillian/tests/other/adapters/pom.xml index 8b09d913f8..132b8f6346 100644 --- a/testsuite/integration-arquillian/tests/other/adapters/pom.xml +++ b/testsuite/integration-arquillian/tests/other/adapters/pom.xml @@ -286,13 +286,6 @@ - - auth-server-wildfly - - wildfly-relative - - - app-server-eap6 @@ -311,6 +304,12 @@ wildfly + + app-server-wildfly-relative + + wildfly-relative + + app-server-wildfly8 diff --git a/testsuite/integration-arquillian/tests/other/adapters/wildfly-relative/pom.xml b/testsuite/integration-arquillian/tests/other/adapters/wildfly-relative/pom.xml index e705fec69e..89aabe5a86 100644 --- a/testsuite/integration-arquillian/tests/other/adapters/wildfly-relative/pom.xml +++ b/testsuite/integration-arquillian/tests/other/adapters/wildfly-relative/pom.xml @@ -1,20 +1,20 @@ +~ Copyright 2016 Red Hat, Inc. and/or its affiliates +~ and other contributors as indicated by the @author tags. +~ +~ Licensed under the Apache License, Version 2.0 (the "License"); +~ you may not use this file except in compliance with the License. +~ You may obtain a copy of the License at +~ +~ http://www.apache.org/licenses/LICENSE-2.0 +~ +~ Unless required by applicable law or agreed to in writing, software +~ distributed under the License is distributed on an "AS IS" BASIS, +~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +~ See the License for the specific language governing permissions and +~ limitations under the License. +--> @@ -54,7 +54,39 @@ + + + + + org.apache.maven.plugins + maven-enforcer-plugin + + + enforce-auth-server-wildfly-profile + + enforce + + + + + auth-server-wildfly + + + + + + + + + + + + + auth-server-wildfly + + + adapter-libs-bundled