Search in sources :

Example 1 with DeploymentDescription

use of org.jboss.arquillian.container.spi.client.deployment.DeploymentDescription in project keycloak by keycloak.

the class DeploymentTargetModifier method generate.

@Override
public List<DeploymentDescription> generate(TestClass testClass) {
    TestContext context = testContext.get();
    if (context.isAdapterTest() && !context.isAdapterContainerEnabled() && !context.isAdapterContainerEnabledCluster()) {
        // adapter test will be skipped, no need to genarate dependencies
        return new ArrayList<>();
    }
    List<DeploymentDescription> deployments = super.generate(testClass);
    checkTestDeployments(deployments, testClass, context.isAdapterTest());
    Set<String> appServerQualifiers = getAppServerQualifiers(testClass.getJavaClass());
    // no adapter test
    if (appServerQualifiers.isEmpty())
        return deployments;
    String appServerQualifier = appServerQualifiers.stream().filter(q -> q.contains(AppServerTestEnricher.CURRENT_APP_SERVER)).findAny().orElse(null);
    if (appServerQualifier.contains(";"))
        return deployments;
    if (appServerQualifier != null && !appServerQualifier.isEmpty()) {
        for (DeploymentDescription deployment : deployments) {
            final boolean containerMatches = deployment.getTarget() != null && deployment.getTarget().getName().startsWith(appServerQualifier);
            if (deployment.getTarget() == null || Objects.equals(deployment.getTarget().getName(), "_DEFAULT_")) {
                log.debug("Setting target container for " + deployment.getName() + ": " + appServerQualifier);
                deployment.setTarget(new TargetDescription(appServerQualifier));
            } else if (!containerMatches && !deployment.getArchive().getName().equals("run-on-server-classes.war")) {
                // run-on-server deployment can have different target
                throw new RuntimeException("Inconsistency found: target container for " + deployment.getName() + " is set to " + deployment.getTarget().getName() + " but the test class targets " + appServerQualifier);
            }
        }
    }
    return deployments;
}
Also used : DeploymentDescription(org.jboss.arquillian.container.spi.client.deployment.DeploymentDescription) ArrayList(java.util.ArrayList) TargetDescription(org.jboss.arquillian.container.spi.client.deployment.TargetDescription)

Example 2 with DeploymentDescription

use of org.jboss.arquillian.container.spi.client.deployment.DeploymentDescription in project keycloak by keycloak.

the class DeploymentTargetModifier method checkTestDeployments.

private void checkTestDeployments(List<DeploymentDescription> descriptions, TestClass testClass, boolean isAdapterTest) {
    for (DeploymentDescription deployment : descriptions) {
        if (deployment.getTarget() != null) {
            String containerQualifier = deployment.getTarget().getName();
            if (AUTH_SERVER_CURRENT.equals(containerQualifier) || (!isAdapterTest && "_DEFAULT_".equals(containerQualifier))) {
                String newAuthServerQualifier = AuthServerTestEnricher.AUTH_SERVER_CONTAINER;
                updateServerQualifier(deployment, testClass, newAuthServerQualifier);
            } else if (containerQualifier.contains(APP_SERVER_CURRENT)) {
                String suffix = containerQualifier.split(APP_SERVER_CURRENT)[1];
                String newAppServerQualifier = ContainerConstants.APP_SERVER_PREFIX + AppServerTestEnricher.CURRENT_APP_SERVER + "-" + suffix;
                updateServerQualifier(deployment, testClass, newAppServerQualifier);
            } else {
                String newServerQualifier = StringPropertyReplacer.replaceProperties(containerQualifier);
                if (!newServerQualifier.equals(containerQualifier)) {
                    updateServerQualifier(deployment, testClass, newServerQualifier);
                }
            }
        }
    }
}
Also used : DeploymentDescription(org.jboss.arquillian.container.spi.client.deployment.DeploymentDescription)

Example 3 with DeploymentDescription

use of org.jboss.arquillian.container.spi.client.deployment.DeploymentDescription in project wildfly-swarm by wildfly-swarm.

the class DefaultDeploymentScenarioGenerator method generate.

