From 027311c0c059d369f04d1e81b5252bd9e3b829bb Mon Sep 17 00:00:00 2001 From: Tomas Kyjovsky Date: Fri, 6 Nov 2015 13:03:42 +0100 Subject: [PATCH] Adapter tests for Karaf: Fuse Example installation now done via JMX instead of maven-karaf plugin. Needed for testing on Fuse. --- .../tests/adapters/karaf/pom.xml | 80 +++++-------- .../karaf/src/main/xslt/arquillian-fuse.xsl | 45 ++++++++ .../karaf/src/main/xslt/arquillian.xsl | 15 ++- .../integration-arquillian/tests/base/pom.xml | 8 ++ .../arquillian/ContainersTestEnricher.java | 7 +- .../KeycloakArquillianExtension.java | 4 +- .../karaf/CustomKarafContainer.java | 105 ++++++++++++++++++ .../CustomKarafContainerConfiguration.java | 25 +++++ .../integration-arquillian/tests/pom.xml | 26 +++++ 9 files changed, 257 insertions(+), 58 deletions(-) create mode 100644 testsuite/integration-arquillian/tests/adapters/karaf/src/main/xslt/arquillian-fuse.xsl create mode 100644 testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/karaf/CustomKarafContainer.java create mode 100644 testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/karaf/CustomKarafContainerConfiguration.java diff --git a/testsuite/integration-arquillian/tests/adapters/karaf/pom.xml b/testsuite/integration-arquillian/tests/adapters/karaf/pom.xml index fc29132e10..55ad00c875 100644 --- a/testsuite/integration-arquillian/tests/adapters/karaf/pom.xml +++ b/testsuite/integration-arquillian/tests/adapters/karaf/pom.xml @@ -13,7 +13,8 @@ 3.0.3 - ${project.build.directory}/assembly + ${containers.home}/apache-karaf-minimal-${karaf.version} + 0 @@ -25,82 +26,57 @@ - + - org.apache.karaf.features - framework + org.apache.karaf + apache-karaf-minimal ${karaf.version} - kar + zip - - org.apache.camel.karaf - apache-camel - 2.12.5 - features - xml - runtime - - - org.apache.cxf.karaf - apache-cxf - 2.7.14 - features - xml - runtime - - - org.keycloak - keycloak-osgi-features - ${project.version} - features - xml - runtime - - - org.keycloak.example.demo - keycloak-fuse-example-features - ${project.version} - features - xml - runtime - - + org.jboss.arquillian.container arquillian-container-karaf-managed 2.1.0.CR18 + org.apache.aries.jmx org.apache.aries.jmx 1.1.1 + + - org.apache.karaf.tooling - karaf-maven-plugin - ${karaf.version} - true + org.apache.maven.plugins + maven-dependency-plugin - prepare-karaf-with-examples - generate-test-resources + unpack-karaf + generate-resources - - install-kars + unpack + + + + org.apache.karaf + apache-karaf-minimal + ${karaf.version} + zip + ${containers.home} + + + true + - - - - keycloak-fuse-example - - + org.apache.maven.plugins maven-surefire-plugin diff --git a/testsuite/integration-arquillian/tests/adapters/karaf/src/main/xslt/arquillian-fuse.xsl b/testsuite/integration-arquillian/tests/adapters/karaf/src/main/xslt/arquillian-fuse.xsl new file mode 100644 index 0000000000..75aea2acda --- /dev/null +++ b/testsuite/integration-arquillian/tests/adapters/karaf/src/main/xslt/arquillian-fuse.xsl @@ -0,0 +1,45 @@ + + + + + + + + + + + + ${app.server.karaf} + org.keycloak.testsuite.arquillian.karaf.CustomKarafContainer + false + ${karaf.home} + -agentlib:jdwp=transport=dt_socket,address=5005,server=y,suspend=n ${adapter.test.props} + service:jmx:rmi://127.0.0.1:44444/jndi/rmi://127.0.0.1:1099/karaf-root + admin + admin + + + features:addurl mvn:org.keycloak/keycloak-osgi-features/1.7.0.Final-SNAPSHOT/xml/features, + features:addurl mvn:org.keycloak.example.demo/keycloak-fuse-example-features/1.7.0.Final-SNAPSHOT/xml/features, + features:install keycloak-fuse-example + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/testsuite/integration-arquillian/tests/adapters/karaf/src/main/xslt/arquillian.xsl b/testsuite/integration-arquillian/tests/adapters/karaf/src/main/xslt/arquillian.xsl index fabd47b007..b6aa589019 100644 --- a/testsuite/integration-arquillian/tests/adapters/karaf/src/main/xslt/arquillian.xsl +++ b/testsuite/integration-arquillian/tests/adapters/karaf/src/main/xslt/arquillian.xsl @@ -14,13 +14,24 @@ ${app.server.karaf} - org.jboss.arquillian.container.osgi.karaf.managed.KarafManagedDeployableContainer + + org.keycloak.testsuite.arquillian.karaf.CustomKarafContainer false ${karaf.home} -agentlib:jdwp=transport=dt_socket,address=5005,server=y,suspend=n ${adapter.test.props} service:jmx:rmi://127.0.0.1:44444/jndi/rmi://127.0.0.1:1099/karaf-root karaf - karaf + karaf + + + + feature:repo-add mvn:org.apache.camel.karaf/apache-camel/2.15.1/xml/features, + feature:repo-add mvn:org.apache.cxf.karaf/apache-cxf/3.0.4/xml/features, + feature:repo-add mvn:org.keycloak/keycloak-osgi-features/1.7.0.Final-SNAPSHOT/xml/features, + feature:repo-add mvn:org.keycloak.example.demo/keycloak-fuse-example-features/1.7.0.Final-SNAPSHOT/xml/features, + feature:install keycloak-fuse-example + + diff --git a/testsuite/integration-arquillian/tests/base/pom.xml b/testsuite/integration-arquillian/tests/base/pom.xml index 6317df80ba..41038cde19 100644 --- a/testsuite/integration-arquillian/tests/base/pom.xml +++ b/testsuite/integration-arquillian/tests/base/pom.xml @@ -16,6 +16,14 @@ - + + + org.jboss.arquillian.container + arquillian-container-karaf-managed + 2.1.0.CR18 + + + diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/ContainersTestEnricher.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/ContainersTestEnricher.java index 67271089d4..9b68c4322e 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/ContainersTestEnricher.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/ContainersTestEnricher.java @@ -123,7 +123,8 @@ public class ContainersTestEnricher { */ private void checkServerLog() throws IOException { Container container = containers.removeFirst(); - if (!container.getName().equals("auth-server-undertow")) { + if (container.getName().equals("auth-server-wildfly") + || container.getName().matches("auth-server-eap.")) { String jbossHomePath = container.getContainerConfiguration().getContainerProperties().get("jbossHome"); log.debug("jbossHome: " + jbossHomePath + "\n"); @@ -133,8 +134,8 @@ public class ContainersTestEnricher { = serverLogContent.contains("ERROR") || serverLogContent.contains("SEVERE") || serverLogContent.contains("Exception "); - //There is expected string "Exception" in server log: Adding provider - //singleton org.keycloak.services.resources.ModelExceptionMapper + //There is expected string "Exception" in server log: Adding provider + //singleton org.keycloak.services.resources.ModelExceptionMapper if (containsError) { throw new RuntimeException(container.getName() + ": Server log contains ERROR."); diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/KeycloakArquillianExtension.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/KeycloakArquillianExtension.java index a987a16371..969f8fc9ed 100644 --- a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/KeycloakArquillianExtension.java +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/KeycloakArquillianExtension.java @@ -10,6 +10,7 @@ import org.jboss.arquillian.graphene.location.CustomizableURLResourceProvider; import org.jboss.arquillian.test.spi.enricher.resource.ResourceProvider; import org.jboss.arquillian.test.spi.execution.TestExecutionDecider; import org.keycloak.testsuite.arquillian.jira.JiraTestExecutionDecider; +import org.keycloak.testsuite.arquillian.karaf.CustomKarafContainer; import org.keycloak.testsuite.arquillian.migration.MigrationTestExecutionDecider; import org.keycloak.testsuite.arquillian.undertow.CustomUndertowContainer; @@ -34,7 +35,8 @@ public class KeycloakArquillianExtension implements LoadableExtension { .observer(ContainersTestEnricher.class); builder - .service(DeployableContainer.class, CustomUndertowContainer.class); + .service(DeployableContainer.class, CustomUndertowContainer.class) + .service(DeployableContainer.class, CustomKarafContainer.class); builder .service(TestExecutionDecider.class, JiraTestExecutionDecider.class) diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/karaf/CustomKarafContainer.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/karaf/CustomKarafContainer.java new file mode 100644 index 0000000000..fb90f835b2 --- /dev/null +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/karaf/CustomKarafContainer.java @@ -0,0 +1,105 @@ +package org.keycloak.testsuite.arquillian.karaf; + +import java.io.IOException; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import javax.management.InstanceNotFoundException; +import javax.management.MBeanServerConnection; +import javax.management.ObjectName; +import org.jboss.arquillian.container.osgi.jmx.ObjectNameFactory; +import org.jboss.arquillian.container.osgi.karaf.managed.KarafManagedDeployableContainer; +import org.jboss.arquillian.container.spi.client.container.LifecycleException; +import org.jboss.logging.Logger; + +/** + * + * @author tkyjovsk + */ +public class CustomKarafContainer extends KarafManagedDeployableContainer { + + protected final Logger log = Logger.getLogger(this.getClass()); + + private CustomKarafContainerConfiguration config; + + protected MBeanServerConnection mbeanServer = null; + protected ObjectName feature; + + @Override + public void start() throws LifecycleException { + super.start(); + executePostStartCommands(); + } + + @Override + public void setup(CustomKarafContainerConfiguration config) { + super.setup(config); + this.config = config; + } + + @Override + public Class getConfigurationClass() { + return CustomKarafContainerConfiguration.class; + } + + protected void executePostStartCommands() throws LifecycleException { + try { + mbeanServer = getMBeanServerConnection(500, TimeUnit.MILLISECONDS); + } catch (TimeoutException ex) { + throw new LifecycleException("JMX connection timed out."); + } + + try { + + feature = ObjectNameFactory.create("org.apache.karaf:type=feature,name=root"); + try { + mbeanServer.getObjectInstance(feature); + } catch (InstanceNotFoundException infe) { + try { + feature = ObjectNameFactory.create("org.apache.karaf:type=features,name=root"); + mbeanServer.getObjectInstance(feature); + } catch (InstanceNotFoundException infe2) { + throw new RuntimeException("Feature MBean not found on server."); + } + } + + featureMBean = getMBeanProxy(mbeanServer, feature, FeatureMBean.class, 30, TimeUnit.SECONDS); + + log.info("Executing karaf after-start commands"); + for (String command : config.getCommandsAfterStartAsArray()) { + String cmd = command.trim().split(" ")[0].trim(); + String param = command.trim().split(" ")[1].trim(); + log.info(String.format("command: %s, param: %s", cmd, param)); + if (cmd.equals("feature:repo-add") || cmd.equals("features:addurl")) { + featureMBean.addRepository(param); + } else if (cmd.equals("feature:repo-remove") || cmd.equals("features:removeurl")) { + featureMBean.removeRepository(param); + } else if (cmd.equals("feature:install") || cmd.equals("features:install")) { + featureMBean.installFeature(param); + } else if (cmd.equals("feature:uninstall") || cmd.equals("features:uninstall")) { + featureMBean.uninstallFeature(param); + } else { + throw new RuntimeException(String.format("Unsupported command: '%s'. " + + "Supported commands on Karaf: 'feature:repo-add', 'feature:install'\n" + + "Supported commands on Fuse: 'features:addurl', 'features:install'", cmd)); + } + } + } catch (IOException | RuntimeException | TimeoutException ex) { + stop(); + throw new LifecycleException("Error when executing karaf post-start commands.", ex); + } + } + + FeatureMBean featureMBean; + + public interface FeatureMBean { + + public void addRepository(String repository); + + public void removeRepository(String repository); + + public void installFeature(String feature); + + public void uninstallFeature(String feature); + } + +} diff --git a/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/karaf/CustomKarafContainerConfiguration.java b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/karaf/CustomKarafContainerConfiguration.java new file mode 100644 index 0000000000..05d063c89f --- /dev/null +++ b/testsuite/integration-arquillian/tests/base/src/main/java/org/keycloak/testsuite/arquillian/karaf/CustomKarafContainerConfiguration.java @@ -0,0 +1,25 @@ +package org.keycloak.testsuite.arquillian.karaf; + +import org.jboss.arquillian.container.osgi.karaf.managed.KarafManagedContainerConfiguration; + +/** + * + * @author tkyjovsk + */ +public class CustomKarafContainerConfiguration extends KarafManagedContainerConfiguration { + + private String commandsAfterStart; + + public String getCommandsAfterStart() { + return commandsAfterStart; + } + + public String[] getCommandsAfterStartAsArray() { + return getCommandsAfterStart().trim().split(","); + } + + public void setCommandsAfterStart(String commandsAfterStart) { + this.commandsAfterStart = commandsAfterStart; + } + +} diff --git a/testsuite/integration-arquillian/tests/pom.xml b/testsuite/integration-arquillian/tests/pom.xml index 074a08a1de..b339d11602 100644 --- a/testsuite/integration-arquillian/tests/pom.xml +++ b/testsuite/integration-arquillian/tests/pom.xml @@ -340,6 +340,32 @@ infinispan-core + + jline + jline + 2.12 + + + org.apache.sshd + sshd-core + 0.12.0 + + + org.apache.karaf.shell + org.apache.karaf.shell.console + 3.0.3 + + + org.apache.karaf + org.apache.karaf.client + 3.0.3 + + + org.apache.aries.jmx + org.apache.aries.jmx + 1.1.1 + +