Skip to content

Commit 4744758

Browse files
committed
feat!: Removed MockWebServer deprecated methods
1 parent 4f99b2b commit 4744758

File tree

6 files changed

+18
-45
lines changed

6 files changed

+18
-45
lines changed

kubernetes-client/src/test/java/io/fabric8/kubernetes/server/mock/KubernetesMockServer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.fabric8.kubernetes.client.ConfigBuilder;
2121
import io.fabric8.kubernetes.client.DefaultKubernetesClient;
2222
import io.fabric8.kubernetes.client.NamespacedKubernetesClient;
23+
import io.fabric8.kubernetes.client.utils.Serialization;
2324
import io.fabric8.mockwebserver.Context;
2425
import io.fabric8.mockwebserver.DefaultMockServer;
2526
import io.fabric8.mockwebserver.ServerRequest;
@@ -37,7 +38,7 @@
3738
// The class has moved under mvn:io.fabric8:kubernetes-server-mock in package: io.fabric8.client.server.mock
3839
public class KubernetesMockServer extends DefaultMockServer {
3940

40-
private static final Context context = new Context();
41+
private static final Context context = new Context(Serialization.jsonMapper());
4142

4243
public KubernetesMockServer() {
4344
this(true);

kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/CustomResourceDefinitionProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class CustomResourceDefinitionProcessor {
3030
private static final String V1BETA1_PATH = "/apis/apiextensions.k8s.io/v1beta1/customresourcedefinitions";
3131
private static final String V1_PATH = "/apis/apiextensions.k8s.io/v1/customresourcedefinitions";
3232

33-
private KubernetesAttributesExtractor extractor;
33+
private final KubernetesAttributesExtractor extractor;
3434

3535
public CustomResourceDefinitionProcessor(KubernetesAttributesExtractor extractor) {
3636
this.extractor = extractor;

kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesAttributesExtractor.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
import static io.fabric8.mockwebserver.crud.AttributeType.NOT_EXISTS;
4545
import static io.fabric8.mockwebserver.crud.AttributeType.WITHOUT;
4646

47-
public class KubernetesAttributesExtractor implements AttributeExtractor<HasMetadata> {
47+
public class KubernetesAttributesExtractor implements AttributeExtractor {
4848

4949
private static final Logger LOGGER = LoggerFactory.getLogger(KubernetesAttributesExtractor.class);
5050

@@ -88,7 +88,7 @@ public class KubernetesAttributesExtractor implements AttributeExtractor<HasMeta
8888
private static final String SCHEME = "http";
8989
private static final String HOST = "localhost";
9090

91-
private Map<List<String>, CustomResourceDefinitionContext> crdContexts;
91+
private final Map<List<String>, CustomResourceDefinitionContext> crdContexts;
9292

9393
public KubernetesAttributesExtractor() {
9494
this(Collections.emptyList());
@@ -160,12 +160,6 @@ public AttributeSet fromResource(String s) {
160160
return new AttributeSet();
161161
}
162162

163-
@Override
164-
public AttributeSet extract(String s) {
165-
return fromPath(s);
166-
}
167-
168-
@Override
169163
public AttributeSet extract(HasMetadata hasMetadata) {
170164
AttributeSet metadataAttributes = new AttributeSet();
171165
String apiVersion = hasMetadata.getApiVersion();

kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesMockServer.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import io.fabric8.kubernetes.client.NamespacedKubernetesClient;
2323
import io.fabric8.kubernetes.client.utils.Serialization;
2424
import io.fabric8.mockwebserver.Context;
25-
import io.fabric8.mockwebserver.ContextBuilder;
2625
import io.fabric8.mockwebserver.DefaultMockServer;
2726
import io.fabric8.mockwebserver.ServerRequest;
2827
import io.fabric8.mockwebserver.ServerResponse;
@@ -31,7 +30,6 @@
3130
import okhttp3.mockwebserver.RecordedRequest;
3231

3332
import java.net.InetAddress;
34-
import java.util.Collections;
3533
import java.util.HashMap;
3634
import java.util.Map;
3735
import java.util.Queue;
@@ -41,7 +39,7 @@
4139

4240
public class KubernetesMockServer extends DefaultMockServer {
4341

44-
private static final Context context = new ContextBuilder().withMapper(Serialization.jsonMapper()).build();
42+
private static final Context context = new Context(Serialization.jsonMapper());
4543

4644
public KubernetesMockServer() {
4745
this(true);

kubernetes-server-mock/src/main/java/io/fabric8/kubernetes/client/server/mock/KubernetesServer.java

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ public class KubernetesServer extends ExternalResource {
3232

3333
private KubernetesMockServer mock;
3434
private NamespacedKubernetesClient client;
35-
private boolean https;
35+
private final boolean https;
3636
// In this mode the mock web server will store, read, update and delete
3737
// kubernetes resources using an in memory map and will appear as a real api
3838
// server.
39-
private boolean crudMode;
39+
private final boolean crudMode;
4040
private final InetAddress address;
41-
private int port;
42-
private List<CustomResourceDefinitionContext> crdContextList;
41+
private final int port;
42+
private final List<CustomResourceDefinitionContext> crdContextList;
4343

4444
public KubernetesServer() {
4545
this(true);
@@ -65,6 +65,7 @@ public KubernetesServer(boolean https, boolean crudMode, InetAddress address, in
6565
this.crdContextList = crdContextList;
6666
}
6767

68+
@Override
6869
public void before() {
6970
mock = crudMode
7071
? new KubernetesMockServer(new Context(), new MockWebServer(), new HashMap<>(), new KubernetesCrudDispatcher(crdContextList), https)
@@ -73,6 +74,7 @@ public void before() {
7374
client = mock.createClient();
7475
}
7576

77+
@Override
7678
public void after() {
7779
mock.destroy();
7880
client.close();
@@ -103,16 +105,7 @@ public void expectAndReturnAsString(String method, String path, int code, String
103105
expect().withPath(path).andReturn(code, body).always();
104106
}
105107

106-
public MockWebServer getMockServer() {
107-
return mock.getServer();
108-
}
109-
110108
public RecordedRequest getLastRequest() throws InterruptedException {
111-
int count = mock.getServer().getRequestCount();
112-
RecordedRequest request = null;
113-
while (count-- > 0) {
114-
request = mock.getServer().takeRequest();
115-
}
116-
return request;
109+
return mock.getLastRequest();
117110
}
118111
}

openshift-server-mock/src/main/java/io/fabric8/openshift/client/server/mock/OpenShiftServer.java

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,25 @@
1717

1818
import io.fabric8.kubernetes.client.KubernetesClient;
1919
import io.fabric8.kubernetes.client.server.mock.KubernetesCrudDispatcher;
20-
import io.fabric8.kubernetes.client.server.mock.KubernetesMockServer;
2120
import io.fabric8.mockwebserver.Context;
22-
import io.fabric8.mockwebserver.ServerRequest;
23-
import io.fabric8.mockwebserver.ServerResponse;
2421
import io.fabric8.mockwebserver.dsl.MockServerExpectation;
2522
import io.fabric8.openshift.client.NamespacedOpenShiftClient;
26-
import io.fabric8.openshift.client.OpenshiftAdapterSupport;
2723
import okhttp3.mockwebserver.MockWebServer;
2824
import okhttp3.mockwebserver.RecordedRequest;
2925
import org.junit.rules.ExternalResource;
3026

3127
import java.util.HashMap;
32-
import java.util.Queue;
3328

3429
public class OpenShiftServer extends ExternalResource {
3530

3631
protected OpenShiftMockServer mock;
3732
private NamespacedOpenShiftClient client;
3833

39-
private boolean https;
34+
private final boolean https;
4035
// In this mode the mock web server will store, read, update and delete
4136
// kubernetes resources using an in memory map and will appear as a real api
4237
// server.
43-
private boolean crudMode;
38+
private final boolean crudMode;
4439

4540
public OpenShiftServer() {
4641
this(true, false);
@@ -55,6 +50,7 @@ public OpenShiftServer(boolean https, boolean crudMode) {
5550
this.crudMode = crudMode;
5651
}
5752

53+
@Override
5854
public void before() {
5955
mock = crudMode
6056
? new OpenShiftMockServer(new Context(), new MockWebServer(), new HashMap<>(), new KubernetesCrudDispatcher(), https)
@@ -63,12 +59,12 @@ public void before() {
6359
client = mock.createOpenShiftClient();
6460
}
6561

62+
@Override
6663
public void after() {
6764
mock.destroy();
6865
client.close();
6966
}
7067

71-
7268
public KubernetesClient getKubernetesClient() {
7369
return client;
7470
}
@@ -91,16 +87,7 @@ public void expectAndReturnAsString(String path, int code, String body) {
9187
expect().withPath(path).andReturn(code, body).always();
9288
}
9389

94-
public MockWebServer getMockServer() {
95-
return mock.getServer();
96-
}
97-
9890
public RecordedRequest getLastRequest() throws InterruptedException {
99-
int count = mock.getServer().getRequestCount();
100-
RecordedRequest request = null;
101-
while (count-- > 0) {
102-
request = mock.getServer().takeRequest();
103-
}
104-
return request;
91+
return mock.getLastRequest();
10592
}
10693
}

0 commit comments

Comments
 (0)