Search in sources :

Example 1 with ContainerDef

use of org.jboss.arquillian.config.descriptor.api.ContainerDef in project keycloak by keycloak.

the class RegistryCreator method createRegistry.

public void createRegistry(@Observes ArquillianDescriptor event) {
    ContainerRegistry reg = new Registry(injector.get());
    ServiceLoader serviceLoader = loader.get();
    log.info("arquillian.xml: " + System.getProperty("arquillian.xml"));
    @SuppressWarnings("rawtypes") Collection<DeployableContainer> containers = serviceLoader.all(DeployableContainer.class);
    if (containers.isEmpty()) {
        throw new IllegalStateException("There are not any container adapters on the classpath");
    }
    // arquillian.xml
    List<ContainerDef> containersDefs = event.getContainers();
    // arquillian.xml
    List<GroupDef> groupDefs = event.getGroups();
    // dynamically loaded containers/groups
    addAppServerContainers(containersDefs, groupDefs);
    createRegistry(containersDefs, reg, serviceLoader);
    for (GroupDef group : groupDefs) {
        createRegistry(group.getGroupContainers(), reg, serviceLoader);
    }
    registry.set(reg);
}
Also used : ServiceLoader(org.jboss.arquillian.core.spi.ServiceLoader) DeployableContainer(org.jboss.arquillian.container.spi.client.container.DeployableContainer) ContainerRegistry(org.jboss.arquillian.container.spi.ContainerRegistry) ContainerDef(org.jboss.arquillian.config.descriptor.api.ContainerDef) ContainerRegistry(org.jboss.arquillian.container.spi.ContainerRegistry) GroupDef(org.jboss.arquillian.config.descriptor.api.GroupDef)

Example 2 with ContainerDef

use of org.jboss.arquillian.config.descriptor.api.ContainerDef in project keycloak by keycloak.

the class RegistryCreator method createRegistry.

private void createRegistry(List<ContainerDef> containerDefs, ContainerRegistry reg, ServiceLoader serviceLoader) {
    for (ContainerDef container : containerDefs) {
        if (isAdapterImplClassAvailable(container)) {
            if (isEnabled(container)) {
                log.info("Registering container: " + container.getContainerName());
                reg.create(container, serviceLoader);
            } else {
                log.info("Container is disabled: " + container.getContainerName());
            }
        }
    }
}
Also used : ContainerDef(org.jboss.arquillian.config.descriptor.api.ContainerDef)

Example 3 with ContainerDef

use of org.jboss.arquillian.config.descriptor.api.ContainerDef in project keycloak by keycloak.

the class KeycloakContainerEventsController method copyKeycloakAddUserFile.

/**
 * Copy keycloak-add-user.json only if it is jboss container (has jbossHome property).
 */
private void copyKeycloakAddUserFile() {
    for (Container c : containerRegistry.get().getContainers()) {
        log.tracef("Copy keycloak-add-user.json for container [%s]", c.getName());
        ContainerDef conf = c.getContainerConfiguration();
        String jbossHome = conf.getContainerProperty("jbossHome");
        if (jbossHome != null && !jbossHome.isEmpty()) {
            File originalUserAddJsonFile = new File("target/test-classes/keycloak-add-user.json");
            File userAddJsonFile = new File(conf.getContainerProperty("jbossHome") + "/standalone/configuration/keycloak-add-user.json");
            try {
                FileUtils.copyFile(originalUserAddJsonFile, userAddJsonFile);
                log.infof("original user file (%s) has been copied to (%s)", originalUserAddJsonFile.getAbsolutePath(), userAddJsonFile.getAbsolutePath());
            } catch (IOException e) {
                log.warnf(e, "Problem: keycloak-add-user.json file not copied to %s.", userAddJsonFile.getAbsolutePath());
            }
        }
    }
}
Also used : RestartContainer(org.keycloak.testsuite.arquillian.annotation.RestartContainer) Container(org.jboss.arquillian.container.spi.Container) ContainerDef(org.jboss.arquillian.config.descriptor.api.ContainerDef) IOException(java.io.IOException) File(java.io.File)

Example 4 with ContainerDef

use of org.jboss.arquillian.config.descriptor.api.ContainerDef in project keycloak by keycloak.

the class KeycloakContainerEventsController method removeKeycloakAddUserFile.

/**
 * Remove keycloak-add-user.json file from server config if exists.
 * It should be removed by previous successful start of the server.
 * This method is there just to make sure it is removed.
 */
private void removeKeycloakAddUserFile() {
    for (Container c : containerRegistry.get().getContainers()) {
        ContainerDef conf = c.getContainerConfiguration();
        String jbossHome = conf.getContainerProperty("jbossHome");
        if (jbossHome != null && !jbossHome.isEmpty()) {
            File adminUserJsonFile = new File(jbossHome + "/standalone/configuration/keycloak-add-user.json");
            if (log.isTraceEnabled()) {
                log.tracef("File %s exists=%s", adminUserJsonFile.getAbsolutePath(), adminUserJsonFile.exists());
            }
            adminUserJsonFile.delete();
        }
    }
}
Also used : RestartContainer(org.keycloak.testsuite.arquillian.annotation.RestartContainer) Container(org.jboss.arquillian.container.spi.Container) ContainerDef(org.jboss.arquillian.config.descriptor.api.ContainerDef) File(java.io.File)

Example 5 with ContainerDef

use of org.jboss.arquillian.config.descriptor.api.ContainerDef 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

ContainerDef (org.jboss.arquillian.config.descriptor.api.ContainerDef)5 Container (org.jboss.arquillian.container.spi.Container)3 RestartContainer (org.keycloak.testsuite.arquillian.annotation.RestartContainer)3 File (java.io.File)2 IOException (java.io.IOException)2 GroupDef (org.jboss.arquillian.config.descriptor.api.GroupDef)1 ContainerRegistry (org.jboss.arquillian.container.spi.ContainerRegistry)1 DeployableContainer (org.jboss.arquillian.container.spi.client.container.DeployableContainer)1 ServiceLoader (org.jboss.arquillian.core.spi.ServiceLoader)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