-
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathWireMockContainerExtensionTest.java
More file actions
66 lines (56 loc) · 2.57 KB
/
WireMockContainerExtensionTest.java
File metadata and controls
66 lines (56 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
* Copyright (C) 2023 WireMock Inc, Oleg Nenashev and all project contributors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.wiremock.integrations.testcontainers;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testcontainers.containers.output.Slf4jLogConsumer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.wiremock.integrations.testcontainers.util.SimpleHttpResponse;
import org.wiremock.integrations.testcontainers.util.SimpleHttpClient;
import java.nio.file.Paths;
import java.time.Duration;
import java.util.Collections;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests the WireMock extension loading.
* It uses the external Jar supplied by the Maven Dependency Plugin.
*/
@Testcontainers
class WireMockContainerExtensionTest {
private static final Logger LOGGER = LoggerFactory.getLogger(WireMockContainerExtensionTest.class);
@Container
WireMockContainer wiremockServer = new WireMockContainer(WireMockContainer.WIREMOCK_2_LATEST)
.withLogConsumer(new Slf4jLogConsumer(LOGGER))
.withStartupTimeout(Duration.ofSeconds(60))
.withMapping("json-body-transformer", WireMockContainerExtensionTest.class, "json-body-transformer.json")
.withExtension("JSON Body Transformer",
Collections.singleton("com.ninecookies.wiremock.extensions.JsonBodyTransformer"),
Collections.singleton(Paths.get("target", "test-wiremock-extension", "wiremock-extensions-0.4.1-jar-with-dependencies.jar").toFile()));
@Test
void testJSONBodyTransformer() throws Exception {
// given
String url = wiremockServer.getUrl("/json-body-transformer");
String body = "{\"name\":\"John Doe\"}";
// when
SimpleHttpResponse response = new SimpleHttpClient().post(url, body);
// then
assertThat(response.getBody())
.as("Wrong response body")
.contains("Hello, John Doe!");
}
}