Skip to content

Commit 99ac09c

Browse files
committed
Bug: review onStarting vs onStarted callback usage from existing modules
- fix #3551 - ref #3550
1 parent 867f89d commit 99ac09c

File tree

7 files changed

+110
-4
lines changed

7 files changed

+110
-4
lines changed

modules/jooby-jackson/src/main/java/io/jooby/jackson/JacksonModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ public void install(@NonNull Jooby application) {
143143
// Parsing exception as 400
144144
application.errorCode(JsonParseException.class, StatusCode.BAD_REQUEST);
145145

146-
application.onStarted(
146+
application.onStarting(
147147
() -> {
148148
for (Class<? extends Module> type : modules) {
149149
Module module = application.require(type);

modules/jooby-metrics/src/main/java/io/jooby/metrics/MetricsModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public void install(@NonNull Jooby application) {
241241

242242
final Set<Reporter> reporters = new HashSet<>();
243243

244-
application.onStarted(
244+
application.onStarting(
245245
() -> {
246246
metricClasses.forEach(
247247
(name, clazz) -> metricRegistry.register(name, application.require(clazz)));

modules/jooby-pac4j/src/main/java/io/jooby/pac4j/Pac4jModule.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ public void install(@NonNull Jooby application) throws Exception {
447447
allClients.values().stream().flatMap(List::stream).filter(r -> !r.isResolved()).toList();
448448

449449
if (!unresolved.isEmpty()) {
450-
application.onStarted(
450+
application.onStarting(
451451
() -> {
452452
List<Client> clientList = new ArrayList<>(clients.getClients());
453453
unresolved.stream()
@@ -567,7 +567,7 @@ public void install(@NonNull Jooby application) throws Exception {
567567
/** Compute default url as next available route. We only select static path patterns. */
568568
if (options.getDefaultUrl() == null) {
569569
int index = application.getRoutes().size();
570-
application.onStarted(
570+
application.onStarting(
571571
() -> {
572572
List<Route> routes = application.getRoutes();
573573
String defaultUrl = application.getContextPath();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Jooby https://jooby.io
3+
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
4+
* Copyright 2014 Edgar Espina
5+
*/
6+
package io.jooby.i3551;
7+
8+
import com.fasterxml.jackson.databind.module.SimpleModule;
9+
import io.jooby.Environment;
10+
import jakarta.inject.Inject;
11+
12+
public class GuiceService3551 extends SimpleModule {
13+
private Environment env;
14+
15+
@Inject
16+
public GuiceService3551(Environment env) {
17+
this.env = env;
18+
}
19+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Jooby https://jooby.io
3+
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
4+
* Copyright 2014 Edgar Espina
5+
*/
6+
package io.jooby.i3551;
7+
8+
import static org.junit.jupiter.api.Assertions.*;
9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
11+
import io.jooby.ServiceKey;
12+
import io.jooby.StatusCode;
13+
import io.jooby.guice.GuiceModule;
14+
import io.jooby.jackson.JacksonModule;
15+
import io.jooby.junit.ServerTest;
16+
import io.jooby.junit.ServerTestRunner;
17+
18+
public class Issue3551 {
19+
@ServerTest
20+
public void shouldEnsureDIOnStartCallbacks(ServerTestRunner runner) {
21+
runner
22+
.define(
23+
app -> {
24+
app.getServices()
25+
.put(
26+
ServiceKey.key(Service3551.class, "service"),
27+
new Service3551(app.getEnvironment()));
28+
app.install(new JacksonModule().module(JacksonModule3551.class));
29+
30+
app.install(new GuiceModule());
31+
32+
app.onStarting(
33+
() -> {
34+
// Ask jooby registry
35+
assertNotNull(app.require(ServiceKey.key(Service3551.class, "service")));
36+
// Ask Guice
37+
assertNotNull(app.require(GuiceService3551.class));
38+
assertNotNull(app.require(JacksonModule3551.class));
39+
});
40+
app.get("/3551", ctx -> StatusCode.OK);
41+
})
42+
.ready(
43+
http -> {
44+
http.get(
45+
"/3551",
46+
rsp -> {
47+
assertEquals(StatusCode.OK.value(), rsp.code());
48+
});
49+
});
50+
}
51+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Jooby https://jooby.io
3+
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
4+
* Copyright 2014 Edgar Espina
5+
*/
6+
package io.jooby.i3551;
7+
8+
import com.fasterxml.jackson.databind.module.SimpleModule;
9+
import io.jooby.Environment;
10+
import jakarta.inject.Inject;
11+
12+
public class JacksonModule3551 extends SimpleModule {
13+
private Environment env;
14+
15+
@Inject
16+
public JacksonModule3551(Environment env) {
17+
this.env = env;
18+
}
19+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/*
2+
* Jooby https://jooby.io
3+
* Apache License Version 2.0 https://jooby.io/LICENSE.txt
4+
* Copyright 2014 Edgar Espina
5+
*/
6+
package io.jooby.i3551;
7+
8+
import com.fasterxml.jackson.databind.module.SimpleModule;
9+
import io.jooby.Environment;
10+
11+
public class Service3551 extends SimpleModule {
12+
private Environment env;
13+
14+
public Service3551(Environment env) {
15+
this.env = env;
16+
}
17+
}

0 commit comments

Comments
 (0)