Skip to content

Commit

Permalink
adding integration tests for stored procs and functions, stored proc …
Browse files Browse the repository at this point in the history
…integration test for postgress is not working
  • Loading branch information
souravroy committed Jan 21, 2024
1 parent a784f1e commit 5604be7
Show file tree
Hide file tree
Showing 4 changed files with 155 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
@@ -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"));
}
}
Original file line number Diff line number Diff line change
@@ -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"));
}

}

0 comments on commit 5604be7

Please sign in to comment.