Hi William, it looks like you pass wrong ActorRef when you are instantiating WebAPI class. You should probably pass in probe.getRef().
Just to make sure that your setup works as expected I have put it to a runnable example here <https://github.com/2m/akka-stream-sandbox-java/blob/c56d895a2bc98476c22295608f8658d7e0f3dd2d/src/test/java/RouteToActorTest.java> and verified that it works alright. :) On Tue, Aug 18, 2015 at 1:55 PM, William Bezuidenhout < [email protected]> wrote: > Hi > > In light of the the route testkit module not having the JUnitTestRoute > class. I thought I would try to test using with JavaTestKit. > > Test setup: > system = ActorSystem.create(); > probe = new JavaTestKit(system); > webAPI = new WebAPI(actorRef); > webAPI.bindRoute("localhost", 8080, this.system); > materializer = ActorMaterializer.create(system); > > The route: > > public Future<Object> sendToActor(RechargeRequest request, > ExecutionContext ec) { > return Patterns.ask(apiActor, request, 3000); > } > > public Future<RouteResult> asyncSendToActor(final RequestContext ctx, > RechargeRequest recharge) { > Mapper<Object, RouteResult> func = new Mapper<Object, RouteResult>() { > @Override > public RouteResult apply(Object parameter) { > return ctx.complete("Test"); > } > }; > return sendToActor(recharge, ctx.executionContext()).map(func, ctx. > executionContext()); > } > > @Override > public Route createRoute() { > RequestVal<RechargeRequest> requestRequestVal = RequestVals.entityAs( > Jackson.jsonAs(RechargeRequest.class)); > return route(pathPrefix("recharge").route( > path("single").route(post(handleWithAsync1(requestRequestVal, > this::asyncSendToActor) > )))); > } > > The test case is as follows: > > ObjectMapper mapper = new ObjectMapper(); > String json = mapper.writeValueAsString(request); > HttpRequest httpRequest = HttpRequest.create() > .withUri("http://localhost:8080/recharge/single") > .withMethod(HttpMethods.POST) > .withEntity(MediaTypes.APPLICATION_JSON.toContentType(), json); > Http.get(system).singleRequest(httpRequest, materializer); > probe.expectMsgClass(RechargeRequest.class); > > The probe never receives the message class sent to it. What is the > recommended way of sending a message from an http route to an actor ? > > > > > -- > >>>>>>>>>> Read the docs: http://akka.io/docs/ > >>>>>>>>>> Check the FAQ: > http://doc.akka.io/docs/akka/current/additional/faq.html > >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user > --- > You received this message because you are subscribed to the Google Groups > "Akka User List" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/akka-user. > For more options, visit https://groups.google.com/d/optout. > -- Martynas Mickevičius Typesafe <http://typesafe.com/> – Reactive <http://www.reactivemanifesto.org/> Apps on the JVM -- >>>>>>>>>> Read the docs: http://akka.io/docs/ >>>>>>>>>> Check the FAQ: >>>>>>>>>> http://doc.akka.io/docs/akka/current/additional/faq.html >>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user --- You received this message because you are subscribed to the Google Groups "Akka User List" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/akka-user. For more options, visit https://groups.google.com/d/optout.
