JAVA-34093: Fix spring-boot-persistance-2 junit-jupiter failures (#16497)

This commit is contained in:
Harry9656 2024-04-27 00:37:22 +02:00 committed by GitHub
parent b17f9029a1
commit a393395bf1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 43 additions and 64 deletions

View File

@ -7,11 +7,9 @@ import static org.junit.Assert.assertTrue;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.boot.jdbi.dao.CarMakerDao;
import com.baeldung.boot.jdbi.dao.CarModelDao;
@ -21,10 +19,9 @@ import com.baeldung.boot.jdbi.service.CarMakerService;
import lombok.extern.slf4j.Slf4j;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {SpringBootJdbiApplication.class, JdbiConfiguration.class})
@Slf4j
public class SpringBootJdbiApplicationIntegrationTest {
class SpringBootJdbiApplicationIntegrationTest {
@Autowired
@ -37,7 +34,7 @@ public class SpringBootJdbiApplicationIntegrationTest {
private CarMakerService carMakerService;
@Test
public void givenNewCarMaker_whenInsertNewCarMaker_thenSuccess() {
void givenNewCarMaker_whenInsertNewCarMaker_thenSuccess() {
assertNotNull(carMakerDao);
@ -51,7 +48,7 @@ public class SpringBootJdbiApplicationIntegrationTest {
}
@Test
public void givenNewCarMakers_whenInsertNewCarMakers_thenSuccess() {
void givenNewCarMakers_whenInsertNewCarMakers_thenSuccess() {
assertNotNull(carMakerDao);
@ -74,7 +71,7 @@ public class SpringBootJdbiApplicationIntegrationTest {
@Test
public void givenExistingCarMaker_whenFindById_thenReturnExistingCarMaker() {
void givenExistingCarMaker_whenFindById_thenReturnExistingCarMaker() {
CarMaker maker = carMakerDao.findById(1L);
assertThat(maker).isNotNull();
@ -83,7 +80,7 @@ public class SpringBootJdbiApplicationIntegrationTest {
}
@Test
public void givenExistingCarMaker_whenBulkInsertFails_thenRollback() {
void givenExistingCarMaker_whenBulkInsertFails_thenRollback() {
CarMaker maker = carMakerDao.findById(1L);
CarModel m1 = CarModel.builder()

View File

@ -4,23 +4,20 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import javax.sql.DataSource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {SpringOraclePoolingApplication.class})
@ActiveProfiles({"oracle-pooling-basic", "c3p0"})
public class SpringOraclePoolingApplicationC3P0LiveTest {
class SpringOraclePoolingApplicationC3P0LiveTest {
@Autowired
private DataSource dataSource;
@Test
public void givenC3p0Configuration_thenBuildsComboPooledDataSource() {
@Test
void givenC3p0Configuration_thenBuildsComboPooledDataSource() {
assertTrue(dataSource instanceof com.mchange.v2.c3p0.ComboPooledDataSource);
}

View File

@ -4,23 +4,20 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import javax.sql.DataSource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {SpringOraclePoolingApplication.class})
@ActiveProfiles("oracle-pooling-basic")
public class SpringOraclePoolingApplicationHikariCPLiveTest {
class SpringOraclePoolingApplicationHikariCPLiveTest {
@Autowired
private DataSource dataSource;
@Test
public void givenHikariCPConfiguration_thenBuildsHikariCP() {
@Test
void givenHikariCPConfiguration_thenBuildsHikariCP() {
assertTrue(dataSource instanceof com.zaxxer.hikari.HikariDataSource);
}

View File

@ -4,23 +4,20 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import javax.sql.DataSource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {SpringOraclePoolingApplication.class})
@ActiveProfiles({"oracle-pooling-basic", "oracle"})
public class SpringOraclePoolingApplicationOracleLiveTest {
class SpringOraclePoolingApplicationOracleLiveTest {
@Autowired
private DataSource dataSource;
@Test
public void givenOracleConfiguration_thenBuildsOracleDataSource() {
@Test
void givenOracleConfiguration_thenBuildsOracleDataSource() {
assertTrue(dataSource instanceof oracle.jdbc.pool.OracleDataSource);
}

View File

@ -4,15 +4,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import javax.sql.DataSource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {SpringOraclePoolingApplication.class})
@ActiveProfiles({"oracle-pooling-basic"})
@TestPropertySource(properties = "spring.datasource.type=oracle.ucp.jdbc.PoolDataSource")
@ -21,7 +18,7 @@ public class SpringOraclePoolingApplicationOracleUCPLiveTest {
@Autowired
private DataSource dataSource;
@Test
@Test
public void givenOracleUCPConfiguration_thenBuildsOraclePoolDataSource() {
assertTrue(dataSource instanceof oracle.ucp.jdbc.PoolDataSource);
}

View File

@ -1,13 +1,8 @@
package com.baeldung.springboothsqldb.application.tests;
import com.baeldung.springboothsqldb.application.entities.Customer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.SerializationFeature;
import java.nio.charset.Charset;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
@ -17,23 +12,27 @@ import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
@RunWith(SpringRunner.class)
import com.baeldung.springboothsqldb.application.entities.Customer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.SerializationFeature;
@SpringBootTest
@AutoConfigureMockMvc
public class CustomerControllerIntegrationTest {
class CustomerControllerIntegrationTest {
private static MediaType MEDIA_TYPE_JSON;
@Autowired
private MockMvc mockMvc;
@Before
public void setUpJsonMediaType() {
@BeforeEach
void setUpJsonMediaType() {
MEDIA_TYPE_JSON = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype());
}
@Test
public void whenPostHttpRequesttoCustomers_thenStatusOK() throws Exception {
void whenPostHttpRequesttoCustomers_thenStatusOK() throws Exception {
Customer customer = new Customer("John", "john@domain.com");
ObjectMapper mapper = new ObjectMapper();
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
@ -50,7 +49,7 @@ public class CustomerControllerIntegrationTest {
}
@Test
public void whenGetHttpRequesttoCustomers_thenStatusOK() throws Exception {
void whenGetHttpRequesttoCustomers_thenStatusOK() throws Exception {
this.mockMvc
.perform(MockMvcRequestBuilders.get("/customers"))

View File

@ -1,20 +1,17 @@
package com.baeldung.states;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import jakarta.persistence.EntityManagerFactory;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
@RunWith(SpringRunner.class)
@SpringBootTest
class UserEntityIntegrationTest {
@Autowired

View File

@ -1,27 +1,25 @@
package com.baeldung.tomcatconnectionpool.test.application;
import static org.assertj.core.api.Assertions.assertThat;
import javax.sql.DataSource;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.tomcatconnectionpool.application.SpringBootConsoleApplication;
import static org.assertj.core.api.Assertions.*;
import org.springframework.boot.test.context.SpringBootTest;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = {SpringBootConsoleApplication.class})
@TestPropertySource(properties = "spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource")
public class SpringBootTomcatConnectionPoolIntegrationTest {
class SpringBootTomcatConnectionPoolIntegrationTest {
@Autowired
private DataSource dataSource;
@Test
public void givenTomcatConnectionPoolInstance_whenCheckedPoolClassName_thenCorrect() {
void givenTomcatConnectionPoolInstance_whenCheckedPoolClassName_thenCorrect() {
assertThat(dataSource.getClass().getName()).isEqualTo("org.apache.tomcat.jdbc.pool.DataSource");
}
}