Author: rmannibucau Date: Wed Oct 19 19:40:46 2016 New Revision: 1765704 URL: http://svn.apache.org/viewvc?rev=1765704&view=rev Log: arquillian container
Added: openwebbeans/microwave/trunk/microwave-arquillian/ openwebbeans/microwave/trunk/microwave-arquillian/pom.xml openwebbeans/microwave/trunk/microwave-arquillian/src/ openwebbeans/microwave/trunk/microwave-arquillian/src/main/ openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/ openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/ openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/apache/ openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/apache/microwave/ openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/apache/microwave/arquillian/ openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/apache/microwave/arquillian/MicrowaveConfiguration.java openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/apache/microwave/arquillian/MicrowaveContainer.java openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/apache/microwave/arquillian/MicrowaveExtension.java openwebbeans/microwave/trunk/microwave-arquillian/src/main/resources/ openwebbeans/microwave/trunk/microwave-arquillian/src/main/resources/META-INF/ openwebbeans/microwave/trunk/microwave-arquillian/src/main/resources/META-INF/services/ openwebbeans/microwave/trunk/microwave-arquillian/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension openwebbeans/microwave/trunk/microwave-arquillian/src/test/ openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/ openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/ openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/apache/ openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/apache/microwave/ openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/apache/microwave/arquillian/ openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/apache/microwave/arquillian/MicrowaveContainerTest.java openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/app/ openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/app/Endpoint.java openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/app/Injectable.java openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/app/RsApp.java Modified: openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/Microwave.java openwebbeans/microwave/trunk/pom.xml Added: openwebbeans/microwave/trunk/microwave-arquillian/pom.xml URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/microwave-arquillian/pom.xml?rev=1765704&view=auto ============================================================================== --- openwebbeans/microwave/trunk/microwave-arquillian/pom.xml (added) +++ openwebbeans/microwave/trunk/microwave-arquillian/pom.xml Wed Oct 19 19:40:46 2016 @@ -0,0 +1,64 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://maven.apache.org/POM/4.0.0 + http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <artifactId>microwave</artifactId> + <groupId>org.apache.microwave</groupId> + <version>0.0.1-SNAPSHOT</version> + </parent> + <modelVersion>4.0.0</modelVersion> + + <artifactId>microwave-arquillian</artifactId> + <name>Microwave :: Arquillian</name> + + <properties> + <arquillian.version>1.1.11.Final</arquillian.version> + </properties> + + <dependencies> + <dependency> + <groupId>org.jboss.arquillian.container</groupId> + <artifactId>arquillian-container-spi</artifactId> + <version>${arquillian.version}</version> + </dependency> + <dependency> + <groupId>org.apache.microwave</groupId> + <artifactId>microwave-core</artifactId> + <version>${project.version}</version> + </dependency> + + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>${junit.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.jboss.arquillian.junit</groupId> + <artifactId>arquillian-junit-container</artifactId> + <version>${arquillian.version}</version> + <scope>test</scope> + </dependency> + </dependencies> +</project> Added: openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/apache/microwave/arquillian/MicrowaveConfiguration.java URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/apache/microwave/arquillian/MicrowaveConfiguration.java?rev=1765704&view=auto ============================================================================== --- openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/apache/microwave/arquillian/MicrowaveConfiguration.java (added) +++ openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/apache/microwave/arquillian/MicrowaveConfiguration.java Wed Oct 19 19:40:46 2016 @@ -0,0 +1,442 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.microwave.arquillian; + +import org.apache.catalina.Realm; +import org.apache.microwave.Microwave; +import org.apache.xbean.recipe.ObjectRecipe; +import org.jboss.arquillian.config.descriptor.api.Multiline; +import org.jboss.arquillian.container.spi.ConfigurationException; +import org.jboss.arquillian.container.spi.client.container.ContainerConfiguration; + +import java.io.ByteArrayInputStream; +import java.io.File; +import java.io.IOException; +import java.lang.reflect.Field; +import java.nio.charset.StandardCharsets; +import java.util.Properties; +import java.util.stream.Stream; + +import static java.util.function.Function.identity; +import static java.util.stream.Collectors.toList; +import static java.util.stream.Collectors.toMap; + +public class MicrowaveConfiguration implements ContainerConfiguration { + private int httpPort = -1; + private int httpsPort = 8443; + private int stopPort = -1; + private String host = "localhost"; + private String dir; + private File serverXml; + private boolean keepServerXmlAsThis; + private Properties properties = new Properties(); + private boolean quickSession = true; + private boolean skipHttp; + private boolean ssl; + private String keystoreFile; + private String keystorePass; + private String keystoreType = "JKS"; + private String clientAuth; + private String keyAlias; + private String sslProtocol; + private String webXml; + private boolean http2; + private String tempDir = new File(System.getProperty("java.io.tmpdir"), "microwave_" + System.nanoTime()).getAbsolutePath(); + private boolean webResourceCached = true; + private String conf; + private boolean deleteBaseOnStartup = true; + private String jaxrsMapping = "/*"; + private boolean cdiConversation; + private boolean jaxrsProviderSetup = true; + private boolean loggingGlobalSetup = true; + private String users; + private String roles; + private String loginConfig; + private String securityConstraints; + private String realm; + + @Override + public void validate() throws ConfigurationException { + // no-op + } + + Microwave.Builder toMicrowaveConfiguration() { + final Microwave.Builder builder = new Microwave.Builder(); + for (final Field field : MicrowaveConfiguration.class.getDeclaredFields()) { + final String name = field.getName(); + if ("users".equals(name) || "roles".equals(name) + || "loginConfig".equals(name) || "securityConstraints".equals(name) + || "realm".equals(name)) { + continue; // specific syntax + } + + try { + final Field configField = Microwave.Builder.class.getDeclaredField(field.getName()); + if (!configField.getType().equals(field.getType())) { + continue; + } + if (!field.isAccessible()) { + field.setAccessible(true); + } + + final Object value = field.get(this); + if (value != null) { + if (!configField.isAccessible()) { + configField.setAccessible(true); + } + configField.set(builder, value); + } + } catch (final NoSuchFieldException nsfe) { + // ignored + } catch (final Exception e) { + throw new IllegalStateException(e); + } + } + + if (httpPort < 0) { + builder.randomHttpPort(); + } + + // for Map use properties + if (users != null) { + final Properties properties = new Properties() {{ + try { + load(new ByteArrayInputStream(users.getBytes(StandardCharsets.UTF_8))); + } catch (final IOException e) { + throw new IllegalStateException(e); + } + }}; + builder.setUsers(properties.stringPropertyNames().stream().collect(toMap(identity(), properties::getProperty))); + } + if (roles != null) { + final Properties properties = new Properties() {{ + try { + load(new ByteArrayInputStream(roles.getBytes(StandardCharsets.UTF_8))); + } catch (final IOException e) { + throw new IllegalStateException(e); + } + }}; + builder.setRoles(properties.stringPropertyNames().stream().collect(toMap(identity(), properties::getProperty))); + } + + // for other not simple type use the Cli syntax + final ClassLoader loader = Thread.currentThread().getContextClassLoader(); + if (realm != null) { + try { + int end = realm.indexOf(':'); + if (end < 0) { + builder.setRealm(Realm.class.cast(loader.loadClass(realm).newInstance())); + } else { + final ObjectRecipe recipe = new ObjectRecipe(realm.substring(0, end)); + Stream.of(realm.substring(end + 1, realm.length()).split(";")) + .map(v -> v.split("=")) + .forEach(v -> recipe.setProperty(v[0], v[1])); + builder.setRealm(Realm.class.cast(recipe.create(loader))); + } + } catch (final Exception cnfe) { + throw new IllegalArgumentException(realm); + } + } + if (securityConstraints != null) { + builder.setSecurityConstraints(Stream.of(securityConstraints.split("|")) + .map(item -> { + try { + final ObjectRecipe recipe = new ObjectRecipe(Microwave.SecurityConstaintBuilder.class); + Stream.of(item.split(";")) + .map(v -> v.split("=")) + .forEach(v -> recipe.setProperty(v[0], v[1])); + return Microwave.SecurityConstaintBuilder.class.cast(recipe.create(loader)); + } catch (final Exception cnfe) { + throw new IllegalArgumentException(securityConstraints); + } + }).collect(toList())); + } + if (loginConfig != null) { + try { + final ObjectRecipe recipe = new ObjectRecipe(Microwave.LoginConfigBuilder.class); + Stream.of(loginConfig.split(";")) + .map(v -> v.split("=")) + .forEach(v -> recipe.setProperty(v[0], v[1])); + builder.setLoginConfig(Microwave.LoginConfigBuilder.class.cast(recipe.create(loader))); + } catch (final Exception cnfe) { + throw new IllegalArgumentException(loginConfig); + } + } + + return builder; + } + + public int getHttpPort() { + return httpPort; + } + + public void setHttpPort(final int httpPort) { + this.httpPort = httpPort; + } + + public int getHttpsPort() { + return httpsPort; + } + + public void setHttpsPort(final int httpsPort) { + this.httpsPort = httpsPort; + } + + public int getStopPort() { + return stopPort; + } + + public void setStopPort(final int stopPort) { + this.stopPort = stopPort; + } + + public String getHost() { + return host; + } + + public void setHost(final String host) { + this.host = host; + } + + public String getDir() { + return dir; + } + + public void setDir(final String dir) { + this.dir = dir; + } + + public File getServerXml() { + return serverXml; + } + + public void setServerXml(final File serverXml) { + this.serverXml = serverXml; + } + + public boolean isKeepServerXmlAsThis() { + return keepServerXmlAsThis; + } + + public void setKeepServerXmlAsThis(final boolean keepServerXmlAsThis) { + this.keepServerXmlAsThis = keepServerXmlAsThis; + } + + public Properties getProperties() { + return properties; + } + + public void setProperties(final Properties properties) { + this.properties = properties; + } + + public boolean isQuickSession() { + return quickSession; + } + + public void setQuickSession(final boolean quickSession) { + this.quickSession = quickSession; + } + + public boolean isSkipHttp() { + return skipHttp; + } + + public void setSkipHttp(boolean skipHttp) { + this.skipHttp = skipHttp; + } + + public boolean isSsl() { + return ssl; + } + + public void setSsl(final boolean ssl) { + this.ssl = ssl; + } + + public String getKeystoreFile() { + return keystoreFile; + } + + public void setKeystoreFile(final String keystoreFile) { + this.keystoreFile = keystoreFile; + } + + public String getKeystorePass() { + return keystorePass; + } + + public void setKeystorePass(final String keystorePass) { + this.keystorePass = keystorePass; + } + + public String getKeystoreType() { + return keystoreType; + } + + public void setKeystoreType(final String keystoreType) { + this.keystoreType = keystoreType; + } + + public String getClientAuth() { + return clientAuth; + } + + public void setClientAuth(final String clientAuth) { + this.clientAuth = clientAuth; + } + + public String getKeyAlias() { + return keyAlias; + } + + public void setKeyAlias(final String keyAlias) { + this.keyAlias = keyAlias; + } + + public String getSslProtocol() { + return sslProtocol; + } + + public void setSslProtocol(final String sslProtocol) { + this.sslProtocol = sslProtocol; + } + + public String getWebXml() { + return webXml; + } + + public void setWebXml(final String webXml) { + this.webXml = webXml; + } + + public boolean isHttp2() { + return http2; + } + + public void setHttp2(final boolean http2) { + this.http2 = http2; + } + + public String getTempDir() { + return tempDir; + } + + public void setTempDir(final String tempDir) { + this.tempDir = tempDir; + } + + public boolean isWebResourceCached() { + return webResourceCached; + } + + public void setWebResourceCached(final boolean webResourceCached) { + this.webResourceCached = webResourceCached; + } + + public String getConf() { + return conf; + } + + public void setConf(final String conf) { + this.conf = conf; + } + + public boolean isDeleteBaseOnStartup() { + return deleteBaseOnStartup; + } + + public void setDeleteBaseOnStartup(final boolean deleteBaseOnStartup) { + this.deleteBaseOnStartup = deleteBaseOnStartup; + } + + public String getJaxrsMapping() { + return jaxrsMapping; + } + + public void setJaxrsMapping(final String jaxrsMapping) { + this.jaxrsMapping = jaxrsMapping; + } + + public boolean isCdiConversation() { + return cdiConversation; + } + + public void setCdiConversation(final boolean cdiConversation) { + this.cdiConversation = cdiConversation; + } + + public boolean isJaxrsProviderSetup() { + return jaxrsProviderSetup; + } + + public void setJaxrsProviderSetup(final boolean jaxrsProviderSetup) { + this.jaxrsProviderSetup = jaxrsProviderSetup; + } + + public boolean isLoggingGlobalSetup() { + return loggingGlobalSetup; + } + + public void setLoggingGlobalSetup(final boolean loggingGlobalSetup) { + this.loggingGlobalSetup = loggingGlobalSetup; + } + + public String getUsers() { + return users; + } + + @Multiline + public void setUsers(final String users) { + this.users = users; + } + + public String getRoles() { + return roles; + } + + @Multiline + public void setRoles(final String roles) { + this.roles = roles; + } + + public String getLoginConfig() { + return loginConfig; + } + + public void setLoginConfig(final String loginConfig) { + this.loginConfig = loginConfig; + } + + public String getSecurityConstraints() { + return securityConstraints; + } + + public void setSecurityConstraints(final String securityConstraints) { + this.securityConstraints = securityConstraints; + } + + public String getRealm() { + return realm; + } + + public void setRealm(final String realm) { + this.realm = realm; + } +} Added: openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/apache/microwave/arquillian/MicrowaveContainer.java URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/apache/microwave/arquillian/MicrowaveContainer.java?rev=1765704&view=auto ============================================================================== --- openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/apache/microwave/arquillian/MicrowaveContainer.java (added) +++ openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/apache/microwave/arquillian/MicrowaveContainer.java Wed Oct 19 19:40:46 2016 @@ -0,0 +1,127 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.microwave.arquillian; + +import org.apache.commons.io.FileUtils; +import org.apache.microwave.Microwave; +import org.jboss.arquillian.container.spi.client.container.DeployableContainer; +import org.jboss.arquillian.container.spi.client.container.DeploymentException; +import org.jboss.arquillian.container.spi.client.container.LifecycleException; +import org.jboss.arquillian.container.spi.client.protocol.ProtocolDescription; +import org.jboss.arquillian.container.spi.client.protocol.metadata.HTTPContext; +import org.jboss.arquillian.container.spi.client.protocol.metadata.ProtocolMetaData; +import org.jboss.arquillian.container.spi.client.protocol.metadata.Servlet; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.exporter.ZipExporter; +import org.jboss.shrinkwrap.descriptor.api.Descriptor; + +import java.io.File; +import java.io.IOException; + +import static java.util.Optional.ofNullable; + +public class MicrowaveContainer implements DeployableContainer<MicrowaveConfiguration> { + private Microwave.Builder configuration; + private Microwave container; + + @Override + public Class<MicrowaveConfiguration> getConfigurationClass() { + return MicrowaveConfiguration.class; + } + + @Override + public void setup(final MicrowaveConfiguration configuration) { + this.configuration = configuration.toMicrowaveConfiguration(); + } + + @Override + public void start() throws LifecycleException { + this.container = new Microwave(this.configuration); + this.container.start(); + } + + @Override + public void stop() throws LifecycleException { + ofNullable(this.container).ifPresent(Microwave::close); + } + + @Override + public ProtocolDescription getDefaultProtocol() { + return new ProtocolDescription("Servlet 3.1"); + } + + @Override + public ProtocolMetaData deploy(final Archive<?> archive) throws DeploymentException { + final File dump = toArchiveDump(archive); + archive.as(ZipExporter.class).exportTo(dump, true); + final String context = sanitizeName(archive); + container.deployWebapp(context, dump); + final int port = configuration.isSkipHttp() ? configuration.getHttpsPort() : configuration.getHttpPort(); + return new ProtocolMetaData() + .addContext(new HTTPContext(configuration.getHost(), port) + .add(new Servlet("arquillian", context))); + } + + @Override + public void undeploy(final Archive<?> archive) throws DeploymentException { + this.container.undeploy(sanitizeName(archive)); + final File dump = toArchiveDump(archive); + if (dump.isFile()) { + FileUtils.deleteQuietly(dump); + } + final File unpacked = new File(dump.getParentFile(), dump.getName().replace(".war", "")); + if (unpacked.isDirectory()) { + try { + FileUtils.deleteDirectory(unpacked); + } catch (final IOException e) { + Runtime.getRuntime().addShutdownHook(new Thread() { + @Override + public void run() { + try { + FileUtils.deleteDirectory(unpacked); + } catch (final IOException e1) { + throw new IllegalStateException(e1); + } + } + }); + } + } + } + + @Override + public void deploy(final Descriptor descriptor) throws DeploymentException { + throw new UnsupportedOperationException(); + } + + @Override + public void undeploy(final Descriptor descriptor) throws DeploymentException { + throw new UnsupportedOperationException(); + } + + private String sanitizeName(final Archive<?> archive) { + final String root = archive.getName().replace(".war", "").replace("ROOT", ""); + return root.isEmpty() ? "" : ("/" + root); + } + + private File toArchiveDump(final Archive<?> archive) { + final File file = new File(this.configuration.getTempDir(), archive.getName()); + file.getParentFile().mkdirs(); + return file; + } +} Added: openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/apache/microwave/arquillian/MicrowaveExtension.java URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/apache/microwave/arquillian/MicrowaveExtension.java?rev=1765704&view=auto ============================================================================== --- openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/apache/microwave/arquillian/MicrowaveExtension.java (added) +++ openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/apache/microwave/arquillian/MicrowaveExtension.java Wed Oct 19 19:40:46 2016 @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.microwave.arquillian; + +import org.jboss.arquillian.container.spi.client.container.DeployableContainer; +import org.jboss.arquillian.core.spi.LoadableExtension; + +public class MicrowaveExtension implements LoadableExtension { + @Override + public void register(final ExtensionBuilder extensionBuilder) { + extensionBuilder.service(DeployableContainer.class, MicrowaveContainer.class); + } +} Added: openwebbeans/microwave/trunk/microwave-arquillian/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/microwave-arquillian/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension?rev=1765704&view=auto ============================================================================== --- openwebbeans/microwave/trunk/microwave-arquillian/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension (added) +++ openwebbeans/microwave/trunk/microwave-arquillian/src/main/resources/META-INF/services/org.jboss.arquillian.core.spi.LoadableExtension Wed Oct 19 19:40:46 2016 @@ -0,0 +1 @@ +org.apache.microwave.arquillian.MicrowaveExtension Added: openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/apache/microwave/arquillian/MicrowaveContainerTest.java URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/apache/microwave/arquillian/MicrowaveContainerTest.java?rev=1765704&view=auto ============================================================================== --- openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/apache/microwave/arquillian/MicrowaveContainerTest.java (added) +++ openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/apache/microwave/arquillian/MicrowaveContainerTest.java Wed Oct 19 19:40:46 2016 @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.microwave.arquillian; + +import org.apache.commons.io.IOUtils; +import org.app.Endpoint; +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.io.IOException; +import java.net.URL; + +import static org.junit.Assert.assertEquals; + +@RunWith(Arquillian.class) +public class MicrowaveContainerTest { + @Deployment(testable = false) + public static Archive<?> app() { + return ShrinkWrap.create(WebArchive.class) + .addPackage(Endpoint.class.getPackage()); + } + + @ArquillianResource + private URL base; + + @Test + public void run() throws IOException { + assertEquals("simple", IOUtils.toString(new URL(base.toExternalForm() + "api/test"))); + } +} Added: openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/app/Endpoint.java URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/app/Endpoint.java?rev=1765704&view=auto ============================================================================== --- openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/app/Endpoint.java (added) +++ openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/app/Endpoint.java Wed Oct 19 19:40:46 2016 @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.app; + +import javax.enterprise.context.ApplicationScoped; +import javax.inject.Inject; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; + +@Path("test") +@ApplicationScoped +public class Endpoint { + @Inject + private Injectable injectable; + + @GET + @Produces(MediaType.TEXT_PLAIN) + public String simple() { + return Boolean.parseBoolean(injectable.injected()) ? "simple" : "fail"; + } +} Added: openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/app/Injectable.java URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/app/Injectable.java?rev=1765704&view=auto ============================================================================== --- openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/app/Injectable.java (added) +++ openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/app/Injectable.java Wed Oct 19 19:40:46 2016 @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.app; + +import javax.enterprise.context.ApplicationScoped; + +@ApplicationScoped +public class Injectable { + public String injected() { + return "true"; + } +} Added: openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/app/RsApp.java URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/app/RsApp.java?rev=1765704&view=auto ============================================================================== --- openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/app/RsApp.java (added) +++ openwebbeans/microwave/trunk/microwave-arquillian/src/test/java/org/app/RsApp.java Wed Oct 19 19:40:46 2016 @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.app; + +import javax.enterprise.context.Dependent; +import javax.ws.rs.ApplicationPath; +import javax.ws.rs.core.Application; + +@Dependent +@ApplicationPath("api") +public class RsApp extends Application { +} Modified: openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/Microwave.java URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/Microwave.java?rev=1765704&r1=1765703&r2=1765704&view=diff ============================================================================== --- openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/Microwave.java (original) +++ openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/Microwave.java Wed Oct 19 19:40:46 2016 @@ -34,6 +34,7 @@ import org.apache.catalina.core.Standard import org.apache.catalina.session.ManagerBase; import org.apache.catalina.session.StandardManager; import org.apache.catalina.startup.Catalina; +import org.apache.catalina.startup.ContextConfig; import org.apache.catalina.startup.Tomcat; import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.text.StrLookup; @@ -84,7 +85,6 @@ import static java.util.Optional.ofNulla public class Microwave implements AutoCloseable { private final Builder configuration; protected File base; - protected InternalTomcat tomcat; // we can undeploy webapps with that later @@ -107,6 +107,11 @@ public class Microwave implements AutoCl return tomcat; } + public void undeploy(final String root) { + final Context context = this.contexts.remove(root); + tomcat.getHost().removeChild(context); + } + public Microwave deployClasspath() { return deployClasspath(""); } @@ -139,6 +144,7 @@ public class Microwave implements AutoCl ctx.setDocBase(warOrDir.getAbsolutePath()); } ctx.addLifecycleListener(new Tomcat.FixContextListener()); + ctx.addLifecycleListener(new ContextConfig()); ctx.addLifecycleListener(event -> { switch (event.getType()) { case Lifecycle.AFTER_START_EVENT: @@ -312,6 +318,7 @@ public class Microwave implements AutoCl final StandardHost host = new StandardHost(); host.setName(configuration.host); host.setAppBase(webapps.getAbsolutePath()); + host.setUnpackWARs(true); // forced for now cause OWB doesn't support war:file:// urls try { host.setWorkDir(new File(base, "work").getCanonicalPath()); } catch (final IOException e) { Modified: openwebbeans/microwave/trunk/pom.xml URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/pom.xml?rev=1765704&r1=1765703&r2=1765704&view=diff ============================================================================== --- openwebbeans/microwave/trunk/pom.xml (original) +++ openwebbeans/microwave/trunk/pom.xml Wed Oct 19 19:40:46 2016 @@ -46,6 +46,7 @@ <module>microwave-maven-plugin</module> <module>microwave-gradle-plugin</module> <module>microwave-junit</module> + <module>microwave-arquillian</module> </modules> <build>