-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7921c65
commit ae69589
Showing
19 changed files
with
591 additions
and
64 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
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
75 changes: 75 additions & 0 deletions
75
...esttemplate-adapter/src/test/java/fr/ouestfrance/querydsl/postgrest/PostgrestRpcTest.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,75 @@ | ||
package fr.ouestfrance.querydsl.postgrest; | ||
|
||
import fr.ouestfrance.querydsl.postgrest.app.Post; | ||
import fr.ouestfrance.querydsl.postgrest.app.PostRequestWithSelect; | ||
import org.apache.commons.lang3.reflect.TypeUtils; | ||
import org.apache.hc.client5.http.impl.classic.HttpClients; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockserver.client.MockServerClient; | ||
import org.mockserver.junit.jupiter.MockServerSettings; | ||
import org.mockserver.model.HttpRequest; | ||
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.util.List; | ||
|
||
import static fr.ouestfrance.querydsl.postgrest.TestUtils.jsonResponse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
@MockServerSettings(ports = 8007) | ||
class PostgrestRpcTest { | ||
|
||
private PostgrestRpcClient rpcClient; | ||
|
||
@BeforeEach | ||
void beforeEach(MockServerClient client) { | ||
client.reset(); | ||
RestTemplate restTemplate = new RestTemplate(); | ||
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(HttpClients.createDefault())); | ||
PostgrestRestTemplate postgrestRestTemplate = PostgrestRestTemplate.of(restTemplate, "http://localhost:8007"); | ||
rpcClient = new PostgrestRpcClient(postgrestRestTemplate); | ||
} | ||
|
||
@Test | ||
void shouldCallRpc(MockServerClient client) { | ||
client.when(HttpRequest.request().withPath("/rpc/testV1")) | ||
.respond(jsonResponse(""" | ||
{"id": 1, "title": "test"} | ||
""")); | ||
Post result = rpcClient.executeRpc("testV1", Post.class); | ||
assertNotNull(result); | ||
} | ||
|
||
@Test | ||
void shouldCallRpcWithCriteria(MockServerClient client) { | ||
client.when(HttpRequest.request().withPath("/rpc/testV1") | ||
.withQueryStringParameter("userId", "eq.1") | ||
.withQueryStringParameter("select", "title,userId")) | ||
.respond(jsonResponse(""" | ||
{"id": 1, "title": "test"} | ||
""")); | ||
|
||
PostRequestWithSelect criteria = new PostRequestWithSelect(); | ||
criteria.setUserId(1); | ||
Post result = rpcClient.executeRpc("testV1", criteria,null, Post.class); | ||
assertNotNull(result); | ||
System.out.println(result); | ||
} | ||
|
||
@Test | ||
void shouldCallRpcWithCriteriaResultIsList(MockServerClient client) { | ||
client.when(HttpRequest.request().withPath("/rpc/testV1") | ||
.withQueryStringParameter("userId", "eq.1") | ||
.withQueryStringParameter("select", "title,userId")) | ||
.respond(jsonResponse(""" | ||
[{"id": 1, "title": "test"}] | ||
""")); | ||
|
||
PostRequestWithSelect criteria = new PostRequestWithSelect(); | ||
criteria.setUserId(1); | ||
List<Post> result = rpcClient.executeRpc("testV1", criteria, null, TypeUtils.parameterize(List.class, Post.class)); | ||
assertNotNull(result); | ||
System.out.println(result); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...grest-resttemplate-adapter/src/test/java/fr/ouestfrance/querydsl/postgrest/TestUtils.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,29 @@ | ||
package fr.ouestfrance.querydsl.postgrest; | ||
|
||
import lombok.SneakyThrows; | ||
import org.mockserver.model.HttpResponse; | ||
import org.mockserver.model.MediaType; | ||
import shaded_package.org.apache.commons.io.IOUtils; | ||
|
||
import java.nio.charset.Charset; | ||
|
||
import static org.mockserver.model.HttpResponse.response; | ||
|
||
public class TestUtils { | ||
|
||
public static HttpResponse jsonResponse(String content) { | ||
return HttpResponse.response().withContentType(MediaType.APPLICATION_JSON) | ||
.withBody(content); | ||
} | ||
|
||
|
||
public static HttpResponse jsonFileResponse(String resourceFileName) { | ||
return response().withContentType(MediaType.APPLICATION_JSON) | ||
.withBody(jsonOf(resourceFileName)); | ||
} | ||
|
||
@SneakyThrows | ||
public static String jsonOf(String name) { | ||
return IOUtils.resourceToString(name, Charset.defaultCharset(), TestUtils.class.getClassLoader()); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...te-adapter/src/test/java/fr/ouestfrance/querydsl/postgrest/app/PostRequestWithSelect.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,22 @@ | ||
package fr.ouestfrance.querydsl.postgrest.app; | ||
|
||
import fr.ouestfrance.querydsl.FilterField; | ||
import fr.ouestfrance.querydsl.FilterOperation; | ||
import fr.ouestfrance.querydsl.postgrest.annotations.Select; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Select({"title", "userId"}) | ||
public class PostRequestWithSelect { | ||
|
||
@FilterField | ||
private Integer userId; | ||
@FilterField(operation = FilterOperation.NEQ.class) | ||
private Integer id; | ||
} |
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
Oops, something went wrong.