Skip to content

Instantly share code, notes, and snippets.

@RunWith(Arquillian.class)
public class BookTest {
@Deployment(testable = false, name = "bookservice")
public static WebArchive createDeploymentBookInfoService() {
return ShrinkWrap.create(WebArchive.class, "bookservice.war").addClasses(BookInfoService.class, ApplicationResource.class);
}
@Deployment(testable = false, name = "bookcomments")
public static WebArchive createDeploymentCommentsService() {
@GET
@Path("{isbn}")
@Produces(MediaType.APPLICATION_JSON)
public void bookAndComment(@Suspended final AsyncResponse asyncResponse, @PathParam("isbn") String isbn) {
//Calling previous defined functions
Observable<JsonObject> bookInfo = getBookInfo(isbn);
Observable<JsonArray> comments = getComments(isbn);
Observable.zip(bookInfo, comments, (JsonObject book, JsonArray bookcomments) ->
Json.createObjectBuilder().add("book", book).add("comments", bookcomments).build()
public Observable<JsonArray> getComments(final String isbn) {
return Observable.create((Observable.OnSubscribe<JsonArray>) subscriber -> {
Runnable r = () -> {
subscriber.onNext(commentServiceTarget.path(isbn).request().get(JsonArray.class));
subscriber.onCompleted();
};
executor.execute(r);
public Observable<JsonObject> getBookInfo(final String isbn) {
return Observable.create((Observable.OnSubscribe<JsonObject>) subscriber -> {
Runnable r = () -> {
subscriber.onNext(bookServiceTarget.path(isbn).request().get(JsonObject.class));
subscriber.onCompleted();
};
executor.execute(r);
@Singleton
@Path("book")
public class BookService {
private static final String BOOKSERVICE = "http://localhost:8080/bookservice";
private static final String COMMENTSERVICE = "http://localhost:8080/bookcomments";
@Resource(name = "DefaultManagedExecutorService")
ManagedExecutorService executor;
@ApplicationPath("rest")
public class ApplicationResource extends Application {
}
@Singleton
@Path("comments")
public class CommentsService {
@GET
@Path("{isbn}")
@Produces(MediaType.APPLICATION_JSON)
public JsonArray bookComments(@PathParam("isbn") String isbn) {
return Json.createArrayBuilder().add("Good Book").add("Awesome").build();
@Singleton
@Path("bookinfo")
public class BookInfoService {
@GET
@Path("{isbn}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public JsonObject findBookByISBN(@PathParam("isbn") String isbn) {
<repository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Maven Repository Group</name>
<url>https://repository.jboss.org/nexus/content/groups/public</url>
</repository>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>undertow-embedded</artifactId>
<version>1.0.0.Alpha1</version>
<container qualifier="undertow" default="true">
<configuration>
<property name="bindAddress">localhost</property>
<property name="bindHttpPort">9090</property> <1>
</configuration>
</container>