Looking for Code example to create akka.http.javadsl.testkitTestResponse

45 views
Skip to first unread message

john....@gmail.com

unread,
Aug 11, 2015, 6:24:32 AM8/11/15
to Akka User List
I am extending 
akka.http.javadsl.testkit.RouteTest.

In one of the methods I need to return a TestResponse.

 How can I do this with java
public TestResponse createTestResponse(HttpResponse response) {

   
return new TestResponse(response,null,null,null);
}

does not work?

john....@gmail.com

unread,
Aug 11, 2015, 7:52:18 AM8/11/15
to Akka User List
ok I found out:
return new TestResponse(response,null,null,null){
     
public  scala.runtime.Nothing$ fail( String message) { return null;}

     
public void assertEquals(int expected, int actual, String message) { }


     
public void assertEquals(Object expected, Object actual, String message) { }

     
@Override
      public void assertTrue(boolean predicate, String message) {}
   
};
}


The "scala.runtime.Nothing$" return type on fail was not obvious to me.

Akka Team

unread,
Aug 13, 2015, 3:01:40 AM8/13/15
to Akka User List
Yes, that is a little unfortunate: the Scala type system allows the expression of non-termination (the bottom type—Nothing) which Java does not know about, so this it what happens “under the hood” (i.e. in the sausage factory).

We might want to change the return type of `fail` from Nothing to Unit, what do you think, Johannes?

Regards,

Roland

--
>>>>>>>>>> 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 akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--
Akka Team
Typesafe - Reactive apps on the JVM
Blog: letitcrash.com
Twitter: @akkateam

Viktor Klang

unread,
Aug 13, 2015, 3:11:02 AM8/13/15
to Akka User List

java.lang.Void?

--
Cheers,

Johannes Rudolph

unread,
Aug 13, 2015, 4:18:39 AM8/13/15
to Akka User List
Yes, good point.

https://github.com/akka/akka/pull/18201

On the other hand, I wonder why you need to implement TestResponse, john? You should only ever need to implement it if you want to support another kind of testing framework. Is that what you are trying to achieve? To write tests with JUnit just derive your test class from JUnitRouteTest.

Have you seen http://doc.akka.io/docs/akka-stream-and-http-experimental/1.0/java/http/routing-dsl/testkit.html?

Johannes

john....@gmail.com

unread,
Aug 13, 2015, 8:30:13 AM8/13/15
to Akka User List
Hi Johannes,
I think I am doing the right thing (at least I hope (-: )

Here is my testing setup:
1) My test class needs to extend "SpringJUnit4ClassRunner" (which mocks a spring-mvn rest server)

2) the called  spring controller needs to integrate with a akka-http service  And here fore  I have programmed a injected  class which extends RoutTest which  actually calls the akkaservice.

So I think have exactly the test scenario which you I have foreseen with RoutTest.
And it works like a charm! I do not need to configure any ports and can test a full servlet-container-akka-http-akka-backend flow.....

Johannes Rudolph

unread,
Aug 13, 2015, 10:21:52 AM8/13/15
to akka-user
Hi john,

glad it works for you. Though, I have to say I don't think I
understand your use case completely, but maybe that's because of too
much spring in it :)

Johannes
> You received this message because you are subscribed to a topic in the
> Google Groups "Akka User List" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/akka-user/zTCdy1WnJQA/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> akka-user+...@googlegroups.com.
> To post to this group, send email to akka...@googlegroups.com.
> Visit this group at http://groups.google.com/group/akka-user.
> For more options, visit https://groups.google.com/d/optout.



--
Johannes

-----------------------------------------------
Johannes Rudolph
http://virtual-void.net
Reply all
Reply to author
Forward
0 new messages