Java Code Examples for org.jboss.arquillian.container.spi.Container#getDeployableContainer()

The following examples show how to use org.jboss.arquillian.container.spi.Container#getDeployableContainer() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArquillianSuiteExtension.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
private Container findContainer(ContainerRegistry registry, DeployableContainer<?> deployable) {
    for (Container container : registry.getContainers()) {
        if (container.getDeployableContainer() == deployable) {
            return container;
        }
    }
    return null;
}
 
Example 2
Source File: CacheStatisticsControllerEnricher.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private Supplier<MBeanServerConnection> getJmxServerConnection(JmxInfinispanCacheStatistics annotation) throws MalformedURLException {
    final String host;
    final int port;

    if (annotation.dc() != DC.UNDEFINED && annotation.dcNodeIndex() != -1) {
        ContainerInfo node = suiteContext.get().getAuthServerBackendsInfo(annotation.dc().getDcIndex()).get(annotation.dcNodeIndex());
        Container container = node.getArquillianContainer();
        if (container.getDeployableContainer() instanceof KeycloakOnUndertow) {
            return () -> ManagementFactory.getPlatformMBeanServer();
        }
        host = "localhost";
        port = container.getContainerConfiguration().getContainerProperties().containsKey("managementPort")
          ? Integer.valueOf(container.getContainerConfiguration().getContainerProperties().get("managementPort"))
          : 9990;
    } else {
        host = annotation.host().isEmpty()
          ? System.getProperty((annotation.hostProperty().isEmpty()
            ? "keycloak.connectionsInfinispan.remoteStoreServer"
            : annotation.hostProperty()))
          : annotation.host();

        port = annotation.managementPort() == -1
          ? Integer.valueOf(System.getProperty((annotation.managementPortProperty().isEmpty()
            ? "cache.server.management.port"
            : annotation.managementPortProperty())))
          : annotation.managementPort();
    }


    JMXServiceURL url = new JMXServiceURL("service:jmx:remote+http://" + host + ":" + port);
    return () -> {
        try {
            return jmxConnectorRegistry.get().getConnection(url).getMBeanServerConnection();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    };
}
 
Example 3
Source File: CacheStatisticsControllerEnricher.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private Supplier<MBeanServerConnection> getJmxServerConnection(JmxInfinispanChannelStatistics annotation) throws MalformedURLException {
    final String host;
    final int port;

    if (annotation.dc() != DC.UNDEFINED && annotation.dcNodeIndex() != -1) {
        ContainerInfo node = suiteContext.get().getAuthServerBackendsInfo(annotation.dc().getDcIndex()).get(annotation.dcNodeIndex());
        Container container = node.getArquillianContainer();
        if (container.getDeployableContainer() instanceof KeycloakOnUndertow) {
            return () -> ManagementFactory.getPlatformMBeanServer();
        }
        host = "localhost";
        port = container.getContainerConfiguration().getContainerProperties().containsKey("managementPort")
          ? Integer.valueOf(container.getContainerConfiguration().getContainerProperties().get("managementPort"))
          : 9990;
    } else {
        host = annotation.host().isEmpty()
          ? System.getProperty((annotation.hostProperty().isEmpty()
            ? "keycloak.connectionsInfinispan.remoteStoreServer"
            : annotation.hostProperty()))
          : annotation.host();

        port = annotation.managementPort() == -1
          ? Integer.valueOf(System.getProperty((annotation.managementPortProperty().isEmpty()
            ? "cache.server.management.port"
            : annotation.managementPortProperty())))
          : annotation.managementPort();
    }

    JMXServiceURL url = new JMXServiceURL("service:jmx:remote+http://" + host + ":" + port);
    return () -> {
        try {
            return jmxConnectorRegistry.get().getConnection(url).getMBeanServerConnection();
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    };
}
 
Example 4
Source File: LoadBalancerControllerProvider.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public Object lookup(ArquillianResource resource, Annotation... qualifiers) {
    String balancerName = null;

    // Check for the presence of possible qualifiers
    for (Annotation a : qualifiers) {
        Class<? extends Annotation> annotationType = a.annotationType();

        if (annotationType.equals(LoadBalancer.class)) {
            balancerName = ((LoadBalancer) a).value();
        }
    }

    ContainerRegistry reg = registry.get();
    Container container = null;
    if (balancerName == null || "".equals(balancerName.trim())) {
        if (reg.getContainers().size() == 1) {
            container = reg.getContainers().get(0);
        } else {
            throw new IllegalArgumentException("Invalid load balancer configuration request - need to specify load balancer name in @LoadBalancerController");
        }
    } else {
        container = reg.getContainer(balancerName);
    }

    if (container == null) {
        throw new IllegalArgumentException("Invalid load balancer configuration - load balancer not found: '" + balancerName + "'");
    }
    if (! (container.getDeployableContainer() instanceof LoadBalancerController)) {
        throw new IllegalArgumentException("Invalid load balancer configuration - container " + container.getName() + " is not a load balancer");
    }

    return container.getDeployableContainer();
}
 
Example 5
Source File: MicroProfileJWTTCKArchiveProcessor.java    From tomee with Apache License 2.0 4 votes vote down vote up
@Override
public void process(final Archive<?> applicationArchive, final TestClass testClass) {
    if (!(applicationArchive instanceof WebArchive)) {
        return;
    }
    final WebArchive war = WebArchive.class.cast(applicationArchive);

    // Add Required Libraries
    war.addAsLibrary(JarLocation.jarLocation(TokenUtils.class))
       .addAsLibrary(JarLocation.jarLocation(JWSSigner.class))
       .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");

    // Provide keys required for tests (vendor specific way)
    war.addClass(JWTAuthContextInfoProvider.class);

    // Spec says that vendor specific ways to load the keys take precedence, so we need to remove it in test
    // cases that use the Config approach.
    Stream.of(
            PublicKeyAsPEMTest.class,
            PublicKeyAsPEMLocationTest.class,
            PublicKeyAsFileLocationURLTest.class,
            PublicKeyAsJWKTest.class,
            PublicKeyAsBase64JWKTest.class,
            PublicKeyAsJWKLocationTest.class,
            PublicKeyAsJWKLocationURLTest.class,
            PublicKeyAsJWKSTest.class,
            PublicKeyAsJWKSLocationTest.class,
            IssValidationTest.class,
            ExpClaimValidationTest.class,
            ExpClaimAllowMissingExpValidationTest.class,
            org.apache.tomee.microprofile.tck.jwt.config.PublicKeyAsPEMLocationTest.class,
            org.apache.tomee.microprofile.tck.jwt.config.PublicKeyAsJWKLocationURLTest.class)
          .filter(c -> c.equals(testClass.getJavaClass()))
          .findAny()
          .ifPresent(c -> war.deleteClass(JWTAuthContextInfoProvider.class));

    // MP Config in wrong place - See https://github.com/eclipse/microprofile/issues/46.
    final Map<ArchivePath, Node> content = war.getContent(object -> object.get().matches(".*META-INF/.*"));
    content.forEach((archivePath, node) -> war.addAsResource(node.getAsset(), node.getPath()));

    // Rewrite the correct server port in configuration
    final Container container = containerRegistry.get().getContainer(TargetDescription.DEFAULT);
    if (container.getDeployableContainer() instanceof RemoteTomEEContainer) {
        final RemoteTomEEContainer remoteTomEEContainer =
                (RemoteTomEEContainer) container.getDeployableContainer();
        final RemoteTomEEConfiguration configuration = remoteTomEEContainer.getConfiguration();
        final String httpPort = configuration.getHttpPort() + "";

        final Map<ArchivePath, Node> microprofileProperties = war.getContent(
                object -> object.get().matches(".*META-INF/microprofile-config\\.properties"));
        microprofileProperties.forEach((archivePath, node) -> {
            try {
                final Properties properties = new Properties();
                properties.load(node.getAsset().openStream());
                properties.replaceAll((key, value) -> ((String) value).replaceAll("8080", httpPort + "/" + "KeyEndpoint.war".replaceAll("\\.war", "")));
                final StringWriter stringWriter = new StringWriter();
                properties.store(stringWriter, null);
                war.delete(archivePath);
                war.add(new StringAsset(stringWriter.toString()), node.getPath());
            } catch (final IOException e) {
                e.printStackTrace();
            }
        });
    }

    System.out.println(war.toString(true));
}