Skip to content

Commit c8c7f1f

Browse files
committed
fixes java 16 compability for util module
Signed-off-by: yue9944882 <291271447@qq.com>
1 parent e30312b commit c8c7f1f

File tree

9 files changed

+42
-75
lines changed

9 files changed

+42
-75
lines changed

kubernetes/src/main/java/io/kubernetes/client/openapi/JSON.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.google.gson.JsonElement;
1818
import com.google.gson.JsonParseException;
1919
import com.google.gson.TypeAdapter;
20+
import com.google.gson.internal.bind.ReflectiveTypeAdapterFactory;
2021
import com.google.gson.internal.bind.util.ISO8601Utils;
2122
import com.google.gson.stream.JsonReader;
2223
import com.google.gson.stream.JsonWriter;
@@ -30,6 +31,7 @@
3031
import java.text.ParseException;
3132
import java.text.ParsePosition;
3233
import java.time.LocalDate;
34+
import java.time.LocalDateTime;
3335
import java.time.OffsetDateTime;
3436
import java.time.format.DateTimeFormatter;
3537
import java.time.format.DateTimeFormatterBuilder;
@@ -108,6 +110,7 @@ public JSON() {
108110
.registerTypeAdapter(Date.class, dateTypeAdapter)
109111
.registerTypeAdapter(java.sql.Date.class, sqlDateTypeAdapter)
110112
.registerTypeAdapter(OffsetDateTime.class, offsetDateTimeTypeAdapter)
113+
.registerTypeAdapter(LocalDateTime.class, offsetDateTimeTypeAdapter)
111114
.registerTypeAdapter(LocalDate.class, localDateTypeAdapter)
112115
.registerTypeAdapter(byte[].class, byteArrayAdapter)
113116
.create();

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@
261261
<version>1.2.1</version>
262262
<scope>test</scope>
263263
</dependency>
264+
<dependency>
265+
<groupId>uk.org.webcompere</groupId>
266+
<artifactId>system-stubs-core</artifactId>
267+
<version>2.0.0</version>
268+
<scope>test</scope>
269+
</dependency>
264270
<dependency>
265271
<groupId>com.github.tomakehurst</groupId>
266272
<artifactId>wiremock</artifactId>

util/pom.xml

Lines changed: 2 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@
101101
<scope>test</scope>
102102
</dependency>
103103
<dependency>
104-
<groupId>com.github.stefanbirkner</groupId>
105-
<artifactId>system-lambda</artifactId>
104+
<groupId>uk.org.webcompere</groupId>
105+
<artifactId>system-stubs-core</artifactId>
106106
<scope>test</scope>
107107
</dependency>
108108
<dependency>
@@ -159,52 +159,4 @@
159159
</plugin>
160160
</plugins>
161161
</build>
162-
<profiles>
163-
<profile>
164-
<id>surefire-newerJava</id>
165-
<activation>
166-
<jdk>(1.8,)</jdk>
167-
</activation>
168-
<build>
169-
<plugins>
170-
<plugin>
171-
<groupId>org.apache.maven.plugins</groupId>
172-
<artifactId>maven-surefire-plugin</artifactId>
173-
<configuration>
174-
<argLine>
175-
@{argLine} -Xms512m -Xmx1500m --illegal-access=warn --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.time=ALL-UNNAMED
176-
</argLine>
177-
<parallel>methods</parallel>
178-
<perCoreThreadCount>false</perCoreThreadCount>
179-
<threadCount>1</threadCount>
180-
<forkCount>1</forkCount>
181-
<reuseForks>false</reuseForks>
182-
</configuration>
183-
</plugin>
184-
</plugins>
185-
</build>
186-
</profile>
187-
<profile>
188-
<id>surefire-java8</id>
189-
<activation>
190-
<jdk>1.8</jdk>
191-
</activation>
192-
<build>
193-
<plugins>
194-
<plugin>
195-
<groupId>org.apache.maven.plugins</groupId>
196-
<artifactId>maven-surefire-plugin</artifactId>
197-
<configuration>
198-
<argLine>@{argLine} -Xms512m -Xmx1500m</argLine>
199-
<parallel>methods</parallel>
200-
<perCoreThreadCount>false</perCoreThreadCount>
201-
<threadCount>1</threadCount>
202-
<forkCount>1</forkCount>
203-
<reuseForks>false</reuseForks>
204-
</configuration>
205-
</plugin>
206-
</plugins>
207-
</build>
208-
</profile>
209-
</profiles>
210162
</project>

util/src/main/java/io/kubernetes/client/util/Watch.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public static class Response<T> {
5252

5353
public V1Status status;
5454

55+
public Response() {}
56+
5557
public Response(String type, T object) {
5658
this.type = type;
5759
this.object = object;

util/src/test/java/io/kubernetes/client/util/ClientBuilderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
*/
1313
package io.kubernetes.client.util;
1414

15-
import static com.github.stefanbirkner.systemlambda.SystemLambda.withEnvironmentVariable;
1615
import static io.kubernetes.client.util.Config.ENV_SERVICE_HOST;
1716
import static io.kubernetes.client.util.Config.ENV_SERVICE_PORT;
1817
import static org.hamcrest.MatcherAssert.assertThat;
@@ -21,6 +20,7 @@
2120
import static org.junit.Assert.assertThrows;
2221
import static org.mockito.Mockito.mock;
2322
import static org.mockito.Mockito.verify;
23+
import static uk.org.webcompere.systemstubs.SystemStubs.withEnvironmentVariable;
2424

2525
import io.kubernetes.client.Resources;
2626
import io.kubernetes.client.openapi.ApiClient;

util/src/test/java/io/kubernetes/client/util/ConfigTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313
package io.kubernetes.client.util;
1414

15-
import static com.github.stefanbirkner.systemlambda.SystemLambda.withEnvironmentVariable;
15+
import static uk.org.webcompere.systemstubs.SystemStubs.withEnvironmentVariable;
1616
import static org.junit.Assert.*;
1717

1818
import io.kubernetes.client.openapi.ApiClient;

util/src/test/java/io/kubernetes/client/util/generic/GenericKubernetesApiForCoreApiTest.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
import static org.junit.Assert.*;
1717

1818
import com.github.tomakehurst.wiremock.junit.WireMockRule;
19-
import com.google.gson.Gson;
2019
import io.kubernetes.client.custom.V1Patch;
2120
import io.kubernetes.client.openapi.ApiClient;
21+
import io.kubernetes.client.openapi.JSON;
2222
import io.kubernetes.client.openapi.models.V1ListMeta;
2323
import io.kubernetes.client.openapi.models.V1ObjectMeta;
2424
import io.kubernetes.client.openapi.models.V1Pod;
@@ -36,6 +36,7 @@ public class GenericKubernetesApiForCoreApiTest {
3636

3737
@Rule public WireMockRule wireMockRule = new WireMockRule(8181);
3838

39+
private JSON json = new JSON();
3940
private GenericKubernetesApi<V1Pod, V1PodList> podClient;
4041

4142
@Before
@@ -51,7 +52,7 @@ public void deleteNamespacedPodReturningStatus() {
5152
V1Status status = new V1Status().kind("Status").code(200).message("good!");
5253
stubFor(
5354
delete(urlEqualTo("/api/v1/namespaces/default/pods/foo1"))
54-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(status))));
55+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(status))));
5556

