Skip to content

Commit 46c72ca

Browse files
committed
Route inheritance from base controller no longer works when multiple subclasses extend it (Jooby 4.x vs 1.x)
- ref #3786
1 parent 9fd6e31 commit 46c72ca

File tree

4 files changed

+133
-0
lines changed

4 files changed

+133
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 tests.i3786;
7+
8+
import io.jooby.Context;
9+
import io.jooby.annotation.GET;
10+
import io.jooby.annotation.Path;
11+
import io.jooby.annotation.QueryParam;
12+
13+
@Path("/base")
14+
public abstract class Base3786 {
15+
16+
@GET
17+
public String base() {
18+
return "base";
19+
}
20+
21+
@GET("/withPath")
22+
public String withPath(@QueryParam String q) {
23+
return "withPath";
24+
}
25+
26+
@GET("/{id}")
27+
public String getOne(Context ctx) {
28+
return "base: " + ctx.path("id").value();
29+
}
30+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 tests.i3786;
7+
8+
import io.jooby.Context;
9+
import io.jooby.annotation.GET;
10+
import io.jooby.annotation.POST;
11+
import io.jooby.annotation.Path;
12+
13+
@Path("/inherited")
14+
public class C3786 extends Base3786 {
15+
@GET("/childOnly")
16+
public String childOnly(Context ctx) {
17+
return ctx.getMethod() + ctx.getRequestPath();
18+
}
19+
20+
@POST("/childOnly")
21+
public String childOnlyPost(Context ctx) {
22+
return ctx.getMethod() + ctx.getRequestPath();
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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 tests.i3786;
7+
8+
import io.jooby.Context;
9+
import io.jooby.annotation.GET;
10+
import io.jooby.annotation.POST;
11+
import io.jooby.annotation.Path;
12+
13+
@Path("/overrideMethod")
14+
public class D3786 extends Base3786 {
15+
@GET("/childOnly")
16+
public String childOnly(Context ctx) {
17+
return ctx.getRequestPath();
18+
}
19+
20+
@POST("/user")
21+
public String newPath(Context q) {
22+
return "/overrideMethod/user";
23+
}
24+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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 tests.i3786;
7+
8+
import static org.junit.jupiter.api.Assertions.*;
9+
10+
import org.junit.jupiter.api.Test;
11+
12+
import io.jooby.apt.ProcessorRunner;
13+
import io.jooby.test.MockContext;
14+
import io.jooby.test.MockRouter;
15+
16+
public class Issue3786 {
17+
@Test
18+
public void shouldCheckBase() throws Exception {
19+
new ProcessorRunner(new C3786())
20+
.withRouter(
21+
app -> {
22+
var router = new MockRouter(app);
23+
assertEquals("base", router.get("/inherited", new MockContext()).value());
24+
assertEquals(
25+
"withPath", router.get("/inherited/withPath", new MockContext()).value());
26+
assertEquals("base: 123", router.get("/inherited/123", new MockContext()).value());
27+
assertEquals(
28+
"GET/inherited/childOnly",
29+
router.get("/inherited/childOnly", new MockContext()).value());
30+
assertEquals(
31+
"POST/inherited/childOnly",
32+
router.post("/inherited/childOnly", new MockContext()).value());
33+
});
34+
}
35+
36+
@Test
37+
public void shouldCheckOverride() throws Exception {
38+
new ProcessorRunner(new D3786())
39+
.withRouter(
40+
app -> {
41+
var router = new MockRouter(app);
42+
assertEquals("base", router.get("/overrideMethod", new MockContext()).value());
43+
assertEquals(
44+
"withPath", router.get("/overrideMethod/withPath", new MockContext()).value());
45+
assertEquals(
46+
"base: 123", router.get("/overrideMethod/123", new MockContext()).value());
47+
assertEquals(
48+
"/overrideMethod/childOnly",
49+
router.get("/overrideMethod/childOnly", new MockContext()).value());
50+
assertEquals(
51+
"/overrideMethod/user",
52+
router.post("/overrideMethod/user", new MockContext()).value());
53+
});
54+
}
55+
}

0 commit comments

Comments
 (0)