Skip to content

Commit

Permalink
#554 - fixed all ORACLE tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grabdoc committed May 11, 2024
1 parent 13c08b4 commit 270ffb6
Show file tree
Hide file tree
Showing 13 changed files with 50 additions and 44 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.homihq.db2rest;

import com.homihq.db2rest.jdbc.multidb.RoutingDataSource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.boot.test.context.TestConfiguration;
Expand All @@ -11,6 +12,7 @@

import javax.sql.DataSource;
import java.util.List;
import java.util.Map;

@TestConfiguration(proxyBeanMethods = false)
@Profile("it-oracle")
Expand Down Expand Up @@ -39,7 +41,13 @@ public DataSource dataSource() {
dataSourceBuilder.url(testOracle10g.getJdbcUrl());
dataSourceBuilder.username(testOracle10g.getUsername());
dataSourceBuilder.password(testOracle10g.getPassword());
return dataSourceBuilder.build();
DataSource dataSource = dataSourceBuilder.build();

final RoutingDataSource routingDataSource = new RoutingDataSource();
routingDataSource.setTargetDataSources(Map.of("oradb", dataSource));
routingDataSource.setDefaultTargetDataSource(dataSource);

return routingDataSource;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ class OracleBasicJoinControllerTest extends OracleBaseIntegrationTest {
@GivenJsonResource("/testdata/RIGHT_JOIN_ORACLE.json")
List<Map<String,Object>> RIGHT_JOIN;

@Disabled
@Test
@DisplayName("Test left Join")
void testLeftJoin() throws Exception {


mockMvc.perform(post("/USERS/_expand")
mockMvc.perform(post("/oradb/USERS/_expand")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(LEFT_JOIN))
)
Expand All @@ -61,13 +60,13 @@ void testLeftJoin() throws Exception {

}

@Disabled

@Test
@DisplayName("Test right Join")
void testRightJoin() throws Exception {


mockMvc.perform(post("/USERS/_expand")
mockMvc.perform(post("/oradb/USERS/_expand")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(RIGHT_JOIN))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class OracleBulkCreateControllerTest extends OracleBaseIntegrationTest {
@DisplayName("Create many films.")
void create() throws Exception {

mockMvc.perform(post("/FILM/bulk")
mockMvc.perform(post("/oradb/FILM/bulk")
.queryParam("sequences", "film_id:film_sequence")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(BULK_CREATE_FILM_REQUEST))
Expand All @@ -80,7 +80,7 @@ void create() throws Exception {
@DisplayName("Create many films with CSV type.")
void createCSV() throws Exception {

mockMvc.perform(post("/FILM/bulk")
mockMvc.perform(post("/oradb/FILM/bulk")
.queryParam("sequences", "film_id:film_sequence")
.contentType("text/csv").accept(APPLICATION_JSON)
.content(CREATE_FILM_REQUEST_CSV))
Expand All @@ -98,7 +98,7 @@ void createCSV() throws Exception {
@DisplayName("Create many films with CSV type resulting error.")
void createCSVWithError() throws Exception {

mockMvc.perform(post("/FILM/bulk")
mockMvc.perform(post("/oradb/FILM/bulk")
.queryParam("sequences", "film_id:film_sequence")
.contentType("text/csv")
.accept(APPLICATION_JSON)
Expand All @@ -113,7 +113,7 @@ void createCSVWithError() throws Exception {
@DisplayName("Create many films with failure.")
void createError() throws Exception {

mockMvc.perform(post("/FILM/bulk")
mockMvc.perform(post("/oradb/FILM/bulk")
.queryParam("sequences", "film_id:film_sequence")
.contentType(APPLICATION_JSON)
.accept(APPLICATION_JSON)
Expand All @@ -128,7 +128,7 @@ void createError() throws Exception {
@DisplayName("Create many directors.")
void createDirector() throws Exception {

mockMvc.perform(post("/DIRECTOR/bulk")
mockMvc.perform(post("/oradb/DIRECTOR/bulk")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.param("tsIdEnabled", "true")
.content(objectMapper.writeValueAsString(BULK_CREATE_DIRECTOR_REQUEST))
Expand All @@ -143,7 +143,7 @@ void createDirector() throws Exception {
@DisplayName("Create many directors with wrong tsid type.")
void createDirectorWithWrongTsidType() throws Exception {

mockMvc.perform(post("/DIRECTOR/bulk")
mockMvc.perform(post("/oradb/DIRECTOR/bulk")
.characterEncoding(UTF_8)
.contentType(APPLICATION_JSON)
.accept(APPLICATION_JSON)
Expand All @@ -162,7 +162,7 @@ void createDirectorWithWrongTsidType() throws Exception {
@DisplayName("Create reviews with default tsid type.")
void createReviewWithDefaultTsidType() throws Exception {

mockMvc.perform(post("/REVIEW/bulk")
mockMvc.perform(post("/oradb/REVIEW/bulk")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.param("tsIdEnabled", "true")
.content(objectMapper.writeValueAsString(BULK_CREATE_REVIEW_REQUEST))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class OracleCountControllerTest extends OracleBaseIntegrationTest {
@Test
@DisplayName("Get count")
void findFilmCount() throws Exception {
mockMvc.perform(get("/FILM/count")
mockMvc.perform(get("/oradb/FILM/count")
.accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
//.andDo(print())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class OracleCreateControllerTest extends OracleBaseIntegrationTest {
@DisplayName("Create a film.")
void create() throws Exception {

mockMvc.perform(post("/FILM")
mockMvc.perform(post("/oradb/FILM")
.queryParam("sequences", "film_id:film_sequence")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(CREATE_FILM_REQUEST))
Expand All @@ -67,7 +67,7 @@ void create() throws Exception {
@DisplayName("Test Create a film with error.")
void createError() throws Exception {

mockMvc.perform(post("/FILM")
mockMvc.perform(post("/oradb/FILM")
.queryParam("sequences", "film_id:film_sequence")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(CREATE_FILM_REQUEST_ERROR)))
Expand All @@ -81,7 +81,7 @@ void createError() throws Exception {
@DisplayName("Test create a film - non existent table.")
void createNonExistentTable() throws Exception {

mockMvc.perform(post("/FILMS")
mockMvc.perform(post("/oradb/FILMS")
.queryParam("sequences", "film_id:film_sequence")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(CREATE_FILM_REQUEST)))
Expand All @@ -95,7 +95,7 @@ void createNonExistentTable() throws Exception {
@DisplayName("Test Create a director - TSID enabled")
void createDirectorWithTSIDEnabled() throws Exception {
//TODO - MySQL return keys not working
mockMvc.perform(post("/DIRECTOR")
mockMvc.perform(post("/oradb/DIRECTOR")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.param("tsIdEnabled", "true")
.content(objectMapper.writeValueAsString(CREATE_DIRECTOR_REQUEST)))
Expand All @@ -112,7 +112,7 @@ void createDirectorWithTSIDEnabled() throws Exception {
@DisplayName("Create a director - with TSID explicitly OFF")
void createDirectorWithTSIDOff() throws Exception {

mockMvc.perform(post("/DIRECTOR")
mockMvc.perform(post("/oradb/DIRECTOR")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.param("tsIdEnabled", "false")
.content(objectMapper.writeValueAsString(CREATE_DIRECTOR_REQUEST)))
Expand All @@ -126,7 +126,7 @@ void createDirectorWithTSIDOff() throws Exception {
@DisplayName("Test Create a Vanity Van - with varchar tsid type")
void createVanityVanWithVarcharTsIdType() throws Exception {
//TODO - MySQL return keys not working
mockMvc.perform(post("/VANITY_VAN")
mockMvc.perform(post("/oradb/VANITY_VAN")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.param("tsIdEnabled", "true")
.content(objectMapper.writeValueAsString(CREATE_VANITY_VAN_REQUEST)))
Expand All @@ -141,7 +141,7 @@ void createVanityVanWithVarcharTsIdType() throws Exception {
@Test
@DisplayName("Create a film with subset of columns")
void createFilmWithSubsetOfColumns() throws Exception {
var result = mockMvc.perform(post("/FILM")
var result = mockMvc.perform(post("/oradb/FILM")
.queryParam("sequences", "film_id:film_sequence")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.queryParam("columns", "title,description,language_id")
Expand All @@ -157,7 +157,7 @@ void createFilmWithSubsetOfColumns() throws Exception {

var pk = JsonPath.read(result.getResponse().getContentAsString(), "$.keys.FILM_ID");

mockMvc.perform(get("/FILM")
mockMvc.perform(get("/oradb/FILM")
.accept(APPLICATION_JSON)
.queryParam("fields", "title,release_year")
.queryParam("filter", String.format("film_id==%s", pk)))
Expand All @@ -174,7 +174,7 @@ void createFilmWithSubsetOfColumns() throws Exception {
@DisplayName("Ignore if columns parameter is blank")
void shouldIgnoreWhenColumnsQueryParamIsEmpty() throws Exception {

var result = mockMvc.perform(post("/FILM")
var result = mockMvc.perform(post("/oradb/FILM")
.queryParam("sequences", "film_id:film_sequence")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.queryParam("columns", "")
Expand All @@ -189,7 +189,7 @@ void shouldIgnoreWhenColumnsQueryParamIsEmpty() throws Exception {

var pk = JsonPath.read(result.getResponse().getContentAsString(), "$.keys.FILM_ID");

mockMvc.perform(get("/FILM")
mockMvc.perform(get("/oradb/FILM")
.accept(APPLICATION_JSON)
.queryParam("fields", "title,release_year")
.queryParam("filter", String.format("film_id==%s", pk)))
Expand All @@ -207,7 +207,7 @@ void shouldIgnoreWhenColumnsQueryParamIsEmpty() throws Exception {
@DisplayName("Column is present in columns param but not in payload")
void columnIsPresentInColumnsQueryParamButNotInPayload() throws Exception {

var result = mockMvc.perform(post("/FILM")
var result = mockMvc.perform(post("/oradb/FILM")
.contentType(APPLICATION_JSON)
.accept(APPLICATION_JSON)
.queryParam("columns", "title,description,language_id")
Expand All @@ -224,7 +224,7 @@ void columnIsPresentInColumnsQueryParamButNotInPayload() throws Exception {
@DisplayName("Column violates not-null constraint")
void column_violates_not_null_constraint() throws Exception {

mockMvc.perform(post("/FILM")
mockMvc.perform(post("/oradb/FILM")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.queryParam("columns", "title,description")
.content(objectMapper.writeValueAsString(CREATE_FILM_REQUEST)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class OracleCrossJoinControllerTest extends OracleBaseIntegrationTest {
void testCrossJoin() throws Exception {


mockMvc.perform(post("/USERS/_expand")
mockMvc.perform(post("/oradb/USERS/_expand")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(CROSS_JOIN))
)
Expand All @@ -68,7 +68,7 @@ void testCrossJoin() throws Exception {
void testCrossJoinTops() throws Exception {


mockMvc.perform(post("/TOPS/_expand")
mockMvc.perform(post("/oradb/TOPS/_expand")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(CROSS_JOIN_TOPS))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class OracleDeleteAllTest extends OracleBaseIntegrationTest {
@Test
@DisplayName("Delete all records while allowSafeDelete=false")
void deleteAllWithAllowSafeDeleteFalse() throws Exception {
mockMvc.perform(delete("/COUNTRY")
mockMvc.perform(delete("/oradb/COUNTRY")
.accept(APPLICATION_JSON))
.andDo(print())
.andExpect(status().isOk())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class OracleDeleteControllerTest extends OracleBaseIntegrationTest {
@Test
@DisplayName("Delete a Director")
void delete_single_record() throws Exception {
mockMvc.perform(delete("/DIRECTOR")
mockMvc.perform(delete("/oradb/DIRECTOR")
.accept(APPLICATION_JSON)
.param("filter", "first_name==\"Alex\""))
.andExpect(status().isOk())
Expand All @@ -32,7 +32,7 @@ void delete_single_record() throws Exception {
@Test
@DisplayName("Delete all records while allowSafeDelete=true")
void delete_all_records_with_allow_safe_delete_true() throws Exception {
mockMvc.perform(delete("/DIRECTOR")
mockMvc.perform(delete("/oradb/DIRECTOR")
.accept(APPLICATION_JSON))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.detail",
Expand All @@ -44,7 +44,7 @@ void delete_all_records_with_allow_safe_delete_true() throws Exception {
@Test
@DisplayName("Column Does Not Exist")
void column_does_not_exist() throws Exception {
mockMvc.perform(delete("/DIRECTOR")
mockMvc.perform(delete("/oradb/DIRECTOR")
.accept(APPLICATION_JSON)
.param("filter", "_name==\"Alex\""))
.andExpect(status().isNotFound())
Expand All @@ -58,7 +58,7 @@ void column_does_not_exist() throws Exception {
@Test
@DisplayName("Foreign Key Constraint Violation")
void foreign_key_constraint_violation() throws Exception {
mockMvc.perform(delete("/LANGUAGE")
mockMvc.perform(delete("/oradb/LANGUAGE")
.accept(APPLICATION_JSON)
.param("filter", "name==\"English\""))
.andDo(print())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class OracleInnerJoinControllerTest extends OracleBaseIntegrationTest {
void testInnerJoin() throws Exception {


mockMvc.perform(post("/REVIEW/_expand")
mockMvc.perform(post("/oradb/REVIEW/_expand")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(INNER_JOIN))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class OracleInnerJoinMultiTableControllerTest extends OracleBaseIntegrationTest
void testInnerMultiTable() throws Exception {


mockMvc.perform(post("/FILM/_expand")
mockMvc.perform(post("/oradb/FILM/_expand")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(INNER_JOIN_MULTI_TABLE))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,10 @@ class OracleInnerSelfJoinControllerTest extends OracleBaseIntegrationTest {

@Test
@DisplayName("Test inner self Join")
@Disabled
void testInnerSelfJoin() throws Exception {


mockMvc.perform(post("/FILM/_expand")
mockMvc.perform(post("/oradb/FILM/_expand")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(INNER_SELF_JOIN))
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class OracleReadControllerTest extends OracleBaseIntegrationTest {
@DisplayName("Test find all films - all columns.")
void findAllFilms() throws Exception {

mockMvc.perform(get("/FILM")
mockMvc.perform(get("/oradb/FILM")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON))
//.andDo(print())
.andExpect(status().isOk())
Expand All @@ -35,7 +35,7 @@ void findAllFilms() throws Exception {
@Test
@DisplayName("Test find all films - 3 columns")
void findAllFilmsWithThreeCols() throws Exception {
mockMvc.perform(get("/FILM")
mockMvc.perform(get("/oradb/FILM")
.contentType(APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)
.param("fields", "title,description,release_year")
)
Expand All @@ -50,7 +50,7 @@ void findAllFilmsWithThreeCols() throws Exception {
@Test
@DisplayName("Test find all films - with column alias")
void findAllFilmsWithColumnAlias() throws Exception {
mockMvc.perform(get("/FILM")
mockMvc.perform(get("/oradb/FILM")
.contentType(APPLICATION_JSON).accept(MediaType.APPLICATION_JSON)
.param("fields", "title,description,release_year:releaseYear")
)
Expand All @@ -68,7 +68,7 @@ void findAllFilmsWithColumnAlias() throws Exception {
@Test
@DisplayName("Get one")
void findOneFilm() throws Exception {
mockMvc.perform(get("/FILM/one")
mockMvc.perform(get("/oradb/FILM/one")
.accept(MediaType.APPLICATION_JSON)
.param("fields", "title")
.param("filter", "film_id==1"))
Expand Down
Loading

0 comments on commit 270ffb6

Please sign in to comment.