parent
6036bd2c3b
commit
f8e0cc44f9
3 changed files with 40 additions and 1 deletions
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
|
@ -0,0 +1,2 @@
|
|||
*.iml
|
||||
target/
|
|
@ -1133,4 +1133,33 @@ class MockServerIntegrationTest extends Specification {
|
|||
remoteMockServer.removeMock('testRest')?.size() == 1
|
||||
}
|
||||
|
||||
@Unroll
|
||||
def 'should handle leading slash'() {
|
||||
given:
|
||||
String name = "testRest-${UUID.randomUUID().toString()}"
|
||||
expect:
|
||||
remoteMockServer.addMock(new AddMock(
|
||||
name: name,
|
||||
path: mockPath,
|
||||
port: 9999,
|
||||
statusCode: 201,
|
||||
soap: false
|
||||
))
|
||||
when:
|
||||
HttpPost restPost = new HttpPost("http://localhost:9999/$urlPath")
|
||||
CloseableHttpResponse response = client.execute(restPost)
|
||||
then:
|
||||
response.statusLine.statusCode == 201
|
||||
Util.consumeResponse(response)
|
||||
expect:
|
||||
remoteMockServer.removeMock(name)?.size() == 1
|
||||
where:
|
||||
mockPath | urlPath
|
||||
'' | ''
|
||||
'/' | ''
|
||||
'test' | 'test'
|
||||
'/test' | 'test'
|
||||
'test/other' | 'test/other'
|
||||
'/test/other' | 'test/other'
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,10 +41,18 @@ class Mock implements Comparable<Mock> {
|
|||
throw new RuntimeException("Mock name must be given")
|
||||
}
|
||||
this.name = name
|
||||
this.path = path
|
||||
this.path = stripLeadingSlash(path)
|
||||
this.port = port
|
||||
}
|
||||
|
||||
private static String stripLeadingSlash(String path) {
|
||||
if (path?.startsWith('/')) {
|
||||
return path - '/'
|
||||
} else {
|
||||
return path
|
||||
}
|
||||
}
|
||||
|
||||
boolean match(Method method, MockRequest request) {
|
||||
return this.method == method && predicate(request)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue