Search in sources :

Example 1 with RestartContainer

use of org.keycloak.testsuite.arquillian.annotation.RestartContainer in project keycloak by keycloak.

the class KeycloakContainerEventsController method execute.

@Override
public void execute(BeforeClass event) {
    if (event.getTestClass().isAnnotationPresent(RestartContainer.class)) {
        // stop executing the test - remote container cannot be restarted
        ContainerAssume.assumeNotAuthServerRemote();
        RestartContainer restartContainer = event.getTestClass().getAnnotation(RestartContainer.class);
        beforeOriginalContainerStop(restartContainer);
        container.fire(new StopManualContainers());
        container.fire(new StopSuiteContainers());
        beforeNewContainerStart(restartContainer);
        container.fire(new StartClassContainers());
        container.fire(new StartSuiteContainers());
    }
    super.execute(event);
}
Also used : StopSuiteContainers(org.jboss.arquillian.container.spi.event.StopSuiteContainers) StartSuiteContainers(org.jboss.arquillian.container.spi.event.StartSuiteContainers) RestartContainer(org.keycloak.testsuite.arquillian.annotation.RestartContainer) StopManualContainers(org.jboss.arquillian.container.spi.event.StopManualContainers) StartClassContainers(org.jboss.arquillian.container.spi.event.StartClassContainers)

Example 2 with RestartContainer

use of org.keycloak.testsuite.arquillian.annotation.RestartContainer in project keycloak by keycloak.

the class KeycloakContainerEventsController method deployAndDropAllTables.

/**
 * Drop all KeycloakDS database tables using liquibase dropAll method.
 * @param restartContainer to pass more information from test annotation
 */
private void deployAndDropAllTables(RestartContainer restartContainer) {
    for (Container c : containerRegistry.get().getContainers()) {
        String containerName = c.getName();
        log.infof("Deploy and dropAll at '%s'", containerName);
        if (containerName == null || !containerName.startsWith("auth-server")) {
            log.infof("Skipping deployAndDropAllTables for '%s'", containerName);
            continue;
        }
        ContainerDef conf = c.getContainerConfiguration();
        String mgmtPort = conf.getContainerProperty("managementPort");
        if (mgmtPort == null || mgmtPort.isEmpty()) {
            log.warnf("Skipping deployAndDropAllTables for '%s' due to not defined 'managementPort' property.", containerName);
            continue;
        }
        OnlineManagementClient client = null;
        try {
            client = ManagementClient.online(OnlineOptions.standalone().hostAndPort("localhost", Integer.valueOf(mgmtPort).intValue()).build());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        try {
            WebArchive war = ShrinkWrap.create(WebArchive.class, DropAllServlet.WAR_NAME).addClass(DropAllServlet.class).addAsWebInfResource(new StringAsset(DropAllServlet.jbossDeploymentStructureContent), "jboss-deployment-structure.xml");
            client.apply(new Deploy.Builder(war.as(ZipExporter.class).exportAsInputStream(), DropAllServlet.WAR_NAME, true).build());
            if (restartContainer.intializeDatabaseWait() > 0) {
                try {
                    Thread.sleep(restartContainer.intializeDatabaseWait());
                } catch (InterruptedException e) {
                    log.warn(e);
                }
            }
            client.apply(new Undeploy.Builder(DropAllServlet.WAR_NAME).build());
        } catch (CommandFailedException e) {
            log.error(e);
            throw new RuntimeException(e);
        }
    }
}
Also used : RestartContainer(org.keycloak.testsuite.arquillian.annotation.RestartContainer) Container(org.jboss.arquillian.container.spi.Container) StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) DropAllServlet(org.keycloak.helpers.DropAllServlet) OnlineManagementClient(org.wildfly.extras.creaper.core.online.OnlineManagementClient) ContainerDef(org.jboss.arquillian.config.descriptor.api.ContainerDef) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) IOException(java.io.IOException) CommandFailedException(org.wildfly.extras.creaper.core.CommandFailedException)

Aggregations

RestartContainer (org.keycloak.testsuite.arquillian.annotation.RestartContainer)2 IOException (java.io.IOException)1 ContainerDef (org.jboss.arquillian.config.descriptor.api.ContainerDef)1 Container (org.jboss.arquillian.container.spi.Container)1 StartClassContainers (org.jboss.arquillian.container.spi.event.StartClassContainers)1 StartSuiteContainers (org.jboss.arquillian.container.spi.event.StartSuiteContainers)1 StopManualContainers (org.jboss.arquillian.container.spi.event.StopManualContainers)1 StopSuiteContainers (org.jboss.arquillian.container.spi.event.StopSuiteContainers)1 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)1 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)1 DropAllServlet (org.keycloak.helpers.DropAllServlet)1 CommandFailedException (org.wildfly.extras.creaper.core.CommandFailedException)1 OnlineManagementClient (org.wildfly.extras.creaper.core.online.OnlineManagementClient)1