Merge branch 'master' into master

This commit is contained in:
Loredana Crusoveanu
2024-04-27 14:05:55 +03:00
committed by GitHub
162 changed files with 4745 additions and 504 deletions
@@ -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()
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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);
}
@@ -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", "[email protected]");
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"))
@@ -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
@@ -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");
}
}
@@ -8,5 +8,5 @@
- [Differences Between Spring Data JPA findFirst() and findTop()](https://www.baeldung.com/spring-data-jpa-findfirst-vs-findtop)
- [Difference Between findBy and findAllBy in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-find-by-vs-find-all-by)
- [Calling Stored Procedures from Spring Data JPA Repositories](https://www.baeldung.com/spring-data-jpa-stored-procedures)
- [Generate Database Schema with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-generate-db-schema)
- More articles: [[<-- prev]](../spring-data-jpa-repo)
@@ -58,10 +58,6 @@
<version>${querydsl.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-ant</artifactId>
</dependency>
</dependencies>
<build>
@@ -9,5 +9,4 @@ This module contains articles about Spring Data JPA.
- [Difference Between findBy and findOneBy in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-findby-vs-findoneby)
- [How to Get Last Record in Spring Data JPA](https://www.baeldung.com/spring-data-jpa-last-record)
- [Refresh and Fetch an Entity After Save in JPA](https://www.baeldung.com/spring-data-jpa-refresh-fetch-entity-after-save)
- [Pagination and Sorting using Spring Data JPA](https://www.baeldung.com/spring-data-jpa-pagination-sorting)
- More articles: [[<-- prev]](../spring-data-jpa-repo-2)
@@ -32,11 +32,6 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
</dependencies>
<properties>
<start-class>com.baeldung.spring.data.jpa.naturalid.Application</start-class>
@@ -3,7 +3,6 @@
This module contains articles about repositories in Spring Data JPA
### Relevant Articles:
- [Introduction to Spring Data JPA](https://www.baeldung.com/the-persistence-layer-with-spring-data-jpa)
- [Case Insensitive Queries with Spring Data Repository](https://www.baeldung.com/spring-data-case-insensitive-queries)
- [Spring Data – CrudRepository save() Method](https://www.baeldung.com/spring-data-crud-repository-save)
- [Spring Data JPA – Adding a Method in All Repositories](https://www.baeldung.com/spring-data-jpa-method-in-all-repositories)
@@ -1,7 +0,0 @@
package com.baeldung.simple.service;
import com.baeldung.simple.entity.Foo;
public interface IFooService {
Foo create(Foo foo);
}
@@ -8,10 +8,13 @@ This module contains articles about Spring Data JPA that are also part of an Ebo
Since this is a module tied to an e-book, it should **not** be moved or used to store the code for any further article.
### Relevant Articles
- [Introduction to Spring Data JPA](https://www.baeldung.com/the-persistence-layer-with-spring-data-jpa)
- [Customizing the Result of JPA Queries with Aggregation Functions](https://www.baeldung.com/jpa-queries-custom-result-with-aggregation-functions)
- [CrudRepository, JpaRepository, and PagingAndSortingRepository in Spring Data](https://www.baeldung.com/spring-data-repositories)
- [New CRUD Repository Interfaces in Spring Data 3](https://www.baeldung.com/spring-data-3-crud-repository-interfaces)
- [Derived Query Methods in Spring Data JPA Repositories](https://www.baeldung.com/spring-data-derived-queries)
- [Spring Data JPA @Query](https://www.baeldung.com/spring-data-jpa-query)
- [Spring Data JPA Projections](https://www.baeldung.com/spring-data-jpa-projections)
- [Spring Data JPA @Modifying Annotation](https://www.baeldung.com/spring-data-jpa-modifying-annotation)
- [Spring Data JPA @Modifying Annotation](https://www.baeldung.com/spring-data-jpa-modifying-annotation)
- [Generate Database Schema with Spring Data JPA](https://www.baeldung.com/spring-data-jpa-generate-db-schema)
- [Pagination and Sorting using Spring Data JPA](https://www.baeldung.com/spring-data-jpa-pagination-sorting)
@@ -43,11 +43,21 @@
<groupId>org.springframework</groupId>
<artifactId>spring-oxm</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>${jakarta.xml.bind.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-ant</artifactId>
<version>${hibernate.version}</version>
</dependency>
</dependencies>
<properties>
@@ -1,11 +1,11 @@
package com.baeldung.simple;
package com.baeldung.jpa.simple;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
@SpringBootApplication
@EnableJpaRepositories("com.baeldung.simple.repository")
@EnableJpaRepositories("com.baeldung.jpa.simple.repository")
public class JpaApplication {
public static void main(String[] args) {
@@ -1,4 +1,4 @@
package com.baeldung.simple.config;
package com.baeldung.jpa.simple.config;
import java.util.Properties;
@@ -32,7 +32,7 @@ public class PersistenceConfig {
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
final LocalContainerEntityManagerFactoryBean em = new LocalContainerEntityManagerFactoryBean();
em.setDataSource(dataSource());
em.setPackagesToScan("com.baeldung.simple.entity");
em.setPackagesToScan("com.baeldung.jpa.simple.model");
final HibernateJpaVendorAdapter vendorAdapter = new HibernateJpaVendorAdapter();
em.setJpaVendorAdapter(vendorAdapter);
@@ -1,4 +1,4 @@
package com.baeldung.simple.entity;
package com.baeldung.jpa.simple.model;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
@@ -1,4 +1,4 @@
package com.baeldung.simple.entity;
package com.baeldung.jpa.simple.model;
import java.io.Serializable;

Some files were not shown because too many files have changed in this diff Show More