5657
KubernetesApiResponse<V1Pod> deletePodResp = podClient.delete("default", "foo1", null);
5758
assertTrue(deletePodResp.isSuccess());
@@ -67,7 +68,7 @@ public void deleteNamespacedPodReturningDeletedObject() {
6768

6869
stubFor(
6970
delete(urlEqualTo("/api/v1/namespaces/default/pods/foo1"))
70-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(foo1))));
71+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
7172

7273
KubernetesApiResponse<V1Pod> deletePodResp = podClient.delete("default", "foo1");
7374
assertTrue(deletePodResp.isSuccess());
@@ -82,7 +83,7 @@ public void deleteNamespacedPodReturningForbiddenStatus() {
8283

8384
stubFor(
8485
delete(urlEqualTo("/api/v1/namespaces/default/pods/foo1"))
85-
.willReturn(aResponse().withStatus(403).withBody(new Gson().toJson(status))));
86+
.willReturn(aResponse().withStatus(403).withBody(json.serialize(status))));
8687

8788
KubernetesApiResponse<V1Pod> deletePodResp = podClient.delete("default", "foo1");
8889
assertFalse(deletePodResp.isSuccess());
@@ -97,7 +98,7 @@ public void listNamespacedPodReturningObject() {
9798

9899
stubFor(
99100
get(urlPathEqualTo("/api/v1/namespaces/default/pods"))
100-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(podList))));
101+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(podList))));
101102
KubernetesApiResponse<V1PodList> podListResp = podClient.list("default");
102103
assertTrue(podListResp.isSuccess());
103104
assertEquals(podList, podListResp.getObject());
@@ -111,7 +112,7 @@ public void listClusterPodReturningObject() {
111112

112113
stubFor(
113114
get(urlPathEqualTo("/api/v1/pods"))
114-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(podList))));
115+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(podList))));
115116
KubernetesApiResponse<V1PodList> podListResp = podClient.list();
116117
assertTrue(podListResp.isSuccess());
117118
assertEquals(podList, podListResp.getObject());
@@ -128,7 +129,7 @@ public void createNamespacedPodReturningObject() {
128129

129130
stubFor(
130131
post(urlEqualTo("/api/v1/namespaces/default/pods"))
131-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(foo1))));
132+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
132133
KubernetesApiResponse<V1Pod> podListResp = podClient.create(foo1);
133134
assertTrue(podListResp.isSuccess());
134135
assertEquals(foo1, podListResp.getObject());
@@ -143,7 +144,7 @@ public void updateNamespacedPodReturningObject() {
143144

144145
stubFor(
145146
put(urlEqualTo("/api/v1/namespaces/default/pods/foo1"))
146-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(foo1))));
147+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
147148
KubernetesApiResponse<V1Pod> podListResp = podClient.update(foo1);
148149
assertTrue(podListResp.isSuccess());
149150
assertEquals(foo1, podListResp.getObject());
@@ -159,7 +160,7 @@ public void patchNamespacedPodReturningObject() {
159160
stubFor(
160161
patch(urlEqualTo("/api/v1/namespaces/default/pods/foo1"))
161162
.withHeader("Content-Type", containing(V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH))
162-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(foo1))));
163+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
163164
KubernetesApiResponse<V1Pod> podPatchResp =
164165
podClient.patch("default", "foo1", V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, v1Patch);
165166

