-
-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3426 from kliushnichenko/fix/avaje-module
Fix avaje module
- Loading branch information
Showing
5 changed files
with
136 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
modules/jooby-avaje-inject/src/test/java/io/jooby/avaje/inject/AvajeInjectModuleTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()); | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
modules/jooby-avaje-inject/src/test/java/io/jooby/avaje/inject/app/Controller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
modules/jooby-avaje-inject/src/test/java/io/jooby/avaje/inject/app/TestApp.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); | ||
} | ||
} |