@Override
public List<DeploymentDescription> generate(TestClass testClass) {
    DefaultDeployment anno = testClass.getAnnotation(DefaultDeployment.class);
    if (anno == null) {
        return super.generate(testClass);
    }
    String classPrefix = (anno.type() == DefaultDeployment.Type.JAR ? "" : "WEB-INF/classes");
    Archive<?> archive;
    if (DefaultDeployment.Type.WAR.equals(anno.type())) {
        WebArchive webArchive = ShrinkWrap.create(WebArchive.class, testClass.getJavaClass().getSimpleName() + ".war");
        // Add the marker to also include the project dependencies
        MarkerContainer.addMarker(webArchive, DependenciesContainer.ALL_DEPENDENCIES_MARKER);
        archive = webArchive;
    } else {
        archive = ShrinkWrap.create(JavaArchive.class, testClass.getJavaClass().getSimpleName() + ".jar");
    }
    ClassLoader cl = testClass.getJavaClass().getClassLoader();
    Set<CodeSource> codeSources = new HashSet<>();
    URLPackageScanner.Callback callback = (className, asset) -> {
        ArchivePath classNamePath = AssetUtil.getFullPathForClassResource(className);
        ArchivePath location = new BasicPath(classPrefix, classNamePath);
        archive.add(asset, location);
        try {
            Class<?> cls = cl.loadClass(className);
            codeSources.add(cls.getProtectionDomain().getCodeSource());
        } catch (ClassNotFoundException | NoClassDefFoundError e) {
        // e.printStackTrace();
        }
    };
    URLPackageScanner scanner = URLPackageScanner.newInstance(true, cl, callback, testClass.getJavaClass().getPackage().getName());
    scanner.scanPackage();
    Set<String> prefixes = codeSources.stream().map(e -> e.getLocation().toExternalForm()).collect(Collectors.toSet());
    try {
        List<URL> resources = Collections.list(cl.getResources(""));
        resources.stream().filter(e -> {
            for (String prefix : prefixes) {
                if (e.toExternalForm().startsWith(prefix)) {
                    return true;
                }
            }
            return false;
        }).filter(e -> e.getProtocol().equals("file")).map(e -> getPlatformPath(e.getPath())).map(e -> Paths.get(e)).filter(e -> Files.isDirectory(e)).forEach(e -> {
            try {
                Files.walkFileTree(e, new SimpleFileVisitor<Path>() {

                    public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                        if (!file.toString().endsWith(".class")) {
                            String location = javaSlashize(handleExceptionalCases(archive, e.relativize(file)));
                            archive.add(new FileAsset(file.toFile()), location);
                        }
                        return super.visitFile(file, attrs);
                    }
                });
            } catch (IOException e1) {
            }
        });
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    /*
        Map<ArchivePath, Node> content = archive.getContent();
        for (ArchivePath each : content.keySet()) {
            System.err.println(" --> " + each);
        }
        */
    DeploymentModules deploymentModules = testClass.getAnnotation(DeploymentModules.class);
    if (deploymentModules != null) {
        for (DeploymentModule each : deploymentModules.value()) {
            archive.as(JARArchive.class).addModule(each.name(), each.slot());
        }
    }
    DeploymentModule deploymentModule = testClass.getAnnotation(DeploymentModule.class);
    if (deploymentModule != null) {
        archive.as(JARArchive.class).addModule(deploymentModule.name(), deploymentModule.slot());
    }
    DeploymentDescription description = new DeploymentDescription(testClass.getName(), archive);
    Class<?> mainClass = anno.main();
    if (mainClass != Void.class) {
        archive.add(new StringAsset(mainClass.getName()), "META-INF/arquillian-main-class");
    }
    description.shouldBeTestable(anno.testable());
    return Collections.singletonList(description);
}
Also used : URL(java.net.URL) AnnotationDeploymentScenarioGenerator(org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator) DependenciesContainer(org.wildfly.swarm.spi.api.DependenciesContainer) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) AssetUtil(org.jboss.shrinkwrap.impl.base.asset.AssetUtil) URI(java.net.URI) DeploymentModule(org.wildfly.swarm.spi.api.annotations.DeploymentModule) Path(java.nio.file.Path) TestClass(org.jboss.arquillian.test.spi.TestClass) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) MarkerContainer(org.wildfly.swarm.spi.api.MarkerContainer) DefaultDeployment(org.wildfly.swarm.arquillian.DefaultDeployment) ShrinkWrap(org.jboss.shrinkwrap.api.ShrinkWrap) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) Files(java.nio.file.Files) DeploymentModules(org.wildfly.swarm.spi.api.annotations.DeploymentModules) Set(java.util.Set) JARArchive(org.wildfly.swarm.spi.api.JARArchive) IOException(java.io.IOException) Archive(org.jboss.shrinkwrap.api.Archive) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) DeploymentDescription(org.jboss.arquillian.container.spi.client.deployment.DeploymentDescription) Collectors(java.util.stream.Collectors) StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) FileVisitResult(java.nio.file.FileVisitResult) List(java.util.List) URLPackageScanner(org.jboss.shrinkwrap.impl.base.URLPackageScanner) Paths(java.nio.file.Paths) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) FileAsset(org.jboss.shrinkwrap.api.asset.FileAsset) CodeSource(java.security.CodeSource) Collections(java.util.Collections) BasicPath(org.jboss.shrinkwrap.impl.base.path.BasicPath) StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) DefaultDeployment(org.wildfly.swarm.arquillian.DefaultDeployment) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) URL(java.net.URL) DeploymentModules(org.wildfly.swarm.spi.api.annotations.DeploymentModules) ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) URLPackageScanner(org.jboss.shrinkwrap.impl.base.URLPackageScanner) DeploymentDescription(org.jboss.arquillian.container.spi.client.deployment.DeploymentDescription) JARArchive(org.wildfly.swarm.spi.api.JARArchive) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) HashSet(java.util.HashSet) ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) Path(java.nio.file.Path) BasicPath(org.jboss.shrinkwrap.impl.base.path.BasicPath) FileAsset(org.jboss.shrinkwrap.api.asset.FileAsset) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) FileVisitResult(java.nio.file.FileVisitResult) IOException(java.io.IOException) CodeSource(java.security.CodeSource) DeploymentModule(org.wildfly.swarm.spi.api.annotations.DeploymentModule) BasicPath(org.jboss.shrinkwrap.impl.base.path.BasicPath) TestClass(org.jboss.arquillian.test.spi.TestClass)

Aggregations

DeploymentDescription (org.jboss.arquillian.container.spi.client.deployment.DeploymentDescription)3 ArrayList (java.util.ArrayList)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URL (java.net.URL)1 FileVisitResult (java.nio.file.FileVisitResult)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 SimpleFileVisitor (java.nio.file.SimpleFileVisitor)1 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)1 CodeSource (java.security.CodeSource)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 TargetDescription (org.jboss.arquillian.container.spi.client.deployment.TargetDescription)1 AnnotationDeploymentScenarioGenerator (org.jboss.arquillian.container.test.impl.client.deployment.AnnotationDeploymentScenarioGenerator)1 TestClass (org.jboss.arquillian.test.spi.TestClass)1