Skip to content

Commit a25f685

Browse files
authored
Merge pull request #393 from brendandburns/unit
Add a simple example test.
2 parents 1743608 + 698299b commit a25f685

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

examples/pom.xml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23
<modelVersion>4.0.0</modelVersion>
34
<groupId>io.kubernetes</groupId>
45
<artifactId>client-java-examples</artifactId>
@@ -39,6 +40,12 @@
3940
<version>${junit-version}</version>
4041
<scope>test</scope>
4142
</dependency>
43+
<dependency>
44+
<groupId>com.github.tomakehurst</groupId>
45+
<artifactId>wiremock</artifactId>
46+
<version>2.19.0</version>
47+
<scope>test</scope>
48+
</dependency>
4249
</dependencies>
4350
<build>
4451
<plugins>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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

Comments
 (0)