Skip to content

Commit

Permalink
Add runtime config info, fix arquillian injection
Browse files Browse the repository at this point in the history
  • Loading branch information
adrienlauer committed Nov 27, 2017
1 parent aed298b commit 841a2cc
Show file tree
Hide file tree
Showing 12 changed files with 153 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
package org.seedstack.seed.spi;

public class ConfigurationPriority {
/**
* Runtime information has the highest priority to avoid any override.
*/
public static final int RUNTIME_INFO = Integer.MAX_VALUE;

/**
* Environment variables have the highest priority to avoid any override.
*/
Expand Down
6 changes: 6 additions & 0 deletions testing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
<version>${arquillian.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${javax.servlet.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.seedstack.poms</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.Collection;
import java.util.Set;
import org.seedstack.seed.core.internal.BindingDefinition;
import org.seedstack.seed.it.internal.arquillian.InjectionEnricher;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -34,8 +33,6 @@ class ITModule extends AbstractModule {

@Override
protected void configure() {
requestStaticInjection(InjectionEnricher.class);

if (testClass != null) {
bind(testClass);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,19 @@
import org.slf4j.LoggerFactory;

/**
* Arquillian TestEnricher to enable SEED injection on tests.
* Arquillian TestEnricher to enable SeedStack injection on tests.
*/
public class InjectionEnricher implements TestEnricher {
public class InjectionTestEnricher implements TestEnricher {
private static final Logger LOGGER = LoggerFactory.getLogger(InjectionTestEnricher.class);
@Inject
private static Injector injector;

private Logger logger = LoggerFactory.getLogger(InjectionEnricher.class);

@Override
public void enrich(Object testCase) {
if (injector != null) {
injector.injectMembers(testCase);
} else {
logger.warn("Seed injector is not available, cannot inject Arquillian test {}",
LOGGER.warn("SeedStack injector is not available, cannot inject client-side Arquillian test {}",
testCase.getClass().getCanonicalName());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

package org.seedstack.seed.it.internal.arquillian;

import org.jboss.arquillian.container.test.spi.RemoteLoadableExtension;
import io.nuun.kernel.api.Plugin;
import org.jboss.arquillian.container.test.spi.client.deployment.AuxiliaryArchiveAppender;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
Expand All @@ -21,8 +21,7 @@ public class SeedArchiveAppender implements AuxiliaryArchiveAppender {
@Override
public Archive<?> createAuxiliaryArchive() {
return ShrinkWrap.create(JavaArchive.class, "seed-arquillian-support.jar")
.addClass(InjectionEnricher.class)
.addClass(SeedRemoteExtension.class)
.addAsServiceProvider(RemoteLoadableExtension.class, SeedRemoteExtension.class);
.addPackages(false, "org.seedstack.seed.it.internal.arquillian.remote")
.addAsServiceProvider(Plugin.class, WebITPlugin.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
public class SeedClientExtension implements LoadableExtension {
@Override
public void register(final ExtensionBuilder builder) {
// append the SEED arquillian support to the deployed app
// append arquillian support to the deployed app
builder.service(AuxiliaryArchiveAppender.class, SeedArchiveAppender.class);

// registers the enricher for embedded containers
builder.service(TestEnricher.class, InjectionEnricher.class);
// register the injection enricher
builder.service(TestEnricher.class, InjectionTestEnricher.class);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Copyright © 2013-2017, The SeedStack authors <http://seedstack.org>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.seedstack.seed.it.internal.arquillian;

import com.google.inject.AbstractModule;

class WebITModule extends AbstractModule {
@Override
protected void configure() {
requestStaticInjection(InjectionTestEnricher.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright © 2013-2017, The SeedStack authors <http://seedstack.org>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.seedstack.seed.it.internal.arquillian;

import org.seedstack.seed.core.internal.AbstractSeedPlugin;

public class WebITPlugin extends AbstractSeedPlugin {
@Override
public String name() {
return "web-testing";
}

@Override
public Object nativeUnitModule() {
return new WebITModule();
}
}
52 changes: 52 additions & 0 deletions web/core/src/it/java/org/seedstack/seed/web/WebIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright © 2013-2017, The SeedStack authors <http://seedstack.org>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

package org.seedstack.seed.web;

import static org.assertj.core.api.Assertions.assertThat;

import java.net.URL;
import javax.inject.Inject;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Ignore;
import org.junit.Test;
import org.seedstack.seed.Configuration;
import org.seedstack.seed.diagnostic.DiagnosticManager;
import org.seedstack.seed.it.AbstractSeedWebIT;

public class WebIT extends AbstractSeedWebIT {
@Inject
private DiagnosticManager diagnosticManager;
@Configuration("web.runtime.servlet.contextPath")
private String contextPath;
@ArquillianResource
private URL baseUrl;

@Deployment
public static WebArchive createDeployment() {
return ShrinkWrap.create(WebArchive.class);
}

@Test
@Ignore("remote injection not working, please fix if possible")
public void testIsInjected() throws Exception {
assertThat(diagnosticManager).isNotNull();
assertThat(diagnosticManager).isNotNull();
}

@Test
@RunAsClient
public void testAsClientIsInjected() throws Exception {
assertThat(diagnosticManager).isNotNull();
assertThat(baseUrl.toString()).endsWith(contextPath + "/");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.seedstack.seed.SeedException;
import org.seedstack.seed.core.SeedRuntime;
import org.seedstack.seed.core.internal.AbstractSeedPlugin;
import org.seedstack.seed.spi.ConfigurationPriority;
import org.seedstack.seed.web.spi.FilterDefinition;
import org.seedstack.seed.web.spi.ListenerDefinition;
import org.seedstack.seed.web.spi.SeedFilterPriority;
Expand Down Expand Up @@ -56,6 +57,12 @@ public String name() {
@Override
protected void setup(SeedRuntime seedRuntime) {
servletContext = seedRuntime.contextAs(ServletContext.class);
if (servletContext != null) {
seedRuntime.registerConfigurationProvider(
new WebRuntimeConfigurationProvider(servletContext),
ConfigurationPriority.RUNTIME_INFO
);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright © 2013-2017, The SeedStack authors <http://seedstack.org>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.seedstack.seed.web.internal;

import javax.servlet.ServletContext;
import org.seedstack.coffig.node.MapNode;
import org.seedstack.coffig.node.NamedNode;
import org.seedstack.coffig.spi.ConfigurationProvider;

class WebRuntimeConfigurationProvider implements ConfigurationProvider {
private final ServletContext servletContext;

WebRuntimeConfigurationProvider(ServletContext servletContext) {
this.servletContext = servletContext;
}

@Override
public MapNode provide() {
return new MapNode(new NamedNode("web", new MapNode(
new NamedNode("runtime", new MapNode(
new NamedNode("servlet", new MapNode(
new NamedNode("contextPath", servletContext.getContextPath()),
new NamedNode("serverInfo", servletContext.getServerInfo()),
new NamedNode("virtualServerName", servletContext.getVirtualServerName())
))
))
)));
}
}

0 comments on commit 841a2cc

Please sign in to comment.