Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jameskleeh committed Oct 21, 2019
1 parent 784006c commit ee853a5
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package io.micronaut.docs.basics

// tag::imports[]
import io.micronaut.context.annotation.Requires

// tag::imports[]
import io.micronaut.http.HttpStatus
import io.micronaut.http.MediaType
import io.micronaut.http.annotation.*
Expand All @@ -12,6 +13,7 @@ import io.reactivex.Maybe
import static io.micronaut.http.HttpRequest.GET
// end::imports[]

@Requires(property = "spec.name", value = "HelloControllerSpec")
@Controller("/")
class HelloController {

Expand Down Expand Up @@ -52,4 +54,4 @@ class HelloController {
String echoHello(@Body String message) {
return message
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import static io.micronaut.http.HttpRequest.POST

class HelloControllerSpec extends Specification {

@Shared @AutoCleanup EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer)
@Shared @AutoCleanup EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer, ["spec.name": HelloControllerSpec.simpleName])
@Shared @AutoCleanup RxHttpClient client = embeddedServer.getApplicationContext()
.createBean(RxHttpClient, embeddedServer.getURL())

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package io.micronaut.docs.basics

// tag::imports[]
import io.micronaut.context.annotation.Requires

// tag::imports[]
import io.micronaut.http.HttpStatus
import io.micronaut.http.MediaType
import io.micronaut.http.annotation.*
Expand All @@ -10,9 +11,9 @@ import io.micronaut.http.client.annotation.Client
import io.reactivex.Maybe

import io.micronaut.http.HttpRequest.GET

// end::imports[]

@Requires(property = "spec.name", value = "HelloControllerSpec")
@Controller("/")
class HelloController(@param:Client("/endpoint") private val httpClient: RxHttpClient) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import io.micronaut.http.HttpRequest.POST
class HelloControllerSpec: StringSpec() {

val embeddedServer = autoClose(
ApplicationContext.run(EmbeddedServer::class.java)
ApplicationContext.run(EmbeddedServer::class.java, mapOf("spec.name" to HelloControllerSpec::class.simpleName))
)

val client = autoClose(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.micronaut.docs.basics;

import io.micronaut.context.annotation.Requires;
// tag::imports[]

import io.micronaut.http.HttpStatus;
import io.micronaut.http.MediaType;
import io.micronaut.http.annotation.*;
Expand All @@ -12,6 +12,7 @@
import static io.micronaut.http.HttpRequest.GET;
// end::imports[]

@Requires(property = "spec.name", value = "HelloControllerSpec")
@Controller("/")
public class HelloController {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public class HelloControllerSpec {

@Test
public void testSimpleRetrieve() {
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class);
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class, Collections.singletonMap("spec.name", HelloControllerSpec.class.getSimpleName()));
RxHttpClient client = embeddedServer.getApplicationContext().createBean(RxHttpClient.class, embeddedServer.getURL());

// tag::simple[]
Expand All @@ -66,7 +66,7 @@ public void testSimpleRetrieve() {

@Test
public void testRetrieveWithHeaders() {
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class);
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class, Collections.singletonMap("spec.name", HelloControllerSpec.class.getSimpleName()));
RxHttpClient client = embeddedServer.getApplicationContext().createBean(RxHttpClient.class, embeddedServer.getURL());

// tag::headers[]
Expand All @@ -87,7 +87,7 @@ public void testRetrieveWithHeaders() {

@Test
public void testRetrieveWithJSON() {
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class);
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class, Collections.singletonMap("spec.name", HelloControllerSpec.class.getSimpleName()));
RxHttpClient client = embeddedServer.getApplicationContext().createBean(RxHttpClient.class, embeddedServer.getURL());

// tag::jsonmap[]
Expand Down Expand Up @@ -118,7 +118,7 @@ public void testRetrieveWithJSON() {

@Test
public void testRetrieveWithPOJO() {
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class);
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class, Collections.singletonMap("spec.name", HelloControllerSpec.class.getSimpleName()));
RxHttpClient client = embeddedServer.getApplicationContext().createBean(RxHttpClient.class, embeddedServer.getURL());

// tag::jsonpojo[]
Expand All @@ -138,7 +138,7 @@ public void testRetrieveWithPOJO() {

@Test
public void testRetrieveWithPOJOResponse() {
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class);
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class, Collections.singletonMap("spec.name", HelloControllerSpec.class.getSimpleName()));
RxHttpClient client = embeddedServer.getApplicationContext().createBean(RxHttpClient.class, embeddedServer.getURL());

// tag::pojoresponse[]
Expand Down Expand Up @@ -167,7 +167,7 @@ public void testRetrieveWithPOJOResponse() {

@Test
public void testPostRequestWithString() {
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class);
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class, Collections.singletonMap("spec.name", HelloControllerSpec.class.getSimpleName()));
RxHttpClient client = embeddedServer.getApplicationContext().createBean(RxHttpClient.class, embeddedServer.getURL());

// tag::poststring[]
Expand Down Expand Up @@ -199,7 +199,7 @@ public void testPostRequestWithString() {

@Test
public void testPostRequestWithPOJO() {
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class);
EmbeddedServer embeddedServer = ApplicationContext.run(EmbeddedServer.class, Collections.singletonMap("spec.name", HelloControllerSpec.class.getSimpleName()));
RxHttpClient client = embeddedServer.getApplicationContext().createBean(RxHttpClient.class, embeddedServer.getURL());

// tag::postpojo[]
Expand Down

0 comments on commit ee853a5

Please sign in to comment.