diff --git a/coverage-report/src/test/java/org/jooby/ws/OnByteArrayMessageFeature.java b/coverage-report/src/test/java/org/jooby/ws/OnByteArrayMessageFeature.java index 223c5d2420..91930840c3 100644 --- a/coverage-report/src/test/java/org/jooby/ws/OnByteArrayMessageFeature.java +++ b/coverage-report/src/test/java/org/jooby/ws/OnByteArrayMessageFeature.java @@ -6,6 +6,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import org.jooby.MediaType; import org.jooby.test.ServerFeature; import org.junit.After; import org.junit.Before; @@ -29,7 +30,7 @@ public class OnByteArrayMessageFeature extends ServerFeature { ws.close(); }); }); - }); + }).produces(MediaType.octetstream); } diff --git a/coverage-report/src/test/java/org/jooby/ws/OnByteBufferMessageFeature.java b/coverage-report/src/test/java/org/jooby/ws/OnByteBufferMessageFeature.java index 18d356b3fa..7cf87abf43 100644 --- a/coverage-report/src/test/java/org/jooby/ws/OnByteBufferMessageFeature.java +++ b/coverage-report/src/test/java/org/jooby/ws/OnByteBufferMessageFeature.java @@ -7,6 +7,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; +import org.jooby.MediaType; import org.jooby.test.ServerFeature; import org.junit.After; import org.junit.Before; @@ -30,8 +31,7 @@ public class OnByteBufferMessageFeature extends ServerFeature { ws.close(); }); }); - - }); + }).produces(MediaType.octetstream); } diff --git a/jooby-banner/src/test/java/org/jooby/banner/BannerTest.java b/jooby-banner/src/test/java/org/jooby/banner/BannerTest.java index e49efd9a74..7b4e77dddc 100644 --- a/jooby-banner/src/test/java/org/jooby/banner/BannerTest.java +++ b/jooby-banner/src/test/java/org/jooby/banner/BannerTest.java @@ -1,6 +1,9 @@ package org.jooby.banner; import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.isA; + +import javax.inject.Provider; import org.jooby.Env; import org.jooby.test.MockUnit; @@ -14,6 +17,9 @@ import com.github.lalyos.jfiglet.FigletFont; import com.google.inject.Binder; +import com.google.inject.Key; +import com.google.inject.binder.LinkedBindingBuilder; +import com.google.inject.name.Names; import com.typesafe.config.Config; import javaslang.control.Try.CheckedRunnable; @@ -34,6 +40,7 @@ public void configure() throws Exception { new MockUnit(Env.class, Config.class, Binder.class, Logger.class) .expect(conf("app", "1.0.0")) .expect(log("app")) + .expect(banner()) .expect(onStart) .run(unit -> { new Banner(banner) @@ -50,6 +57,7 @@ public void print() throws Exception { .expect(onStart) .expect(convertOnLine(banner, "speed")) .expect(print(banner, "1.0.0")) + .expect(banner()) .run(unit -> { new Banner(banner) .configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class)); @@ -67,6 +75,7 @@ public void font() throws Exception { .expect(onStart) .expect(convertOnLine(banner, "myfont")) .expect(print(banner, "1.0.0")) + .expect(banner()) .run(unit -> { new Banner(banner) .font("myfont") @@ -85,6 +94,7 @@ public void defprint() throws Exception { .expect(onStart) .expect(convertOnLine(banner, "speed")) .expect(print(banner, "1.0.0")) + .expect(banner()) .run(unit -> { new Banner() .configure(unit.get(Env.class), unit.get(Config.class), unit.get(Binder.class)); @@ -121,4 +131,16 @@ private Block conf(final String name, final String v) { expect(conf.getString("application.version")).andReturn(v); }; } + + @SuppressWarnings("unchecked") + private Block banner() { + return unit -> { + + LinkedBindingBuilder lbb = unit.mock(LinkedBindingBuilder.class); + expect(lbb.toProvider(isA(Provider.class))).andReturn(lbb); + + Binder binder = unit.get(Binder.class); + expect(binder.bind(Key.get(String.class, Names.named("application.banner")))).andReturn(lbb); + }; + } } diff --git a/jooby/src/main/java/org/jooby/Route.java b/jooby/src/main/java/org/jooby/Route.java index ba9f51b385..db8092aa4d 100644 --- a/jooby/src/main/java/org/jooby/Route.java +++ b/jooby/src/main/java/org/jooby/Route.java @@ -1008,7 +1008,8 @@ public Collection map(final Mapper mapper) { class Definition implements Props { private static final SourceProvider SRC = SourceProvider.DEFAULT_INSTANCE - .plusSkippedClasses(Definition.class, Jooby.class, Collection.class, Group.class); + .plusSkippedClasses(Definition.class, Jooby.class, Collection.class, Group.class, + javaslang.collection.List.class, Routes.class); /** * Route's name. @@ -1173,6 +1174,15 @@ public boolean glob() { return cpattern.glob(); } + /** + * Source information (where the route was defined). + * + * @return Source information (where the route was defined). + */ + public Route.Source source() { + return new RouteSourceImpl(declaringClass, line); + } + /** * Recreate a route path and apply the given variables. * @@ -2229,7 +2239,9 @@ static String normalize(final String path) { } /** - * @return Source information. + * Source information (where the route was defined). + * + * @return Source information (where the route was defined). */ Route.Source source(); diff --git a/jooby/src/main/java/org/jooby/WebSocket.java b/jooby/src/main/java/org/jooby/WebSocket.java index 628972bb35..e2b7711da2 100644 --- a/jooby/src/main/java/org/jooby/WebSocket.java +++ b/jooby/src/main/java/org/jooby/WebSocket.java @@ -279,13 +279,13 @@ class Definition { * Defines the media types that the methods of a resource class or can consumes. Default is: * {@literal *}/{@literal *}. */ - private MediaType consumes = MediaType.all; + private MediaType consumes = MediaType.plain; /** * Defines the media types that the methods of a resource class or can produces. Default is: * {@literal *}/{@literal *}. */ - private MediaType produces = MediaType.all; + private MediaType produces = MediaType.plain; /** A path pattern. */ private String pattern; diff --git a/jooby/src/main/java/org/jooby/internal/WebSocketImpl.java b/jooby/src/main/java/org/jooby/internal/WebSocketImpl.java index 3b90209314..e3a5474df4 100644 --- a/jooby/src/main/java/org/jooby/internal/WebSocketImpl.java +++ b/jooby/src/main/java/org/jooby/internal/WebSocketImpl.java @@ -151,7 +151,7 @@ public void connect(final Injector injector, final Request req, final NativeWebS ws.onTextMessage(message -> Try .run(() -> messageCallback.invoke( - new MutantImpl(injector.getInstance(ParserExecutor.class), + new MutantImpl(injector.getInstance(ParserExecutor.class), consumes, new StrParamReferenceImpl("body", "message", ImmutableList.of(message))))) .onFailure(this::handleErr)); diff --git a/jooby/src/test/java/org/jooby/RouteDefinitionTest.java b/jooby/src/test/java/org/jooby/RouteDefinitionTest.java index 7a9a08c904..72dc0eaf9e 100644 --- a/jooby/src/test/java/org/jooby/RouteDefinitionTest.java +++ b/jooby/src/test/java/org/jooby/RouteDefinitionTest.java @@ -316,6 +316,14 @@ public void attrs() throws Exception { assertEquals(Route.class, r.attr("type")); } + @Test + public void src() throws Exception { + Function route = path -> new Route.Definition("*", path, () -> null); + Route.Definition r = route.apply("/"); + + assertEquals("org.jooby.RouteDefinitionTest:321", r.source().toString()); + } + @Test public void glob() throws Exception { Function route = path -> new Route.Definition("*", path, () -> null); diff --git a/jooby/src/test/java/org/jooby/WebSocketDefinitionTest.java b/jooby/src/test/java/org/jooby/WebSocketDefinitionTest.java index dbf58c22a3..d04f2d7c5f 100644 --- a/jooby/src/test/java/org/jooby/WebSocketDefinitionTest.java +++ b/jooby/src/test/java/org/jooby/WebSocketDefinitionTest.java @@ -13,8 +13,8 @@ public void toStr() { }); assertEquals("WS /pattern\n" + - " consume: */*\n" + - " produces: */*\n", def.toString()); + " consume: text/plain\n" + + " produces: text/plain\n", def.toString()); } @Test diff --git a/jooby/src/test/java/org/jooby/internal/AppPrinterTest.java b/jooby/src/test/java/org/jooby/internal/AppPrinterTest.java index 3eb40f26c1..8308535d15 100644 --- a/jooby/src/test/java/org/jooby/internal/AppPrinterTest.java +++ b/jooby/src/test/java/org/jooby/internal/AppPrinterTest.java @@ -32,7 +32,7 @@ public void print() { " GET {complete}/ [*/*] [*/*] (/anonymous)\n" + " GET / [*/*] [*/*] (/anonymous)\n" + " GET /home [*/*] [*/*] (/anonymous)\n" + - " WS /ws [*/*] [*/*]\n" + + " WS /ws [text/plain] [text/plain]\n" + "\n" + "listening on:\n" + " http://localhost:8080/", setup); @@ -58,11 +58,11 @@ public void printHttps() { .toString(); assertEquals(" GET / [*/*] [*/*] (/anonymous)\n" + " GET /home [*/*] [*/*] (/anonymous)\n" + - " WS /ws [*/*] [*/*]\n" + + " WS /ws [text/plain] [text/plain]\n" + "\n" + - "listening on:" + - "\n http://localhost:8080/" + - "\n https://localhost:8443/", setup); + "listening on:\n" + + " http://localhost:8080/\n" + + " https://localhost:8443/", setup); } @Test @@ -76,11 +76,11 @@ public void printHttp2() { .toString(); assertEquals(" GET / [*/*] [*/*] (/anonymous)\n" + " GET /home [*/*] [*/*] (/anonymous)\n" + - " WS /ws [*/*] [*/*]\n" + + " WS /ws [text/plain] [text/plain]\n" + "\n" + - "listening on:" + - "\n http://localhost:8080/ +h2" + - "\n https://localhost:8443/ +h2", setup); + "listening on:\n" + + " http://localhost:8080/ +h2\n" + + " https://localhost:8443/ +h2", setup); } @Test @@ -95,11 +95,11 @@ public void printHttp2Https() { .toString(); assertEquals(" GET / [*/*] [*/*] (/anonymous)\n" + " GET /home [*/*] [*/*] (/anonymous)\n" + - " WS /ws [*/*] [*/*]\n" + + " WS /ws [text/plain] [text/plain]\n" + "\n" + - "listening on:" + - "\n http://localhost:8080/" + - "\n https://localhost:8443/ +h2", setup); + "listening on:\n" + + " http://localhost:8080/\n" + + " https://localhost:8443/ +h2", setup); } @Test @@ -113,10 +113,10 @@ public void printHttp2ClearText() { .toString(); assertEquals(" GET / [*/*] [*/*] (/anonymous)\n" + " GET /home [*/*] [*/*] (/anonymous)\n" + - " WS /ws [*/*] [*/*]\n" + + " WS /ws [text/plain] [text/plain]\n" + "\n" + - "listening on:" + - "\n http://localhost:8080/ +h2", setup); + "listening on:\n" + + " http://localhost:8080/ +h2", setup); } private Config config(final String path) { @@ -136,7 +136,7 @@ public void printWithPath() { .toString(); assertEquals(" GET / [*/*] [*/*] (/anonymous)\n" + " GET /home [*/*] [*/*] (/anonymous)\n" + - " WS /ws [*/*] [*/*]\n" + + " WS /ws [text/plain] [text/plain]\n" + "\n" + "listening on:\n" + " http://localhost:8080/app", setup);