JAVA-34093: Fix spring-boot-persistance-2 junit-jupiter failures (#16497)
This commit is contained in:
parent
b17f9029a1
commit
a393395bf1
@ -7,11 +7,9 @@ import static org.junit.Assert.assertTrue;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
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.CarMakerDao;
|
||||||
import com.baeldung.boot.jdbi.dao.CarModelDao;
|
import com.baeldung.boot.jdbi.dao.CarModelDao;
|
||||||
@ -21,10 +19,9 @@ import com.baeldung.boot.jdbi.service.CarMakerService;
|
|||||||
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@SpringBootTest(classes = {SpringBootJdbiApplication.class, JdbiConfiguration.class})
|
@SpringBootTest(classes = {SpringBootJdbiApplication.class, JdbiConfiguration.class})
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class SpringBootJdbiApplicationIntegrationTest {
|
class SpringBootJdbiApplicationIntegrationTest {
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -37,7 +34,7 @@ public class SpringBootJdbiApplicationIntegrationTest {
|
|||||||
private CarMakerService carMakerService;
|
private CarMakerService carMakerService;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenNewCarMaker_whenInsertNewCarMaker_thenSuccess() {
|
void givenNewCarMaker_whenInsertNewCarMaker_thenSuccess() {
|
||||||
|
|
||||||
assertNotNull(carMakerDao);
|
assertNotNull(carMakerDao);
|
||||||
|
|
||||||
@ -51,7 +48,7 @@ public class SpringBootJdbiApplicationIntegrationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenNewCarMakers_whenInsertNewCarMakers_thenSuccess() {
|
void givenNewCarMakers_whenInsertNewCarMakers_thenSuccess() {
|
||||||
|
|
||||||
assertNotNull(carMakerDao);
|
assertNotNull(carMakerDao);
|
||||||
|
|
||||||
@ -74,7 +71,7 @@ public class SpringBootJdbiApplicationIntegrationTest {
|
|||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenExistingCarMaker_whenFindById_thenReturnExistingCarMaker() {
|
void givenExistingCarMaker_whenFindById_thenReturnExistingCarMaker() {
|
||||||
|
|
||||||
CarMaker maker = carMakerDao.findById(1L);
|
CarMaker maker = carMakerDao.findById(1L);
|
||||||
assertThat(maker).isNotNull();
|
assertThat(maker).isNotNull();
|
||||||
@ -83,7 +80,7 @@ public class SpringBootJdbiApplicationIntegrationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenExistingCarMaker_whenBulkInsertFails_thenRollback() {
|
void givenExistingCarMaker_whenBulkInsertFails_thenRollback() {
|
||||||
|
|
||||||
CarMaker maker = carMakerDao.findById(1L);
|
CarMaker maker = carMakerDao.findById(1L);
|
||||||
CarModel m1 = CarModel.builder()
|
CarModel m1 = CarModel.builder()
|
||||||
|
@ -4,23 +4,20 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@SpringBootTest(classes = {SpringOraclePoolingApplication.class})
|
@SpringBootTest(classes = {SpringOraclePoolingApplication.class})
|
||||||
@ActiveProfiles({"oracle-pooling-basic", "c3p0"})
|
@ActiveProfiles({"oracle-pooling-basic", "c3p0"})
|
||||||
public class SpringOraclePoolingApplicationC3P0LiveTest {
|
class SpringOraclePoolingApplicationC3P0LiveTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenC3p0Configuration_thenBuildsComboPooledDataSource() {
|
void givenC3p0Configuration_thenBuildsComboPooledDataSource() {
|
||||||
assertTrue(dataSource instanceof com.mchange.v2.c3p0.ComboPooledDataSource);
|
assertTrue(dataSource instanceof com.mchange.v2.c3p0.ComboPooledDataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,23 +4,20 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@SpringBootTest(classes = {SpringOraclePoolingApplication.class})
|
@SpringBootTest(classes = {SpringOraclePoolingApplication.class})
|
||||||
@ActiveProfiles("oracle-pooling-basic")
|
@ActiveProfiles("oracle-pooling-basic")
|
||||||
public class SpringOraclePoolingApplicationHikariCPLiveTest {
|
class SpringOraclePoolingApplicationHikariCPLiveTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenHikariCPConfiguration_thenBuildsHikariCP() {
|
void givenHikariCPConfiguration_thenBuildsHikariCP() {
|
||||||
assertTrue(dataSource instanceof com.zaxxer.hikari.HikariDataSource);
|
assertTrue(dataSource instanceof com.zaxxer.hikari.HikariDataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,23 +4,20 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@SpringBootTest(classes = {SpringOraclePoolingApplication.class})
|
@SpringBootTest(classes = {SpringOraclePoolingApplication.class})
|
||||||
@ActiveProfiles({"oracle-pooling-basic", "oracle"})
|
@ActiveProfiles({"oracle-pooling-basic", "oracle"})
|
||||||
public class SpringOraclePoolingApplicationOracleLiveTest {
|
class SpringOraclePoolingApplicationOracleLiveTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenOracleConfiguration_thenBuildsOracleDataSource() {
|
void givenOracleConfiguration_thenBuildsOracleDataSource() {
|
||||||
assertTrue(dataSource instanceof oracle.jdbc.pool.OracleDataSource);
|
assertTrue(dataSource instanceof oracle.jdbc.pool.OracleDataSource);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,15 +4,12 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
|
|||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.ActiveProfiles;
|
import org.springframework.test.context.ActiveProfiles;
|
||||||
import org.springframework.test.context.TestPropertySource;
|
import org.springframework.test.context.TestPropertySource;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@SpringBootTest(classes = {SpringOraclePoolingApplication.class})
|
@SpringBootTest(classes = {SpringOraclePoolingApplication.class})
|
||||||
@ActiveProfiles({"oracle-pooling-basic"})
|
@ActiveProfiles({"oracle-pooling-basic"})
|
||||||
@TestPropertySource(properties = "spring.datasource.type=oracle.ucp.jdbc.PoolDataSource")
|
@TestPropertySource(properties = "spring.datasource.type=oracle.ucp.jdbc.PoolDataSource")
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
package com.baeldung.springboothsqldb.application.tests;
|
package com.baeldung.springboothsqldb.application.tests;
|
||||||
|
|
||||||
import com.baeldung.springboothsqldb.application.entities.Customer;
|
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import com.fasterxml.jackson.databind.ObjectWriter;
|
import org.junit.jupiter.api.Test;
|
||||||
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.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
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.request.MockMvcRequestBuilders;
|
||||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
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
|
@SpringBootTest
|
||||||
@AutoConfigureMockMvc
|
@AutoConfigureMockMvc
|
||||||
public class CustomerControllerIntegrationTest {
|
class CustomerControllerIntegrationTest {
|
||||||
|
|
||||||
private static MediaType MEDIA_TYPE_JSON;
|
private static MediaType MEDIA_TYPE_JSON;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private MockMvc mockMvc;
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void setUpJsonMediaType() {
|
void setUpJsonMediaType() {
|
||||||
MEDIA_TYPE_JSON = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype());
|
MEDIA_TYPE_JSON = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenPostHttpRequesttoCustomers_thenStatusOK() throws Exception {
|
void whenPostHttpRequesttoCustomers_thenStatusOK() throws Exception {
|
||||||
Customer customer = new Customer("John", "john@domain.com");
|
Customer customer = new Customer("John", "john@domain.com");
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
|
mapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
|
||||||
@ -50,7 +49,7 @@ public class CustomerControllerIntegrationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenGetHttpRequesttoCustomers_thenStatusOK() throws Exception {
|
void whenGetHttpRequesttoCustomers_thenStatusOK() throws Exception {
|
||||||
this.mockMvc
|
this.mockMvc
|
||||||
.perform(MockMvcRequestBuilders.get("/customers"))
|
.perform(MockMvcRequestBuilders.get("/customers"))
|
||||||
|
|
||||||
|
@ -1,20 +1,17 @@
|
|||||||
package com.baeldung.states;
|
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.Session;
|
||||||
import org.hibernate.SessionFactory;
|
import org.hibernate.SessionFactory;
|
||||||
import org.hibernate.Transaction;
|
import org.hibernate.Transaction;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
import jakarta.persistence.EntityManagerFactory;
|
import jakarta.persistence.EntityManagerFactory;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
||||||
|
|
||||||
@RunWith(SpringRunner.class)
|
|
||||||
@SpringBootTest
|
@SpringBootTest
|
||||||
class UserEntityIntegrationTest {
|
class UserEntityIntegrationTest {
|
||||||
@Autowired
|
@Autowired
|
||||||
|
@ -1,27 +1,25 @@
|
|||||||
package com.baeldung.tomcatconnectionpool.test.application;
|
package com.baeldung.tomcatconnectionpool.test.application;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
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.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
import org.springframework.test.context.TestPropertySource;
|
import org.springframework.test.context.TestPropertySource;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
|
||||||
|
|
||||||
import com.baeldung.tomcatconnectionpool.application.SpringBootConsoleApplication;
|
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})
|
@SpringBootTest(classes = {SpringBootConsoleApplication.class})
|
||||||
@TestPropertySource(properties = "spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource")
|
@TestPropertySource(properties = "spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource")
|
||||||
public class SpringBootTomcatConnectionPoolIntegrationTest {
|
class SpringBootTomcatConnectionPoolIntegrationTest {
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private DataSource dataSource;
|
private DataSource dataSource;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenTomcatConnectionPoolInstance_whenCheckedPoolClassName_thenCorrect() {
|
void givenTomcatConnectionPoolInstance_whenCheckedPoolClassName_thenCorrect() {
|
||||||
assertThat(dataSource.getClass().getName()).isEqualTo("org.apache.tomcat.jdbc.pool.DataSource");
|
assertThat(dataSource.getClass().getName()).isEqualTo("org.apache.tomcat.jdbc.pool.DataSource");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user