From 5604be753bfca79921e0d5ba7c36378b3b0ebd7e Mon Sep 17 00:00:00 2001 From: Sourav Roy Date: Sun, 21 Jan 2024 16:53:25 +0000 Subject: [PATCH] adding integration tests for stored procs and functions, stored proc integration test for postgress is not working --- .../rest/MySQLFunctionControllerTest.java | 37 ++++++++++++++++ .../rest/MySQLProcedureControllerTest.java | 38 +++++++++++++++++ .../rest/PgFunctionControllerTest.java | 38 +++++++++++++++++ .../rest/PgProcedureControllerTest.java | 42 +++++++++++++++++++ 4 files changed, 155 insertions(+) create mode 100644 src/test/java/com/homihq/db2rest/rest/MySQLFunctionControllerTest.java create mode 100644 src/test/java/com/homihq/db2rest/rest/MySQLProcedureControllerTest.java create mode 100644 src/test/java/com/homihq/db2rest/rest/PgFunctionControllerTest.java create mode 100644 src/test/java/com/homihq/db2rest/rest/PgProcedureControllerTest.java diff --git a/src/test/java/com/homihq/db2rest/rest/MySQLFunctionControllerTest.java b/src/test/java/com/homihq/db2rest/rest/MySQLFunctionControllerTest.java new file mode 100644 index 00000000..481b8ae6 --- /dev/null +++ b/src/test/java/com/homihq/db2rest/rest/MySQLFunctionControllerTest.java @@ -0,0 +1,37 @@ +package com.homihq.db2rest.rest; + +import com.homihq.db2rest.MySQLBaseIntegrationTest; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.http.MediaType; + +import java.util.Map; + +import static org.hamcrest.Matchers.*; +import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +class MySQLFunctionControllerTest extends MySQLBaseIntegrationTest { + @Test + @DisplayName("Execute function on mysql db") + void execute() throws Exception { + var json = """ + { + "movieTitle": "ACADEMY DINOSAUR" + } + """; + + mockMvc.perform(post("/function/GetMovieRentalRateFunc") + .contentType(MediaType.APPLICATION_JSON).characterEncoding("utf-8") + .content(json).accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$", instanceOf(Map.class))) + .andExpect(jsonPath("$.*", hasSize(1))) + .andExpect(jsonPath("$.return", equalTo(0.99))) + .andDo(print()) + .andDo(document("mysql-execute-function")); + } +} diff --git a/src/test/java/com/homihq/db2rest/rest/MySQLProcedureControllerTest.java b/src/test/java/com/homihq/db2rest/rest/MySQLProcedureControllerTest.java new file mode 100644 index 00000000..ebdfb380 --- /dev/null +++ b/src/test/java/com/homihq/db2rest/rest/MySQLProcedureControllerTest.java @@ -0,0 +1,38 @@ +package com.homihq.db2rest.rest; + +import com.homihq.db2rest.MySQLBaseIntegrationTest; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.http.MediaType; + +import java.util.Map; + +import static org.hamcrest.Matchers.*; +import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +class MySQLProcedureControllerTest extends MySQLBaseIntegrationTest { + + @Test + @DisplayName("Execute stored procedure on mysql db") + void execute() throws Exception { + var json = """ + { + "movieTitle": "ACADEMY DINOSAUR" + } + """; + + mockMvc.perform(post("/procedure/GetMovieRentalRateProc") + .contentType(MediaType.APPLICATION_JSON).characterEncoding("utf-8") + .content(json).accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$", instanceOf(Map.class))) + .andExpect(jsonPath("$.*", hasSize(2))) + .andExpect(jsonPath("$.rentalRate", equalTo(0.99))) + .andDo(print()) + .andDo(document("mysql-execute-procedure")); + } +} diff --git a/src/test/java/com/homihq/db2rest/rest/PgFunctionControllerTest.java b/src/test/java/com/homihq/db2rest/rest/PgFunctionControllerTest.java new file mode 100644 index 00000000..65537440 --- /dev/null +++ b/src/test/java/com/homihq/db2rest/rest/PgFunctionControllerTest.java @@ -0,0 +1,38 @@ +package com.homihq.db2rest.rest; + +import com.homihq.db2rest.PostgreSQLBaseIntegrationTest; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.http.MediaType; + +import java.util.Map; + +import static org.hamcrest.Matchers.*; +import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +class PgFunctionControllerTest extends PostgreSQLBaseIntegrationTest { + + @Test + @DisplayName("Execute function on postgres db") + void execute() throws Exception { + var json = """ + { + "movieTitle": "ACADEMY DINOSAUR" + } + """; + + mockMvc.perform(post("/function/GetMovieRentalRateFunc") + .contentType(MediaType.APPLICATION_JSON).characterEncoding("utf-8") + .content(json).accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$", instanceOf(Map.class))) + .andExpect(jsonPath("$.*", hasSize(1))) + .andExpect(jsonPath("$.returnvalue", equalTo(0.99))) + .andDo(print()) + .andDo(document("pg-execute-function")); + } +} diff --git a/src/test/java/com/homihq/db2rest/rest/PgProcedureControllerTest.java b/src/test/java/com/homihq/db2rest/rest/PgProcedureControllerTest.java new file mode 100644 index 00000000..efc4f319 --- /dev/null +++ b/src/test/java/com/homihq/db2rest/rest/PgProcedureControllerTest.java @@ -0,0 +1,42 @@ +package com.homihq.db2rest.rest; + +import com.homihq.db2rest.PostgreSQLBaseIntegrationTest; +import org.hamcrest.Matchers; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.http.MediaType; + +import java.util.Map; + +import static org.hamcrest.Matchers.*; +import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; +import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +class PgProcedureControllerTest extends PostgreSQLBaseIntegrationTest { + + @Test + @Disabled //TODO - Need to fix + @DisplayName("Execute stored procedure on postgres db") + void execute() throws Exception { + var json = """ + { + "movieTitle": "ACADEMY DINOSAUR" + } + """; + + mockMvc.perform(post("/procedure/GetMovieRentalRateProc") + .contentType(MediaType.APPLICATION_JSON).characterEncoding("utf-8") + .content(json).accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$", instanceOf(Map.class))) + //.andExpect(jsonPath("$.*", hasSize(2))) + //.andExpect(jsonPath("$.rentalRate", equalTo(0.99))) + .andDo(print()) + .andDo(document("mysql-execute-procedure")); + } + +}