@@ -179,7 +180,7 @@ public void patchNamespacedPodWithApiPrefix() {
179180
stubFor(
180181
patch(urlEqualTo(prefix + "/api/v1/namespaces/default/pods/foo1"))
181182
.withHeader("Content-Type", containing(V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH))
182-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(foo1))));
183+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
183184

184185
GenericKubernetesApi<V1Pod, V1PodList> rancherPodClient =
185186
new GenericKubernetesApi<>(

util/src/test/java/io/kubernetes/client/util/generic/GenericKubernetesApiTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class GenericKubernetesApiTest {
4141

4242
@Rule public WireMockRule wireMockRule = new WireMockRule(8181);
4343

44+
private JSON json = new JSON();
4445
private GenericKubernetesApi<V1Job, V1JobList> jobClient;
4546

4647
@Before
@@ -56,7 +57,7 @@ public void deleteNamespacedJobReturningStatus() {
5657
V1Status status = new V1Status().kind("Status").code(200).message("good!");
5758
stubFor(
5859
delete(urlEqualTo("/apis/batch/v1/namespaces/default/jobs/foo1"))
59-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(status))));
60+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(status))));
6061

6162
KubernetesApiResponse<V1Job> deleteJobResp = jobClient.delete("default", "foo1", null);
6263
assertTrue(deleteJobResp.isSuccess());
@@ -72,7 +73,7 @@ public void deleteNamespacedJobReturningDeletedObject() {
7273

7374
stubFor(
7475
delete(urlEqualTo("/apis/batch/v1/namespaces/default/jobs/foo1"))
75-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(foo1))));
76+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
7677

7778
KubernetesApiResponse<V1Job> deleteJobResp = jobClient.delete("default", "foo1");
7879
assertTrue(deleteJobResp.isSuccess());
@@ -87,7 +88,7 @@ public void deleteNamespacedJobReturningForbiddenStatus() {
8788

8889
stubFor(
8990
delete(urlEqualTo("/apis/batch/v1/namespaces/default/jobs/foo1"))
90-
.willReturn(aResponse().withStatus(403).withBody(new Gson().toJson(status))));
91+
.willReturn(aResponse().withStatus(403).withBody(json.serialize(status))));
9192

