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);
}
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());
}
}
}
}
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());
}
}
}
}
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();
}
}
}
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);
}
}
}
Aggregations