Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more parameter types in Dev UI JsonRPC Tests #37511

Merged
merged 1 commit into from
Dec 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void testGenerateMigrationFromHibernate() throws Exception {
RestAssured.get("fruit").then().statusCode(200)
.body("[0].name", CoreMatchers.is("Orange"));

Map<String, String> params = Map.of("ds", "<default>");
Map<String, Object> params = Map.of("ds", "<default>");
JsonNode devuiresponse = super.executeJsonRPCMethod("create", params);

Assertions.assertNotNull(devuiresponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public void testCleanDatabase() throws Exception {
RestAssured.when().get("/my-entity/count").then().body(is("2"));
RestAssured.when().get("/my-entity/add").then().body(is("MyEntity:added"));
RestAssured.when().get("/my-entity/count").then().body(is("3"));
Map<String, String> params = Map.of("ds", "<default>");
Map<String, Object> params = Map.of("ds", "<default>");
JsonNode success = super.executeJsonRPCMethod("reset", params);
assertTrue(success.asBoolean());
RestAssured.when().get("/my-entity/count").then().body(is("2"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public <T> T executeJsonRPCMethod(TypeReference typeReference, String methodName
}

@SuppressWarnings("unchecked")
public <T> T executeJsonRPCMethod(TypeReference typeReference, String methodName, Map<String, String> params)
public <T> T executeJsonRPCMethod(TypeReference typeReference, String methodName, Map<String, Object> params)
throws Exception {
int id = sendRequest(methodName, params);
T response = getJsonRPCResponse(typeReference, id);
Expand All @@ -71,7 +71,7 @@ public JsonNode executeJsonRPCMethod(String methodName) throws Exception {
return executeJsonRPCMethod(methodName, null);
}

public JsonNode executeJsonRPCMethod(String methodName, Map<String, String> params) throws Exception {
public JsonNode executeJsonRPCMethod(String methodName, Map<String, Object> params) throws Exception {
return executeJsonRPCMethod(JsonNode.class, methodName, params);
}

Expand All @@ -80,7 +80,7 @@ public <T> T executeJsonRPCMethod(Class<T> classType, String methodName) throws
}

@SuppressWarnings("unchecked")
public <T> T executeJsonRPCMethod(Class<T> classType, String methodName, Map<String, String> params) throws Exception {
public <T> T executeJsonRPCMethod(Class<T> classType, String methodName, Map<String, Object> params) throws Exception {

int id = sendRequest(methodName, params);
T response = getJsonRPCResponse(classType, id);
Expand Down Expand Up @@ -168,7 +168,7 @@ private JsonNode objectResultFromJsonRPC(int id, int loopCount) throws Interrupt
}
}

private String createJsonRPCRequest(int id, String methodName, Map<String, String> params) throws IOException {
private String createJsonRPCRequest(int id, String methodName, Map<String, Object> params) throws IOException {

ObjectNode request = mapper.createObjectNode();

Expand All @@ -177,15 +177,16 @@ private String createJsonRPCRequest(int id, String methodName, Map<String, Strin
request.put("method", this.namespace + "." + methodName);
ObjectNode jsonParams = mapper.createObjectNode();
if (params != null && !params.isEmpty()) {
for (Map.Entry<String, String> p : params.entrySet()) {
jsonParams.put(p.getKey(), p.getValue());
for (Map.Entry<String, Object> p : params.entrySet()) {
JsonNode convertValue = mapper.convertValue(p.getValue(), JsonNode.class);
jsonParams.putIfAbsent(p.getKey(), convertValue);
}
}
request.set("params", jsonParams);
return mapper.writerWithDefaultPrettyPrinter().writeValueAsString(request);
}

private int sendRequest(String methodName, Map<String, String> params) throws IOException {
private int sendRequest(String methodName, Map<String, Object> params) throws IOException {
int id = random.nextInt(Integer.MAX_VALUE);
String request = createJsonRPCRequest(id, methodName, params);
log.debug("request = " + request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public void testServices() throws Exception {

@Test
public void testTestService() throws Exception {
Map<String, String> params = Map.of(
Map<String, Object> params = Map.of(
"serviceName", "helloworld.Greeter",
"methodName", "SayHello",
"methodType", "UNARY",
Expand Down
Loading