Skip to content

Commit ff169d6

Browse files
committed
patch method
1 parent e47936a commit ff169d6

File tree

6 files changed

+39
-1
lines changed

6 files changed

+39
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<url>https://github.com/clean-arch-enablers-project/cae-utils-http-client/blob/main/README.md</url>
99
<groupId>com.clean-arch-enablers</groupId>
1010
<artifactId>cae-http-client</artifactId>
11-
<version>1.0.0</version>
11+
<version>1.1.0</version>
1212
<packaging>jar</packaging>
1313
<licenses>
1414
<license>

src/main/java/com/cae/http_client/HttpRequestStarter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public interface HttpRequestStarter {
77
HttpRequestBuilder startGetRequestFor(String url);
88
HttpRequestBuilder startPostRequestFor(String url, HttpRequest.BodyPublisher body);
99
HttpRequestBuilder startPutRequestFor(String url, HttpRequest.BodyPublisher body);
10+
HttpRequestBuilder startPatchRequestFor(String url, HttpRequest.BodyPublisher body);
1011
HttpRequestBuilder startDeleteRequestFor(String url);
1112

1213
}

src/main/java/com/cae/http_client/implementations/FinalHttpRequestFactory.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ public static HttpRequest makeFinalRequestForPutMethodFrom(AbstractHttpRequestMo
2626
return finallyBuildIt(finalHttpRequestBuilder, httpRequestModel);
2727
}
2828

29+
public static HttpRequest makeFinalRequestForPatchMethodFrom(AbstractHttpRequestModel httpRequestModel) {
30+
var finalHttpRequestBuilder = HttpRequest.newBuilder().method("PATCH", httpRequestModel.body);
31+
return finallyBuildIt(finalHttpRequestBuilder, httpRequestModel);
32+
}
33+
2934
public static HttpRequest makeFinalRequestForDeleteMethodFrom(AbstractHttpRequestModel httpRequestModel) {
3035
var finalHttpRequestBuilder = HttpRequest.newBuilder().DELETE();
3136
return finallyBuildIt(finalHttpRequestBuilder, httpRequestModel);
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.cae.http_client.implementations;
2+
3+
import com.cae.http_client.HttpRequestMethod;
4+
import com.cae.http_client.HttpResponse;
5+
import com.cae.http_client.implementations.exceptions.RetryNeededOnExceptionThrownException;
6+
7+
public class HttpRequestPatchMethod implements HttpRequestMethod {
8+
@Override
9+
public HttpResponse execute(AbstractHttpRequestModel httpRequestModel) throws RetryNeededOnExceptionThrownException {
10+
var finalRequest = FinalHttpRequestFactory.makeFinalRequestForPatchMethodFrom(httpRequestModel);
11+
try {
12+
var unwrappedResponse = FinalHttpRequestExecutor.of(httpRequestModel).execute(finalRequest);
13+
return new HttpResponseImplementation(httpRequestModel, unwrappedResponse);
14+
}
15+
catch (Exception exception) {
16+
ExceptionThrownByHttpRequestChecker.of(httpRequestModel).checkOn(exception);
17+
throw exception;
18+
}
19+
}
20+
}

src/main/java/com/cae/http_client/implementations/HttpRequestStarterImplementation.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public HttpRequestBuilder startPutRequestFor(String url, HttpRequest.BodyPublish
2323
return HttpRequestBuilderImplementation.of(HttpRequestModelImplementation.of(url, new HttpRequestPutMethod(), body));
2424
}
2525

26+
@Override
27+
public HttpRequestBuilder startPatchRequestFor(String url, HttpRequest.BodyPublisher body) {
28+
return HttpRequestBuilderImplementation.of(HttpRequestModelImplementation.of(url, new HttpRequestPatchMethod(), body));
29+
}
30+
2631
@Override
2732
public HttpRequestBuilder startDeleteRequestFor(String url) {
2833
return HttpRequestBuilderImplementation.of(HttpRequestModelImplementation.of(url, new HttpRequestDeleteMethod()));

src/test/java/com/cae/http_client/implementations/HttpRequestStarterImplementationTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,11 @@ void shouldReturnNonNullInstanceOfBuilderWhenStartingForPutMethod(){
3838
Assertions.assertNotNull(this.httpRequestStarter.startPutRequestFor("http://localhost:2222", HttpRequest.BodyPublishers.ofString("{someRandomJsonField: \"someRandomValue\"}")));
3939
}
4040

41+
@Test
42+
@DisplayName("Should return non null instance of builder when starting for patch method")
43+
void shouldReturnNonNullInstanceOfBuilderWhenStartingForPatchMethod(){
44+
Assertions.assertNotNull(this.httpRequestStarter.startPatchRequestFor("http://localhost:2222", HttpRequest.BodyPublishers.ofString("{someRandomJsonField: \"someRandomValue\"}")));
45+
}
46+
47+
4148
}

0 commit comments

Comments
 (0)