-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat (kubernetes-client-api) : Expose put method with InputStream arg…
…uments in HttpRequest Related to eclipse-jkube/jkube#1364 Signed-off-by: Rohan Kumar <rohaan@redhat.com>
- Loading branch information
1 parent
f1185a0
commit 1f73a1a
Showing
8 changed files
with
213 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
httpclient-jdk/src/test/java/io/fabric8/kubernetes/client/jdkhttp/JdkHttpClientPutTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.fabric8.kubernetes.client.jdkhttp; | ||
|
||
import io.fabric8.kubernetes.client.http.AbstractHttpPutTest; | ||
import io.fabric8.kubernetes.client.http.HttpClient; | ||
|
||
@SuppressWarnings("java:S2187") | ||
public class JdkHttpClientPutTest extends AbstractHttpPutTest { | ||
@Override | ||
protected HttpClient.Factory getHttpClientFactory() { | ||
return new JdkHttpClientFactory(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
httpclient-jetty/src/test/java/io/fabric8/kubernetes/client/jetty/JettyHttpPutTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.fabric8.kubernetes.client.jetty; | ||
|
||
import io.fabric8.kubernetes.client.http.AbstractHttpPutTest; | ||
import io.fabric8.kubernetes.client.http.HttpClient; | ||
|
||
@SuppressWarnings("java:S2187") | ||
public class JettyHttpPutTest extends AbstractHttpPutTest { | ||
@Override | ||
protected HttpClient.Factory getHttpClientFactory() { | ||
return new JettyHttpClientFactory(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
httpclient-okhttp/src/test/java/io/fabric8/kubernetes/client/okhttp/OkHttpPutTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.fabric8.kubernetes.client.okhttp; | ||
|
||
import io.fabric8.kubernetes.client.http.AbstractHttpPutTest; | ||
import io.fabric8.kubernetes.client.http.HttpClient; | ||
|
||
@SuppressWarnings("java:S2187") | ||
public class OkHttpPutTest extends AbstractHttpPutTest { | ||
@Override | ||
protected HttpClient.Factory getHttpClientFactory() { | ||
return new OkHttpClientFactory(); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...client-vertx/src/test/java/io/fabric8/kubernetes/client/vertx/VertxHttpClientPutTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.fabric8.kubernetes.client.vertx; | ||
|
||
import io.fabric8.kubernetes.client.http.AbstractHttpPutTest; | ||
import io.fabric8.kubernetes.client.http.HttpClient; | ||
|
||
@SuppressWarnings("java:S2187") | ||
public class VertxHttpClientPutTest extends AbstractHttpPutTest { | ||
@Override | ||
protected HttpClient.Factory getHttpClientFactory() { | ||
return new VertxHttpClientFactory(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...netes-client-api/src/test/java/io/fabric8/kubernetes/client/http/AbstractHttpPutTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* Copyright (C) 2015 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.fabric8.kubernetes.client.http; | ||
|
||
import io.fabric8.mockwebserver.DefaultMockServer; | ||
import okhttp3.mockwebserver.RecordedRequest; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public abstract class AbstractHttpPutTest { | ||
private static DefaultMockServer server; | ||
|
||
@BeforeAll | ||
static void beforeAll() { | ||
server = new DefaultMockServer(false); | ||
server.start(); | ||
} | ||
|
||
@AfterAll | ||
static void afterAll() { | ||
server.shutdown(); | ||
} | ||
|
||
protected abstract HttpClient.Factory getHttpClientFactory(); | ||
|
||
@Test | ||
@DisplayName("String body, should send a PUT request with body") | ||
public void putStringBody() throws Exception { | ||
// When | ||
try (HttpClient client = getHttpClientFactory().newBuilder().build()) { | ||
client | ||
.sendAsync(client.newHttpRequestBuilder() | ||
.uri(server.url("/put-string")) | ||
.put("text/plain", "A string body") | ||
.build(), String.class) | ||
.get(10L, TimeUnit.SECONDS); | ||
} | ||
// Then | ||
assertThat(server.getLastRequest()) | ||
.returns("PUT", RecordedRequest::getMethod) | ||
.returns("A string body", rr -> rr.getBody().readUtf8()) | ||
.extracting(rr -> rr.getHeader("Content-Type")).asString() | ||
.startsWith("text/plain"); | ||
} | ||
|
||
@Test | ||
@DisplayName("InputStream body, should send a PUT request with body") | ||
public void putInputStreamBody() throws Exception { | ||
// When | ||
try (HttpClient client = getHttpClientFactory().newBuilder().build()) { | ||
client | ||
.sendAsync(client.newHttpRequestBuilder() | ||
.uri(server.url("/put-input-stream")) | ||
.put("text/plain", new ByteArrayInputStream("A string body".getBytes(StandardCharsets.UTF_8)), -1) | ||
.build(), String.class) | ||
.get(10L, TimeUnit.SECONDS); | ||
} | ||
// Then | ||
assertThat(server.getLastRequest()) | ||
.returns("PUT", RecordedRequest::getMethod) | ||
.returns("A string body", rr -> rr.getBody().readUtf8()) | ||
.extracting(rr -> rr.getHeader("Content-Type")).asString() | ||
.startsWith("text/plain"); | ||
} | ||
} |