KEYCLOAK-1678: H2TestEnricher for running H2 server instance during integration tests.
This commit is contained in:
parent
a264c15886
commit
89250a69fb
3 changed files with 46 additions and 2 deletions
|
@ -26,6 +26,7 @@ import org.jboss.arquillian.core.spi.LoadableExtension;
|
||||||
import org.jboss.arquillian.graphene.location.CustomizableURLResourceProvider;
|
import org.jboss.arquillian.graphene.location.CustomizableURLResourceProvider;
|
||||||
import org.jboss.arquillian.test.spi.enricher.resource.ResourceProvider;
|
import org.jboss.arquillian.test.spi.enricher.resource.ResourceProvider;
|
||||||
import org.jboss.arquillian.test.spi.execution.TestExecutionDecider;
|
import org.jboss.arquillian.test.spi.execution.TestExecutionDecider;
|
||||||
|
import org.keycloak.testsuite.arquillian.h2.H2TestEnricher;
|
||||||
import org.keycloak.testsuite.arquillian.migration.MigrationTestExecutionDecider;
|
import org.keycloak.testsuite.arquillian.migration.MigrationTestExecutionDecider;
|
||||||
import org.keycloak.testsuite.arquillian.undertow.CustomUndertowContainer;
|
import org.keycloak.testsuite.arquillian.undertow.CustomUndertowContainer;
|
||||||
|
|
||||||
|
@ -48,7 +49,8 @@ public class KeycloakArquillianExtension implements LoadableExtension {
|
||||||
.service(DeploymentScenarioGenerator.class, DeploymentTargetModifier.class)
|
.service(DeploymentScenarioGenerator.class, DeploymentTargetModifier.class)
|
||||||
.service(ApplicationArchiveProcessor.class, DeploymentArchiveProcessor.class)
|
.service(ApplicationArchiveProcessor.class, DeploymentArchiveProcessor.class)
|
||||||
.observer(AuthServerTestEnricher.class)
|
.observer(AuthServerTestEnricher.class)
|
||||||
.observer(AppServerTestEnricher.class);
|
.observer(AppServerTestEnricher.class)
|
||||||
|
.observer(H2TestEnricher.class);
|
||||||
|
|
||||||
builder
|
builder
|
||||||
.service(DeployableContainer.class, CustomUndertowContainer.class);
|
.service(DeployableContainer.class, CustomUndertowContainer.class);
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package org.keycloak.testsuite.arquillian.h2;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
|
import org.jboss.arquillian.core.api.annotation.Observes;
|
||||||
|
import org.jboss.arquillian.test.spi.event.suite.AfterSuite;
|
||||||
|
import org.jboss.arquillian.test.spi.event.suite.BeforeSuite;
|
||||||
|
import org.jboss.logging.Logger;
|
||||||
|
import org.h2.tools.Server;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts H2 before suite and stops it after.
|
||||||
|
*
|
||||||
|
* @author tkyjovsk
|
||||||
|
*/
|
||||||
|
public class H2TestEnricher {
|
||||||
|
|
||||||
|
protected final Logger log = Logger.getLogger(this.getClass());
|
||||||
|
|
||||||
|
boolean runH2 = Boolean.parseBoolean(System.getProperty("run.h2", "false"));
|
||||||
|
|
||||||
|
private Server server = null;
|
||||||
|
|
||||||
|
public void startH2(@Observes(precedence = 2) BeforeSuite event) throws SQLException {
|
||||||
|
if (runH2) {
|
||||||
|
log.info("Starting H2 database.");
|
||||||
|
server = Server.createTcpServer();
|
||||||
|
server.start();
|
||||||
|
log.info(String.format("URL: %s", server.getURL()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void stopH2(@Observes(precedence = -2) AfterSuite event) {
|
||||||
|
if (runH2 && server.isRunning(false)) {
|
||||||
|
log.info("Stopping H2 database.");
|
||||||
|
server.stop();
|
||||||
|
assert !server.isRunning(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -398,6 +398,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.h2database</groupId>
|
<groupId>com.h2database</groupId>
|
||||||
<artifactId>h2</artifactId>
|
<artifactId>h2</artifactId>
|
||||||
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hibernate</groupId>
|
<groupId>org.hibernate</groupId>
|
||||||
|
@ -450,6 +451,7 @@
|
||||||
<adapter.test.props/>
|
<adapter.test.props/>
|
||||||
<keycloak.home>${containers.home}/keycloak-${project.version}</keycloak.home>
|
<keycloak.home>${containers.home}/keycloak-${project.version}</keycloak.home>
|
||||||
<jboss.server.config.dir>${keycloak.home}/standalone/configuration</jboss.server.config.dir>
|
<jboss.server.config.dir>${keycloak.home}/standalone/configuration</jboss.server.config.dir>
|
||||||
|
<h2.version>1.3.173</h2.version>
|
||||||
</properties>
|
</properties>
|
||||||
<dependencies>
|
<dependencies>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
@ -476,7 +478,7 @@
|
||||||
</pluginManagement>
|
</pluginManagement>
|
||||||
</build>
|
</build>
|
||||||
</profile>
|
</profile>
|
||||||
|
|
||||||
<profile>
|
<profile>
|
||||||
<id>auth-server-eap7</id>
|
<id>auth-server-eap7</id>
|
||||||
<properties>
|
<properties>
|
||||||
|
|
Loading…
Reference in a new issue