Skip to content

Commit

Permalink
Fix sonar warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
lserveriiev committed Dec 1, 2024
1 parent a07deda commit 2275b75
Show file tree
Hide file tree
Showing 111 changed files with 735 additions and 813 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,7 @@ public SqlCreatorTemplate sqlCreatorTemplate(TemplateEngine templateEngine, Jdbc

@Bean
public TemplateEngine templateEngine() {
CodeResolver codeResolver =
new ResourceCodeResolver("sql-templates");
return TemplateEngine
.createPrecompiled(ContentType.Plain);
return TemplateEngine.createPrecompiled(ContentType.Plain);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Map;
import java.util.Optional;

@SuppressWarnings("java:S1192")
@RestController
@Slf4j
@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

@Import(MariaDBContainerConfiguration.class)
@ActiveProfiles("it-mariadb")
@SuppressWarnings("java:S2187")
public class MariaDBBaseIntegrationTest extends BaseIntegrationTest {

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

@Import(MongoContainerConfiguration.class)
@ActiveProfiles("it-mongo")
@SuppressWarnings("java:S2187")
public class MongoBaseIntegrationTest extends BaseIntegrationTest {

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.homihq.db2rest.jdbc.sql.DbMeta;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.mock.mockito.MockBean;

import java.util.ArrayList;
Expand Down Expand Up @@ -50,7 +51,7 @@ void setUp() {
}


//@Test
@Test
void getObjects() throws Exception {
mockMvc.perform(get(VERSION + "/$dbs")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ void setUp() {
}

private List<TableObject> getActualTableObject(String filter) {
List<TableObject> actualTableObject = (List<TableObject>) schemaController.getObjects("key", filter, Boolean.FALSE);
return actualTableObject;
return (List<TableObject>) schemaController.getObjects("key", filter, Boolean.FALSE);
}

private void testFilter(String goodFilter, String badFilter) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.springframework.test.web.servlet.MvcResult;

import java.io.UnsupportedEncodingException;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.OffsetDateTime;
import java.time.ZoneId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ class MariaDBBasicJoinControllerTest extends MariaDBBaseIntegrationTest {
.registerModule(new JavaTimeModule());

@GivenJsonResource("/testdata/LEFT_JOIN.json")
List<Map<String, Object>> LEFT_JOIN;
List<Map<String, Object>> leftJoin;

@GivenJsonResource("/testdata/RIGHT_JOIN.json")
List<Map<String, Object>> RIGHT_JOIN;
List<Map<String, Object>> rightJoin;

@Test
@DisplayName("Test left Join")
void testLeftJoin() throws Exception {
mockMvc.perform(post(VERSION + "/mariadb/users/_expand")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(LEFT_JOIN))
.content(objectMapper.writeValueAsString(leftJoin))
)
// .andDo(print())
.andExpect(status().isOk())
Expand All @@ -61,7 +61,7 @@ void testLeftJoin() throws Exception {
void testRightJoin() throws Exception {
mockMvc.perform(post(VERSION + "/mariadb/users/_expand")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(RIGHT_JOIN))
.content(objectMapper.writeValueAsString(rightJoin))
)
//.andDo(print())
.andExpect(status().isOk())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,33 @@ class MariaDBBulkCreateControllerTest extends MariaDBBaseIntegrationTest {
.registerModule(new JavaTimeModule());

@GivenJsonResource("/testdata/BULK_CREATE_FILM_REQUEST.json")
List<Map<String, Object>> BULK_CREATE_FILM_REQUEST;
List<Map<String, Object>> bulkCreateFilmRequest;

@GivenJsonResource("/testdata/BULK_CREATE_FILM_BAD_REQUEST.json")
List<Map<String, Object>> BULK_CREATE_FILM_BAD_REQUEST;
List<Map<String, Object>> bulkCreateFilmBadRequest;

@GivenTextResource("/testdata/CREATE_FILM_REQUEST_CSV.csv")
String CREATE_FILM_REQUEST_CSV;
String createFilmRequestCSV;

@GivenTextResource("/testdata/CREATE_FILM_BAD_REQUEST_CSV.csv")
String CREATE_FILM_BAD_REQUEST_CSV;
String createFilmBadRequestCSV;

@GivenJsonResource("/testdata/BULK_CREATE_DIRECTOR_REQUEST.json")
List<Map<String, Object>> BULK_CREATE_DIRECTOR_REQUEST;
List<Map<String, Object>> bulkCreateDirectorRequest;

@GivenJsonResource("/testdata/BULK_CREATE_DIRECTOR_BAD_REQUEST.json")
List<Map<String, Object>> BULK_CREATE_DIRECTOR_BAD_REQUEST;
List<Map<String, Object>> bulkCreateDirectorBadRequest;

@GivenJsonResource("/testdata/BULK_CREATE_REVIEW_REQUEST.json")
List<Map<String, Object>> BULK_CREATE_REVIEW_REQUEST;
List<Map<String, Object>> bulkCreateReviewRequest;

@Test
@DisplayName("Create many films.")
void create() throws Exception {

mockMvc.perform(post(VERSION + "/mariadb/film/bulk")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(BULK_CREATE_FILM_REQUEST))
.content(objectMapper.writeValueAsString(bulkCreateFilmRequest))
)
.andExpect(status().isCreated())
.andExpect(jsonPath("$.rows").isArray())
Expand All @@ -77,7 +78,7 @@ void create() throws Exception {
void createCSV() throws Exception {
mockMvc.perform(post(VERSION + "/mariadb/film/bulk")
.contentType("text/csv").accept(APPLICATION_JSON)
.content(CREATE_FILM_REQUEST_CSV))
.content(createFilmRequestCSV))
.andExpect(status().isCreated())
.andExpect(jsonPath("$.rows", hasSize(2)))
.andExpect(jsonPath("$.rows", hasItem(1)))
Expand All @@ -94,7 +95,7 @@ void createCSVWithError() throws Exception {
mockMvc.perform(post(VERSION + "/mariadb/film/bulk")
.contentType("text/csv")
.accept(APPLICATION_JSON)
.content(CREATE_FILM_BAD_REQUEST_CSV))
.content(createFilmBadRequestCSV))
.andExpect(status().isBadRequest())
//.andDo(print())
.andDo(document("mariadb-bulk-create-films-csv-error"));
Expand All @@ -106,7 +107,7 @@ void createError() throws Exception {
mockMvc.perform(post(VERSION + "/mariadb/film/bulk")
.contentType(APPLICATION_JSON)
.accept(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(BULK_CREATE_FILM_BAD_REQUEST))
.content(objectMapper.writeValueAsString(bulkCreateFilmBadRequest))
)
.andExpect(status().isBadRequest())
// .andDo(print())
Expand All @@ -119,7 +120,7 @@ void createDirector() throws Exception {
mockMvc.perform(post(VERSION + "/mariadb/director/bulk")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.param("tsIdEnabled", "true")
.content(objectMapper.writeValueAsString(BULK_CREATE_DIRECTOR_REQUEST))
.content(objectMapper.writeValueAsString(bulkCreateDirectorRequest))
)
.andExpect(status().isCreated())
//.andDo(print())
Expand All @@ -136,7 +137,7 @@ void createDirectorWithWrongTsidType() throws Exception {
.param("tsid", "director_id")
.param("tsidType", "string")
.header("Content-Profile", "sakila")
.content(objectMapper.writeValueAsString(BULK_CREATE_DIRECTOR_BAD_REQUEST))
.content(objectMapper.writeValueAsString(bulkCreateDirectorBadRequest))
)
.andExpect(status().isBadRequest())
//.andDo(print())
Expand All @@ -149,7 +150,7 @@ void createReviewWithDefaultTsidType() throws Exception {
mockMvc.perform(post(VERSION + "/mariadb/review/bulk")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.param("tsIdEnabled", "true")
.content(objectMapper.writeValueAsString(BULK_CREATE_REVIEW_REQUEST))
.content(objectMapper.writeValueAsString(bulkCreateReviewRequest))
)
.andExpect(status().isCreated())
//.andDo(print())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,26 @@ class MariaDBCreateControllerTest extends MariaDBBaseIntegrationTest {
.registerModule(new JavaTimeModule());

@GivenJsonResource("/testdata/CREATE_FILM_REQUEST.json")
Map<String, Object> CREATE_FILM_REQUEST;
Map<String, Object> createFilmRequest;

@GivenJsonResource("/testdata/CREATE_FILM_REQUEST_ERROR.json")
Map<String, Object> CREATE_FILM_REQUEST_ERROR;
Map<String, Object> createFilmRequestError;

@GivenJsonResource("/testdata/CREATE_VANITY_VAN_REQUEST.json")
Map<String, Object> CREATE_VANITY_VAN_REQUEST;
Map<String, Object> createVanityVanRequest;

@GivenJsonResource("/testdata/CREATE_DIRECTOR_REQUEST.json")
Map<String, Object> CREATE_DIRECTOR_REQUEST;
Map<String, Object> createDirectorRequest;

@GivenJsonResource("/testdata/CREATE_FILM_REQUEST_MISSING_PAYLOAD.json")
Map<String, Object> CREATE_FILM_REQUEST_MISSING_PAYLOAD;
Map<String, Object> createFilmRequestMissingPayload;

@Test
@DisplayName("Create a film.")
void create() throws Exception {
mockMvc.perform(post(VERSION + "/mariadb/film")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(CREATE_FILM_REQUEST))
.content(objectMapper.writeValueAsString(createFilmRequest))
)
//.andDo(print())
.andExpect(status().isCreated())
Expand All @@ -71,7 +71,7 @@ void createError() throws Exception {

mockMvc.perform(post(VERSION + "/mariadb/film")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(CREATE_FILM_REQUEST_ERROR)))
.content(objectMapper.writeValueAsString(createFilmRequestError)))
// .andDo(print())
.andExpect(status().isBadRequest())
.andDo(document("mariadb-create-a-film-error"));
Expand All @@ -82,7 +82,7 @@ void createError() throws Exception {
void createNonExistentTable() throws Exception {
mockMvc.perform(post(VERSION + "/mariadb/films")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(CREATE_FILM_REQUEST)))
.content(objectMapper.writeValueAsString(createFilmRequest)))
.andExpect(status().isNotFound())
.andDo(print())
.andDo(document("mariadb-create-a-film-no-table"));
Expand All @@ -95,7 +95,7 @@ void createDirectorWithTSIDEnabled() throws Exception {
mockMvc.perform(post(VERSION + "/mariadb/director")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.param("tsIdEnabled", "true")
.content(objectMapper.writeValueAsString(CREATE_DIRECTOR_REQUEST)))
.content(objectMapper.writeValueAsString(createDirectorRequest)))
//.andDo(print())
.andExpect(status().isCreated())
.andExpect(jsonPath("$.row", equalTo(1)))
Expand All @@ -110,7 +110,7 @@ void createDirectorWithTSIDOff() throws Exception {
mockMvc.perform(post(VERSION + "/mariadb/director")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.param("tsIdEnabled", "false")
.content(objectMapper.writeValueAsString(CREATE_DIRECTOR_REQUEST)))
.content(objectMapper.writeValueAsString(createDirectorRequest)))
.andExpect(status().isBadRequest())
//.andDo(print())
.andDo(document("mariadb-create-a-director-with-tsid-OFF"));
Expand All @@ -124,7 +124,7 @@ void createVanityVanWithVarcharTsIdType() throws Exception {
mockMvc.perform(post(VERSION + "/mariadb/vanity_van")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.param("tsIdEnabled", "true")
.content(objectMapper.writeValueAsString(CREATE_VANITY_VAN_REQUEST)))
.content(objectMapper.writeValueAsString(createVanityVanRequest)))
.andDo(print())
.andExpect(status().isCreated())
.andExpect(jsonPath("$.row", equalTo(1)))
Expand All @@ -139,7 +139,7 @@ void createFilmWithSubsetOfColumns() throws Exception {
var result = mockMvc.perform(post(VERSION + "/mariadb/film")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.queryParam("columns", "title,description,language_id")
.content(objectMapper.writeValueAsString(CREATE_FILM_REQUEST)))
.content(objectMapper.writeValueAsString(createFilmRequest)))
.andDo(print())
.andExpect(status().isCreated())
.andExpect(jsonPath("$.row", equalTo(1)))
Expand Down Expand Up @@ -171,7 +171,7 @@ void shouldIgnoreWhenColumnsQueryParamIsEmpty() throws Exception {
var result = mockMvc.perform(post(VERSION + "/mariadb/film")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.queryParam("columns", "")
.content(objectMapper.writeValueAsString(CREATE_FILM_REQUEST)))
.content(objectMapper.writeValueAsString(createFilmRequest)))
//.andDo(print())
.andExpect(status().isCreated())
.andExpect(jsonPath("$.row", equalTo(1)))
Expand Down Expand Up @@ -199,16 +199,14 @@ void shouldIgnoreWhenColumnsQueryParamIsEmpty() throws Exception {
@Test
@DisplayName("Column is present in columns param but not in payload")
void columnIsPresentInColumnsQueryParamButNotInPayload() throws Exception {

var result = mockMvc.perform(post(VERSION + "/mariadb/film")
mockMvc.perform(post(VERSION + "/mariadb/film")
.contentType(APPLICATION_JSON)
.accept(APPLICATION_JSON)
.queryParam("columns", "title,description,language_id")
.content(objectMapper.writeValueAsString(CREATE_FILM_REQUEST_MISSING_PAYLOAD))) //description is not in payload will be set to null
.content(objectMapper.writeValueAsString(createFilmRequestMissingPayload))) //description is not in payload will be set to null
.andExpect(status().isBadRequest())
//.andDo(print())
.andDo(document("mariadb-create-a-film-missing-payload-attribute-error"))
.andReturn();
.andDo(document("mariadb-create-a-film-missing-payload-attribute-error"));
}

@Test
Expand All @@ -217,7 +215,7 @@ void column_violates_not_null_constraint() throws Exception {
mockMvc.perform(post(VERSION + "/mariadb/film")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.queryParam("columns", "title,description")
.content(objectMapper.writeValueAsString(CREATE_FILM_REQUEST)))
.content(objectMapper.writeValueAsString(createFilmRequest)))
.andExpect(status().isBadRequest())
.andExpect(jsonPath("$.detail",
containsString("Field 'language_id' doesn't have a default value")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ class MariaDBCrossJoinControllerTest extends MariaDBBaseIntegrationTest {
.registerModule(new JavaTimeModule());

@GivenJsonResource("/testdata/CROSS_JOIN_USERS.json")
List<Map<String, Object>> CROSS_JOIN;
List<Map<String, Object>> crossJoin;

@GivenJsonResource("/testdata/CROSS_JOIN_TOPS.json")
List<Map<String, Object>> CROSS_JOIN_TOPS;
List<Map<String, Object>> crossJoinTops;

@Test
@DisplayName("Test cross Join - Users")
void testCrossJoin() throws Exception {
mockMvc.perform(post(VERSION + "/mariadb/users/_expand")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(CROSS_JOIN))
.content(objectMapper.writeValueAsString(crossJoin))
)
// .andDo(print())
.andExpect(status().isOk())
Expand All @@ -63,7 +63,7 @@ void testCrossJoin() throws Exception {
void testCrossJoinTops() throws Exception {
mockMvc.perform(post(VERSION + "/mariadb/tops/_expand")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(CROSS_JOIN_TOPS))
.content(objectMapper.writeValueAsString(crossJoinTops))
)
//.andDo(print())
.andExpect(status().isOk())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ class MariaDBInnerJoinControllerTest extends MariaDBBaseIntegrationTest {
.registerModule(new JavaTimeModule());

@GivenJsonResource("/testdata/INNER_JOIN.json")
List<Map<String, Object>> INNER_JOIN;
List<Map<String, Object>> innerJoin;

@Test
@DisplayName("Test inner Join")
void testInnerJoin() throws Exception {
mockMvc.perform(post(VERSION + "/mariadb/review/_expand")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(INNER_JOIN))
.content(objectMapper.writeValueAsString(innerJoin))
)
// .andDo(print())
.andExpect(status().isOk())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ class MariaDBInnerJoinMultiTableControllerTest extends MariaDBBaseIntegrationTes
.registerModule(new JavaTimeModule());

@GivenJsonResource("/testdata/INNER_JOIN_MULTI_TABLE.json")
List<Map<String, Object>> INNER_JOIN_MULTI_TABLE;
List<Map<String, Object>> innerJoinMultiTable;

@Test
@DisplayName("Test inner multi-table Join")
void testInnerMultiTable() throws Exception {
mockMvc.perform(post(VERSION + "/mariadb/film/_expand")
.contentType(APPLICATION_JSON).accept(APPLICATION_JSON)
.content(objectMapper.writeValueAsString(INNER_JOIN_MULTI_TABLE))
.content(objectMapper.writeValueAsString(innerJoinMultiTable))
)
//.andDo(print())
.andExpect(status().isOk())
Expand Down
Loading

0 comments on commit 2275b75

Please sign in to comment.