|
| 1 | +package io.kubernetes.client.examples; |
| 2 | + |
| 3 | +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; |
| 4 | +import static com.github.tomakehurst.wiremock.client.WireMock.get; |
| 5 | +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; |
| 6 | +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; |
| 7 | +import static org.junit.Assert.assertEquals; |
| 8 | + |
| 9 | +import com.github.tomakehurst.wiremock.junit.WireMockRule; |
| 10 | +import io.kubernetes.client.ApiClient; |
| 11 | +import io.kubernetes.client.ApiException; |
| 12 | +import io.kubernetes.client.Configuration; |
| 13 | +import io.kubernetes.client.apis.CoreV1Api; |
| 14 | +import io.kubernetes.client.models.V1Namespace; |
| 15 | +import io.kubernetes.client.models.V1ObjectMeta; |
| 16 | +import java.io.IOException; |
| 17 | +import org.junit.Rule; |
| 18 | +import org.junit.Test; |
| 19 | + |
| 20 | +public class ExampleTest { |
| 21 | + private static final int PORT = 8089; |
| 22 | + @Rule public WireMockRule wireMockRule = new WireMockRule(PORT); |
| 23 | + |
| 24 | + @Test |
| 25 | + public void exactUrlOnly() throws IOException, ApiException { |
| 26 | + ApiClient client = new ApiClient(); |
| 27 | + client.setBasePath("http://localhost:" + PORT); |
| 28 | + Configuration.setDefaultApiClient(client); |
| 29 | + |
| 30 | + V1Namespace ns1 = new V1Namespace().metadata(new V1ObjectMeta().name("name")); |
| 31 | + |
| 32 | + stubFor( |
| 33 | + get(urlEqualTo("/api/v1/namespaces/name")) |
| 34 | + .willReturn( |
| 35 | + aResponse() |
| 36 | + .withHeader("Content-Type", "application/json") |
| 37 | + .withBody(client.getJSON().serialize(ns1)))); |
| 38 | + |
| 39 | + CoreV1Api api = new CoreV1Api(); |
| 40 | + V1Namespace ns2 = api.readNamespace("name", null, null, null); |
| 41 | + assertEquals(ns1, ns2); |
| 42 | + } |
| 43 | +} |
0 commit comments