Updated ports

This commit is contained in:
Marcin Grzejszczak
2016-11-14 10:57:59 +01:00
parent 42d82dca23
commit ffc691167f
10 changed files with 47 additions and 19 deletions

View File

@@ -56,10 +56,12 @@ To start the stub server on a different port use `@AutoConfigureWireMock(port=99
=== Registering Stubs Automatically
If you add a `stubs` attribute to your `@AutoConfigureWireMock` then
it will register WireMock JSON stubs from the file system or
classpath. The stubs attribute can be a resource pattern (ant-style)
or a directory, in which case `**/*.json` is appended. Example:
If you use `@AutoConfigureWireMock` then it will register WireMock
JSON stubs from the file system or classpath, by default from
`file:src/test/resources/mappings`. You can customize the locations
using the `stubs` attribute in the annotation, which can be a resource
pattern (ant-style) or a directory, in which case `**/*.json` is
appended. Example:
----
@RunWith(SpringRunner.class)
@@ -78,6 +80,30 @@ public class WiremockImportApplicationTests {
}
----
NOTE: Actually WireMock always loads mappings from
`src/test/resources/mappings` *as well as* the custom locations in the
stubs attribute. To change this behaviour you have to also specify a
files root as described next.
=== Using Files to Specify the Stub Bodies
WireMock can read response bodies from files on the classpath or file
system. In that case you will see in the JSON DSL that the response
has a "bodyFileName" instead of a (literal) "body". The files are
resolved relative to a root directory `src/test/resources/__files` by
default. To customize this location you can set the `files` attribute
in the `@AutoConfigureWireMock` annotation to the location of the
parent directory (i.e. the place where `__files` is a
subdirectory). You can use Spring resource notation to refer to
`file:...` or `classpath:...` locations (but generic URLs are not
supported). A list of values can be given and WireMock will resolve
the first file that exists when it needs to find a response body.
NOTE: when you configure the `files` root, then it affects the
automatic loading of stubs as well (they come from the root location
in a subdirectory called "mappings"). The value of `files` has no
effect on the stubs loaded explicitly from the `stubs` attribute.
=== Alternative: Using JUnit Rules
For a more conventional WireMock experience, using JUnit `@Rules` to
@@ -760,8 +786,9 @@ Annotate your test class with `@AutoConfigureStubRunner`. In the annotation prov
[source,groovy,indent=0]
----
@RunWith(SpringRunner.class)
@SpringBootTest
@SpringBootTest(webEnvironment=WebEnvironment.NONE)
@AutoConfigureStubRunner(ids = {"com.example:http-server-dsl:+:stubs:8080"}, workOffline = true)
@DirtiesContext
public class LoanApplicationServiceTests {
----

View File

@@ -22,7 +22,7 @@ public class LoanApplicationService {
private final RestTemplate restTemplate;
private int port = 8080;
private int port = 6565;
public LoanApplicationService() {
this.restTemplate = new RestTemplate();

View File

@@ -1,5 +1,7 @@
package com.example.loan;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -14,12 +16,10 @@ import com.example.loan.model.LoanApplication;
import com.example.loan.model.LoanApplicationResult;
import com.example.loan.model.LoanApplicationStatus;
import static org.assertj.core.api.Assertions.assertThat;
// tag::autoconfigure_stubrunner[]
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment=WebEnvironment.NONE, properties="server.context-path=/app")
@AutoConfigureStubRunner(ids = {"com.example:http-server-dsl:+:stubs:8080"}, workOffline = true)
@AutoConfigureStubRunner(ids = {"com.example:http-server-dsl:+:stubs:6565"}, workOffline = true)
@DirtiesContext
public class LoanApplicationServiceContextPathTests {
// end::autoconfigure_stubrunner[]

View File

@@ -1,5 +1,7 @@
package com.example.loan;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
@@ -14,12 +16,10 @@ import com.example.loan.model.LoanApplication;
import com.example.loan.model.LoanApplicationResult;
import com.example.loan.model.LoanApplicationStatus;
import static org.assertj.core.api.Assertions.assertThat;
// tag::autoconfigure_stubrunner[]
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment=WebEnvironment.NONE)
@AutoConfigureStubRunner(ids = {"com.example:http-server-dsl:+:stubs:8080"}, workOffline = true)
@AutoConfigureStubRunner(ids = {"com.example:http-server-dsl:+:stubs:6565"}, workOffline = true)
@DirtiesContext
public class LoanApplicationServiceTests {
// end::autoconfigure_stubrunner[]

View File

@@ -1,3 +1,3 @@
stubrunner:
work-offline: true
stubs.ids: 'com.example:http-server-dsl-gradle:+:stubs:8080'
stubs.ids: 'com.example:http-server-dsl-gradle:+:stubs:6565'

View File

@@ -1,3 +1,2 @@
stubrunner:
work-offline: true
ids: 'com.example:http-server-dsl:+:stubs:8080'
server:
port: 6565

View File

@@ -1 +1 @@
server.port=8085
server.port=0

View File

@@ -1,3 +1,4 @@
stubrunner:
work-offline: true
ids: 'com.example:stream-source'
ids: 'com.example:stream-source'
server.port: 0

View File

@@ -1 +1,2 @@
spring.cloud.stream.bindings.output.contentType=application/json
server.port=0

View File

@@ -1 +1 @@
server.port=8085
server.port=0