Skip to content

Commit

Permalink
Merge pull request #3426 from kliushnichenko/fix/avaje-module
Browse files Browse the repository at this point in the history
Fix avaje module
  • Loading branch information
jknack committed May 19, 2024
2 parents ce92b0b + ebc79c3 commit 85647ea
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 6 deletions.
52 changes: 50 additions & 2 deletions modules/jooby-avaje-inject/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,26 @@
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<groupId>io.jooby</groupId>
<artifactId>jooby-netty</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.jooby</groupId>
<artifactId>jooby-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.jooby</groupId>
<artifactId>jooby-jackson</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<scope>test</scope>
</dependency>

Expand All @@ -51,4 +69,34 @@
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<executions>
<execution>
<id>test</id>
<phase>test-compile</phase>
</execution>
</executions>
<configuration>
<compilerArgs>
<arg>-parameters</arg>
</compilerArgs>
<annotationProcessorPaths>
<path>
<groupId>io.jooby</groupId>
<artifactId>jooby-apt</artifactId>
</path>
<path>
<groupId>io.avaje</groupId>
<artifactId>avaje-inject-generator</artifactId>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import java.util.List;
import java.util.stream.Collectors;

import com.typesafe.config.Config;

import io.avaje.inject.BeanScope;
import io.avaje.inject.BeanScopeBuilder;
import io.jooby.Extension;
Expand Down Expand Up @@ -68,7 +66,7 @@ public void install(Jooby application) throws Exception {
e -> {
final var key = e.getKey();
if (key.getName() == null) {
beanScope.provideDefault(key.getType(), e::getValue);
beanScope.provideDefault(key.getType(), e.getValue()::get);
} else {
beanScope.bean(key.getName(), key.getType(), e.getValue());
}
Expand All @@ -80,7 +78,6 @@ public void install(Jooby application) throws Exception {
// configuration properties
final var config = environment.getConfig();
beanScope.propertyPlugin(new JoobyPropertyPlugin(config));
beanScope.bean(Config.class, config);

for (var entry : config.entrySet()) {
String name = entry.getKey();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.jooby.avaje.inject;

import io.jooby.avaje.inject.app.TestApp;
import io.jooby.test.JoobyTest;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class AvajeInjectModuleTest {

static OkHttpClient client = new OkHttpClient();

@JoobyTest(TestApp.class)
public void shouldPropagateJoobyServicesToAvajeBeanScope(String serverPath) throws IOException {
Request request = new Request.Builder().url(serverPath + "ping").build();

try (Response response = client.newCall(request).execute()) {
assertEquals("test", response.body().string());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package io.jooby.avaje.inject.app;

import com.fasterxml.jackson.databind.json.JsonMapper;
import com.typesafe.config.Config;
import io.avaje.inject.InjectModule;
import io.jooby.annotation.GET;
import io.jooby.annotation.Path;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.inject.Singleton;

@Singleton
@Path("")
@InjectModule(requires = {JsonMapper.class, Config.class, String.class})
public class Controller {

private final JsonMapper jsonMapper;
private final Config config;
private final String env;

@Inject
public Controller(JsonMapper jsonMapper, Config config, @Named("application.env") String env) {
this.jsonMapper = jsonMapper;
this.config = config;
this.env = env;
}

@GET
@Path("/ping")
public String ping() {
jsonMapper.version();
config.isEmpty();

return this.env;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.jooby.avaje.inject.app;

import com.fasterxml.jackson.databind.json.JsonMapper;
import com.typesafe.config.Config;
import io.jooby.Jooby;
import io.jooby.avaje.inject.AvajeInjectModule;
import io.jooby.jackson.JacksonModule;

public class TestApp extends Jooby {

{
install(new JacksonModule());
install(AvajeInjectModule.of());

mvc(Controller.class);

onStarted(() -> {
JsonMapper jsonMapper = require(JsonMapper.class);
Config config = require(Config.class);
jsonMapper.version();
config.isEmpty();
});
}
}

0 comments on commit 85647ea

Please sign in to comment.