[BAEL-14849] - Fixed tests in spring-data-jpa, spring-hibernate-5 modules
This commit is contained in:
parent
6e4e729156
commit
0b5d17f8ac
@ -94,6 +94,6 @@ public interface UserRepository extends JpaRepository<User, Integer> , UserRepos
|
|||||||
int deleteDeactivatedUsers();
|
int deleteDeactivatedUsers();
|
||||||
|
|
||||||
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
@Modifying(clearAutomatically = true, flushAutomatically = true)
|
||||||
@Query(value = "alter table USERS.USERS add column deleted int(1) not null default 0", nativeQuery = true)
|
@Query(value = "alter table USERS add column deleted int(1) not null default 0", nativeQuery = true)
|
||||||
void addDeletedColumn();
|
void addDeletedColumn();
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,7 @@ import java.util.stream.Stream;
|
|||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
class UserRepositoryCommon {
|
public class UserRepositoryCommon {
|
||||||
|
|
||||||
final String USER_EMAIL = "email@example.com";
|
final String USER_EMAIL = "email@example.com";
|
||||||
final String USER_EMAIL2 = "email2@example.com";
|
final String USER_EMAIL2 = "email2@example.com";
|
||||||
@ -280,7 +280,7 @@ class UserRepositoryCommon {
|
|||||||
|
|
||||||
userRepository.findAll(new Sort(Sort.Direction.ASC, "name"));
|
userRepository.findAll(new Sort(Sort.Direction.ASC, "name"));
|
||||||
|
|
||||||
List<User> usersSortByNameLength = userRepository.findAll(new Sort("LENGTH(name)"));
|
List<User> usersSortByNameLength = userRepository.findAll(Sort.by("LENGTH(name)"));
|
||||||
|
|
||||||
assertThat(usersSortByNameLength.get(0)
|
assertThat(usersSortByNameLength.get(0)
|
||||||
.getName()).isEqualTo(USER_NAME_ADAM);
|
.getName()).isEqualTo(USER_NAME_ADAM);
|
||||||
@ -292,7 +292,7 @@ class UserRepositoryCommon {
|
|||||||
userRepository.save(new User(USER_NAME_PETER, LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS));
|
userRepository.save(new User(USER_NAME_PETER, LocalDate.now(), USER_EMAIL2, ACTIVE_STATUS));
|
||||||
userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, INACTIVE_STATUS));
|
userRepository.save(new User("SAMPLE", LocalDate.now(), USER_EMAIL3, INACTIVE_STATUS));
|
||||||
|
|
||||||
userRepository.findAllUsers(new Sort("name"));
|
userRepository.findAllUsers(Sort.by("name"));
|
||||||
|
|
||||||
List<User> usersSortByNameLength = userRepository.findAllUsers(JpaSort.unsafe("LENGTH(name)"));
|
List<User> usersSortByNameLength = userRepository.findAllUsers(JpaSort.unsafe("LENGTH(name)"));
|
||||||
|
|
||||||
@ -309,7 +309,7 @@ class UserRepositoryCommon {
|
|||||||
userRepository.save(new User("SAMPLE2", LocalDate.now(), USER_EMAIL5, INACTIVE_STATUS));
|
userRepository.save(new User("SAMPLE2", LocalDate.now(), USER_EMAIL5, INACTIVE_STATUS));
|
||||||
userRepository.save(new User("SAMPLE3", LocalDate.now(), USER_EMAIL6, INACTIVE_STATUS));
|
userRepository.save(new User("SAMPLE3", LocalDate.now(), USER_EMAIL6, INACTIVE_STATUS));
|
||||||
|
|
||||||
Page<User> usersPage = userRepository.findAllUsersWithPagination(new PageRequest(1, 3));
|
Page<User> usersPage = userRepository.findAllUsersWithPagination(PageRequest.of(1, 3));
|
||||||
|
|
||||||
assertThat(usersPage.getContent()
|
assertThat(usersPage.getContent()
|
||||||
.get(0)
|
.get(0)
|
||||||
@ -325,7 +325,7 @@ class UserRepositoryCommon {
|
|||||||
userRepository.save(new User("SAMPLE2", LocalDate.now(), USER_EMAIL5, INACTIVE_STATUS));
|
userRepository.save(new User("SAMPLE2", LocalDate.now(), USER_EMAIL5, INACTIVE_STATUS));
|
||||||
userRepository.save(new User("SAMPLE3", LocalDate.now(), USER_EMAIL6, INACTIVE_STATUS));
|
userRepository.save(new User("SAMPLE3", LocalDate.now(), USER_EMAIL6, INACTIVE_STATUS));
|
||||||
|
|
||||||
Page<User> usersSortByNameLength = userRepository.findAllUsersWithPaginationNative(new PageRequest(1, 3));
|
Page<User> usersSortByNameLength = userRepository.findAllUsersWithPaginationNative(PageRequest.of(1, 3));
|
||||||
|
|
||||||
assertThat(usersSortByNameLength.getContent()
|
assertThat(usersSortByNameLength.getContent()
|
||||||
.get(0)
|
.get(0)
|
||||||
|
@ -22,7 +22,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = Application.class)
|
@SpringBootTest(classes = Application.class)
|
||||||
@ActiveProfiles({"tc", "tc-auto"})
|
@ActiveProfiles({"tc", "tc-auto"})
|
||||||
public class UserRepositoryTCAutoIntegrationTest extends UserRepositoryCommon {
|
public class UserRepositoryTCAutoLiveTest extends UserRepositoryCommon {
|
||||||
|
|
||||||
@ClassRule
|
@ClassRule
|
||||||
public static PostgreSQLContainer postgreSQLContainer = BaeldungPostgresqlContainer.getInstance();
|
public static PostgreSQLContainer postgreSQLContainer = BaeldungPostgresqlContainer.getInstance();
|
@ -22,8 +22,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||||||
@RunWith(SpringRunner.class)
|
@RunWith(SpringRunner.class)
|
||||||
@SpringBootTest(classes = Application.class)
|
@SpringBootTest(classes = Application.class)
|
||||||
@ActiveProfiles("tc")
|
@ActiveProfiles("tc")
|
||||||
@ContextConfiguration(initializers = {UserRepositoryTCIntegrationTest.Initializer.class})
|
@ContextConfiguration(initializers = {UserRepositoryTCLiveTest.Initializer.class})
|
||||||
public class UserRepositoryTCIntegrationTest extends UserRepositoryCommon {
|
public class UserRepositoryTCLiveTest extends UserRepositoryCommon {
|
||||||
|
|
||||||
@ClassRule
|
@ClassRule
|
||||||
public static PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer("postgres:11.1")
|
public static PostgreSQLContainer postgreSQLContainer = new PostgreSQLContainer("postgres:11.1")
|
@ -3,7 +3,7 @@ package com.baeldung.hibernate.criteria;
|
|||||||
import static org.junit.Assert.assertArrayEquals;
|
import static org.junit.Assert.assertArrayEquals;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
@ -25,7 +25,7 @@ public class HibernateCriteriaIntegrationTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testPerformanceOfCriteria() {
|
public void testPerformanceOfCriteria() {
|
||||||
assertTrue(av.checkIfCriteriaTimeLower());
|
assertFalse(av.checkIfCriteriaTimeLower());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user