Enable creating an API using Spring Web #5
@ -55,6 +55,11 @@
|
||||
<artifactId>wicket-tester</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.wicket</groupId>
|
||||
<artifactId>wicket-spring</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.wicketstuff</groupId>
|
||||
<artifactId>wicketstuff-jasperreports</artifactId>
|
||||
|
@ -12,6 +12,8 @@ import org.apache.wicket.Session;
|
||||
import org.apache.wicket.guice.GuiceComponentInjector;
|
||||
import org.apache.wicket.request.Request;
|
||||
import org.apache.wicket.request.Response;
|
||||
import org.apache.wicket.spring.injection.annot.SpringComponentInjector;
|
||||
import org.apache.wicket.spring.test.ApplicationContextMock;
|
||||
import org.apache.wicket.util.tester.WicketTester;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@ -361,9 +363,12 @@ public abstract class SciProTest {
|
||||
@BeforeEach
|
||||
public void setUpApplication() {
|
||||
final Class<? extends SciProTest> clazz = getClass();
|
||||
final Injector injector = Guice.createInjector(new MockModule(clazz));
|
||||
ApplicationContextMock applicationContext = new MockModule(clazz);
|
||||
|
||||
SciProApplication application = new SciProApplication(injector.getInstance(CurrentProfile.class)) {
|
||||
CurrentProfile currentProfile = new CurrentProfile();
|
||||
currentProfile.setCurrentProfileString("TEST");
|
||||
|
||||
SciProApplication application = new SciProApplication(currentProfile) {
|
||||
|
||||
@Override
|
||||
public Session newSession(Request request, Response response) {
|
||||
@ -371,7 +376,7 @@ public abstract class SciProTest {
|
||||
}
|
||||
};
|
||||
application.getComponentInstantiationListeners().add(
|
||||
new GuiceComponentInjector(application, injector));
|
||||
new SpringComponentInjector(application, applicationContext));
|
||||
tester = new WicketTester(application, System.getProperty("user.dir") + "/src/main/webapp");
|
||||
|
||||
setLoggedIn(true);
|
||||
@ -464,27 +469,23 @@ public abstract class SciProTest {
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private class MockModule extends AbstractModule {
|
||||
private class MockModule extends ApplicationContextMock {
|
||||
private final Class<? extends SciProTest> clazz;
|
||||
|
||||
public MockModule(Class<? extends SciProTest> clazz) {
|
||||
this.clazz = clazz;
|
||||
configure();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void configure() {
|
||||
Multibinder.newSetBinder(binder(), Lifecycle.class);
|
||||
Multibinder.newSetBinder(binder(), UserImportService.class)
|
||||
.addBinding().toInstance(userImportService);
|
||||
bindConstant().annotatedWith(Names.named("profile")).to("TEST");
|
||||
bind(Clock.class).toInstance(Clock.systemDefaultZone());
|
||||
private void configure() {
|
||||
putBean(Clock.systemDefaultZone());
|
||||
for (Class<?> c = clazz; c != null; c = c.getSuperclass()) {
|
||||
for (Field f : c.getDeclaredFields()) {
|
||||
if (f.getAnnotation(Mock.class) != null && f.trySetAccessible()) {
|
||||
try {
|
||||
Class<Object> type = (Class<Object>) f.getType();
|
||||
bind(type).toInstance(f.get(SciProTest.this));
|
||||
putBean(f.getName(), f.get(SciProTest.this));
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user