Skip to content

Commit

Permalink
test: refactored OpenShiftOAuthInterceptorTest to not rely on mocks
Browse files Browse the repository at this point in the history
Signed-off-by: Marc Nuri <[email protected]>
  • Loading branch information
manusa authored Oct 30, 2024
1 parent 75d30c7 commit badd7c8
Show file tree
Hide file tree
Showing 3 changed files with 185 additions and 207 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package io.fabric8.kubernetes.client.http;

import java.nio.charset.StandardCharsets;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand All @@ -27,17 +28,19 @@
*/
public class TestHttpResponse<T> extends StandardHttpHeaders implements HttpResponse<T> {

private final Map<String, List<String>> headers;
private int code;
private T body;
private HttpRequest request;
private HttpResponse<T> previousResponse;

public TestHttpResponse() {
super();
this(new LinkedHashMap<>());
}

public TestHttpResponse(Map<String, List<String>> headers) {
super(headers);
this.headers = headers;
}

@Override
Expand Down Expand Up @@ -78,7 +81,7 @@ public TestHttpResponse<T> withBody(T body) {
return this;
}

public HttpResponse<T> withRequest(HttpRequest request) {
public TestHttpResponse<T> withRequest(HttpRequest request) {
this.request = request;
return this;
}
Expand All @@ -87,11 +90,22 @@ public HttpResponse<T> getPreviousResponse() {
return previousResponse;
}

public HttpResponse<T> withPreviousResponse(HttpResponse<T> previousResponse) {
public TestHttpResponse<T> withPreviousResponse(HttpResponse<T> previousResponse) {
this.previousResponse = previousResponse;
return this;
}

public TestHttpResponse<T> withHeader(String name, String value) {
headers.compute(name, (k, v) -> {
if (v == null) {
v = new java.util.ArrayList<>();
}
v.add(value);
return v;
});
return this;
}

public static TestHttpResponse<byte[]> from(int code, String body) {
return new TestHttpResponse<byte[]>().withCode(code)
.withBody(body.getBytes(StandardCharsets.UTF_8));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import lombok.Getter;

import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.stream.IntStream;
import java.util.stream.Stream;
Expand Down Expand Up @@ -77,4 +78,8 @@ public final void expect(String pathRegex, int statusCode, byte[] body) {
instances.forEach(c -> c.expect(pathRegex, statusCode, body));
}

public final void expect(String pathRegex, CompletableFuture<HttpResponse<AsyncBody>> future) {
instances.forEach(c -> c.expect(pathRegex, future));
}

}
Loading

0 comments on commit badd7c8

Please sign in to comment.