9293
KubernetesApiResponse<V1Job> deleteJobResp = jobClient.delete("default", "foo1");
9394
assertFalse(deleteJobResp.isSuccess());
@@ -102,7 +103,7 @@ public void listNamespacedJobReturningObject() {
102103

103104
stubFor(
104105
get(urlPathEqualTo("/apis/batch/v1/namespaces/default/jobs"))
105-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(jobList))));
106+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(jobList))));
106107
KubernetesApiResponse<V1JobList> jobListResp = jobClient.list("default");
107108
assertTrue(jobListResp.isSuccess());
108109
assertEquals(jobList, jobListResp.getObject());
@@ -116,7 +117,7 @@ public void listClusterJobReturningObject() {
116117

117118
stubFor(
118119
get(urlPathEqualTo("/apis/batch/v1/jobs"))
119-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(jobList))));
120+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(jobList))));
120121
KubernetesApiResponse<V1JobList> jobListResp = jobClient.list();
121122
assertTrue(jobListResp.isSuccess());
122123
assertEquals(jobList, jobListResp.getObject());
@@ -131,7 +132,7 @@ public void createNamespacedJobReturningObject() {
131132

132133
stubFor(
133134
post(urlEqualTo("/apis/batch/v1/namespaces/default/jobs"))
134-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(foo1))));
135+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
135136
KubernetesApiResponse<V1Job> jobListResp = jobClient.create(foo1);
136137
assertTrue(jobListResp.isSuccess());
137138
assertEquals(foo1, jobListResp.getObject());
@@ -146,7 +147,7 @@ public void updateNamespacedJobReturningObject() {
146147

147148
stubFor(
148149
put(urlEqualTo("/apis/batch/v1/namespaces/default/jobs/foo1"))
149-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(foo1))));
150+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
150151
KubernetesApiResponse<V1Job> jobListResp = jobClient.update(foo1);
151152
assertTrue(jobListResp.isSuccess());
152153
assertEquals(foo1, jobListResp.getObject());
@@ -179,7 +180,7 @@ public void patchNamespacedJobReturningObject() {
179180
stubFor(
180181
patch(urlEqualTo("/apis/batch/v1/namespaces/default/jobs/foo1"))
181182
.withHeader("Content-Type", containing(V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH))
182-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(foo1))));
183+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(foo1))));
183184
KubernetesApiResponse<V1Job> jobPatchResp =
184185
jobClient.patch("default", "foo1", V1Patch.PATCH_FORMAT_STRATEGIC_MERGE_PATCH, v1Patch);
185186

@@ -195,7 +196,7 @@ public void watchNamespacedJobReturningObject() throws ApiException {
195196

196197
stubFor(
197198
get(urlPathEqualTo("/apis/batch/v1/namespaces/default/jobs"))
198-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(jobList))));
199+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(jobList))));
199200
Watchable<V1Job> jobListWatch = jobClient.watch("default", new ListOptions());
200201
verify(
201202
1,

util/src/test/java/io/kubernetes/client/util/generic/GenericKubernetesGetApiTest.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.github.tomakehurst.wiremock.junit.WireMockRule;
2020
import com.google.gson.Gson;
2121
import io.kubernetes.client.openapi.ApiClient;
22+
import io.kubernetes.client.openapi.JSON;
2223
import io.kubernetes.client.openapi.models.V1Job;
2324
import io.kubernetes.client.openapi.models.V1JobList;
2425
import io.kubernetes.client.openapi.models.V1Status;
@@ -31,6 +32,7 @@ public class GenericKubernetesGetApiTest {
3132

3233
@Rule public WireMockRule wireMockRule = new WireMockRule(8181);
3334

35+
private JSON json = new JSON();
3436
private GenericKubernetesApi<V1Job, V1JobList> jobClient; // non-core built-in resource
3537
private GenericKubernetesApi<FooCustomResource, FooCustomResourceList>
3638
fooClient; // custom resource
@@ -57,10 +59,10 @@ public void returningNormalObjectShouldWork() {
5759

5860
stubFor(
5961
get(urlEqualTo("/apis/batch/v1/namespaces/default/jobs/noxu"))
60-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(job))));
62+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(job))));
6163
stubFor(
6264
get(urlEqualTo("/apis/example.io/v1/namespaces/default/foos/noxu"))
63-
.willReturn(aResponse().withStatus(200).withBody(new Gson().toJson(foo))));
65+
.willReturn(aResponse().withStatus(200).withBody(json.serialize(foo))));
6466

6567
KubernetesApiResponse<V1Job> jobResp = jobClient.get("default", "noxu");
6668
KubernetesApiResponse<FooCustomResource> fooResp = fooClient.get("default", "noxu");
@@ -77,10 +79,10 @@ public void returningStatusShouldWork() {
7779

7880
stubFor(
7981
get(urlEqualTo("/apis/batch/v1/namespaces/default/jobs/noxu"))
80-
.willReturn(aResponse().withStatus(403).withBody(new Gson().toJson(forbiddenStatus))));
82+
.willReturn(aResponse().withStatus(403).withBody(json.serialize(forbiddenStatus))));
8183
stubFor(
8284
get(urlEqualTo("/apis/example.io/v1/namespaces/default/foos/noxu"))
83-
.willReturn(aResponse().withStatus(403).withBody(new Gson().toJson(forbiddenStatus))));
85+
.willReturn(aResponse().withStatus(403).withBody(json.serialize(forbiddenStatus))));
8486

8587
KubernetesApiResponse<V1Job> jobResp = jobClient.get("default", "noxu");
8688
KubernetesApiResponse<FooCustomResource> fooResp = fooClient.get("default", "noxu");

0 commit comments

Comments
 (0)