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.test.spi.enricher.resource.ResourceProvider;
|
||||
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.undertow.CustomUndertowContainer;
|
||||
|
||||
|
@ -48,7 +49,8 @@ public class KeycloakArquillianExtension implements LoadableExtension {
|
|||
.service(DeploymentScenarioGenerator.class, DeploymentTargetModifier.class)
|
||||
.service(ApplicationArchiveProcessor.class, DeploymentArchiveProcessor.class)
|
||||
.observer(AuthServerTestEnricher.class)
|
||||
.observer(AppServerTestEnricher.class);
|
||||
.observer(AppServerTestEnricher.class)
|
||||
.observer(H2TestEnricher.class);
|
||||
|
||||
builder
|
||||
.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>
|
||||
<groupId>com.h2database</groupId>
|
||||
<artifactId>h2</artifactId>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.hibernate</groupId>
|
||||
|
@ -450,6 +451,7 @@
|
|||
<adapter.test.props/>
|
||||
<keycloak.home>${containers.home}/keycloak-${project.version}</keycloak.home>
|
||||
<jboss.server.config.dir>${keycloak.home}/standalone/configuration</jboss.server.config.dir>
|
||||
<h2.version>1.3.173</h2.version>
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
|
@ -476,7 +478,7 @@
|
|||
</pluginManagement>
|
||||
</build>
|
||||
</profile>
|
||||
|
||||
|
||||
<profile>
|
||||
<id>auth-server-eap7</id>
|
||||
<properties>
|
||||
|
|
Loading…
Reference in a new issue