Polishing.
Add `@author` tags to changed files. Remove Hamcrest usage. Original pull request #602 Related tickest #583
This commit is contained in:
@@ -29,6 +29,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
* Integration test for {@link CustomerRepository}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Divya Srivastava
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest
|
||||
|
||||
@@ -15,10 +15,6 @@
|
||||
*/
|
||||
package example.springdata.jpa.auditing;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.notNullValue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -28,9 +24,13 @@ import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
* @author Divya Srivastava
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@Transactional
|
||||
@@ -44,7 +44,7 @@ public class AuditableUserSample {
|
||||
@Test
|
||||
public void auditEntityCreation() throws Exception {
|
||||
|
||||
assertThat(ReflectionTestUtils.getField(listener, "handler"),is(notNullValue()));
|
||||
assertThat(ReflectionTestUtils.getField(listener, "handler")).isNotNull();
|
||||
|
||||
AuditableUser user = new AuditableUser();
|
||||
user.setUsername("username");
|
||||
@@ -54,7 +54,7 @@ public class AuditableUserSample {
|
||||
user = repository.save(user);
|
||||
user = repository.save(user);
|
||||
|
||||
assertThat(user.getCreatedBy(), is(user));
|
||||
assertThat(user.getLastModifiedBy(), is(user));
|
||||
assertThat(user.getCreatedBy()).isEqualTo(user);
|
||||
assertThat(user.getLastModifiedBy()).isEqualTo(user);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
|
||||
* Test case showing how to use the basic {@link GenericDaoFactory}
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Divya Srivastava
|
||||
*/
|
||||
public class BasicFactorySetup {
|
||||
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.springframework.data.repository.CrudRepository;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
* @author Divya Srivastava
|
||||
*/
|
||||
public class BasicSample {
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
* @author Andrea Rizzini
|
||||
* @author Divya Srivastava
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@Transactional
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* Integration test showing the usage of a composite repository via {@link UserRepository}.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Divya Srivastava
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@Transactional
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
* @author Divya Srivastava
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@Transactional
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* Intergration test showing the usage of a custom method implemented for all repositories
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Divya Srivastava
|
||||
* @soundtrack Elen - It's you (Elen)
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
|
||||
@@ -39,6 +39,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* Integration tests for {@link CustomerRepository} to show projection capabilities.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Divya Srivastava
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest
|
||||
|
||||
@@ -16,10 +16,6 @@
|
||||
package example.springdata.jpa.simple;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.Matchers.hasItems;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.iterableWithSize;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.springframework.data.domain.Sort.Direction.ASC;
|
||||
import static org.springframework.data.domain.Sort.Direction.DESC;
|
||||
|
||||
@@ -45,6 +41,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
* @author Christoph Strobl
|
||||
* @author Divya Srivastava
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@Transactional
|
||||
@@ -155,8 +153,7 @@ public class SimpleUserRepositoryTests {
|
||||
|
||||
List<User> result = repository.findFirst2ByOrderByLastnameAsc();
|
||||
|
||||
assertThat(result.size(), is(2));
|
||||
assertThat(result, hasItems(user0, user1));
|
||||
assertThat(result).containsExactly(user0, user1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -176,13 +173,11 @@ public class SimpleUserRepositoryTests {
|
||||
|
||||
List<User> resultAsc = repository.findTop2By(Sort.by(ASC, "lastname"));
|
||||
|
||||
assertThat(resultAsc.size(), is(2));
|
||||
assertThat(resultAsc, hasItems(user0, user1));
|
||||
assertThat(resultAsc).containsExactly(user0, user1);
|
||||
|
||||
List<User> resultDesc = repository.findTop2By(Sort.by(DESC, "lastname"));
|
||||
|
||||
assertThat(resultDesc.size(), is(2));
|
||||
assertThat(resultDesc, hasItems(user1, user2));
|
||||
assertThat(resultDesc).containsExactly(user2, user1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -204,7 +199,6 @@ public class SimpleUserRepositoryTests {
|
||||
|
||||
Iterable<User> users = repository.findByFirstnameOrLastname(reference);
|
||||
|
||||
assertThat(users, is(iterableWithSize(2)));
|
||||
assertThat(users, hasItems(first, second));
|
||||
assertThat(users).containsExactly(first, second);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,6 +21,10 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
/**
|
||||
* @author Oliver Drotbohm
|
||||
* @author Divya Srivastava
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest
|
||||
public class InterceptorIntegrationTest {
|
||||
|
||||
@@ -40,6 +40,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
* @author Divya Srivastava
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
*
|
||||
* @author Thomas Darimont
|
||||
* @author Jens Schauder
|
||||
* @author Divya Srivastava
|
||||
*/
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* @author Thomas Darimont
|
||||
* @author Divya Srivastava
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@DataJpaTest
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package example.springdata.jpa.storedprocedures;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.ParameterMode;
|
||||
import javax.persistence.StoredProcedureQuery;
|
||||
@@ -29,11 +26,15 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Integration test showing the usage of JPA 2.1 stored procedures support through Spring Data repositories.
|
||||
*
|
||||
* @author Thomas Darimont
|
||||
* @author Oliver Gierke
|
||||
* @author Divya Srivastava
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest
|
||||
@@ -47,7 +48,7 @@ public class UserRepositoryIntegrationTests {
|
||||
*/
|
||||
@Test
|
||||
public void entityAnnotatedCustomNamedProcedurePlus1IO() {
|
||||
assertThat(repository.plus1BackedByOtherNamedStoredProcedure(1), is(2));
|
||||
assertThat(repository.plus1BackedByOtherNamedStoredProcedure(1)).isEqualTo(2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -55,7 +56,7 @@ public class UserRepositoryIntegrationTests {
|
||||
*/
|
||||
@Test
|
||||
public void invokeDerivedStoredProcedure() {
|
||||
assertThat(repository.plus1inout(1), is(2));
|
||||
assertThat(repository.plus1inout(1)).isEqualTo(2);
|
||||
}
|
||||
|
||||
// This is what it would look like implemented manually.
|
||||
@@ -72,7 +73,7 @@ public class UserRepositoryIntegrationTests {
|
||||
proc.setParameter(1, 1);
|
||||
proc.execute();
|
||||
|
||||
assertThat(proc.getOutputParameterValue(2), is((Object) 2));
|
||||
assertThat(proc.getOutputParameterValue(2)).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,6 +84,6 @@ public class UserRepositoryIntegrationTests {
|
||||
proc.setParameter("arg", 1);
|
||||
proc.execute();
|
||||
|
||||
assertThat(proc.getOutputParameterValue("res"), is((Object) 2));
|
||||
assertThat(proc.getOutputParameterValue("res")).isEqualTo(2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,6 @@
|
||||
</parent>
|
||||
|
||||
<artifactId>spring-data-jpa-multiple-datasources</artifactId>
|
||||
<name>Spring Data JPA - Multple datasources</name>
|
||||
<name>Spring Data JPA - Multiple datasources</name>
|
||||
|
||||
</project>
|
||||
@@ -15,10 +15,6 @@
|
||||
*/
|
||||
package example.springdata.jpa.multipleds.customer;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.CoreMatchers.not;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import javax.persistence.EntityManager;
|
||||
@@ -31,10 +27,14 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Integration test for {@link CustomerRepository}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Divya Srivastava
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest
|
||||
@@ -49,7 +49,7 @@ public class CustomerRepositoryTests {
|
||||
|
||||
Optional<Customer> result = repository.findByLastname("Matthews");
|
||||
|
||||
assertThat(result, is(not(Optional.empty())));
|
||||
assertThat(result.get().getFirstname(), is("Dave"));
|
||||
assertThat(result).isNotEmpty();
|
||||
assertThat(result.get().getFirstname()).isEqualTo("Dave");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,9 @@
|
||||
*/
|
||||
package example.springdata.jpa.multipleds.order;
|
||||
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import example.springdata.jpa.multipleds.customer.CustomerRepository;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -25,12 +26,12 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import example.springdata.jpa.multipleds.customer.CustomerRepository;
|
||||
|
||||
/**
|
||||
* Integration test for {@link CustomerRepository}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Divya Srivastava
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest
|
||||
@@ -44,7 +45,7 @@ public class OrderRepositoryTests {
|
||||
public void persistsAndFindsCustomer() {
|
||||
|
||||
customers.findAll().forEach(customer -> {
|
||||
assertThat(orders.findByCustomer(customer.getId()), hasSize(1));
|
||||
assertThat(orders.findByCustomer(customer.getId())).hasSize(1);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package example.springdata.jpa.querybyexample;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
@@ -27,12 +24,16 @@ import org.springframework.data.domain.Example;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
/**
|
||||
* Integration test showing the usage of JPA Query-by-Example support through Spring Data repositories and entities
|
||||
* using inheritance.
|
||||
*
|
||||
* @author Mark Paluch
|
||||
* @author Oliver Gierke
|
||||
* @author Divya Srivastava
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@Transactional
|
||||
@@ -58,7 +59,7 @@ public class UserRepositoryInheritanceIntegrationTests {
|
||||
*/
|
||||
@Test
|
||||
public void countByExample() {
|
||||
assertThat(repository.count(Example.of(new User(null, "White", null))), is(3L));
|
||||
assertThat(repository.count(Example.of(new User(null, "White", null)))).isEqualTo(3L);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -66,6 +67,6 @@ public class UserRepositoryInheritanceIntegrationTests {
|
||||
*/
|
||||
@Test
|
||||
public void countSubtypesByExample() {
|
||||
assertThat(repository.count(Example.of(new SpecialUser(null, "White", null))), is(2L));
|
||||
assertThat(repository.count(Example.of(new SpecialUser(null, "White", null)))).isEqualTo(2L);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* @author Mark Paluch
|
||||
* @author Oliver Gierke
|
||||
* @author Jens Schauder
|
||||
* @author Divya Srivastava
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@Transactional
|
||||
|
||||
@@ -16,11 +16,7 @@
|
||||
package example.springdata.jpa.security;
|
||||
|
||||
import static java.util.Collections.singleton;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -40,6 +36,8 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Thomas Darimont
|
||||
* @author Divya Srivastava
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@SpringBootTest
|
||||
@@ -78,15 +76,13 @@ public class SecurityIntegrationTests {
|
||||
|
||||
List<BusinessObject> businessObjects = secureBusinessObjectRepository.findBusinessObjectsForCurrentUser();
|
||||
|
||||
assertThat(businessObjects, hasSize(1));
|
||||
assertThat(businessObjects, contains(object3));
|
||||
assertThat(businessObjects).containsExactly(object3);
|
||||
|
||||
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(ollie, "x"));
|
||||
|
||||
businessObjects = secureBusinessObjectRepository.findBusinessObjectsForCurrentUser();
|
||||
|
||||
assertThat(businessObjects, hasSize(2));
|
||||
assertThat(businessObjects, contains(object1, object2));
|
||||
assertThat(businessObjects).containsExactly(object1, object2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,8 +92,7 @@ public class SecurityIntegrationTests {
|
||||
|
||||
List<BusinessObject> businessObjects = secureBusinessObjectRepository.findBusinessObjectsForCurrentUser();
|
||||
|
||||
assertThat(businessObjects, hasSize(3));
|
||||
assertThat(businessObjects, contains(object1, object2, object3));
|
||||
assertThat(businessObjects).containsExactly(object1, object2, object3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -107,15 +102,13 @@ public class SecurityIntegrationTests {
|
||||
|
||||
List<BusinessObject> businessObjects = secureBusinessObjectRepository.findBusinessObjectsForCurrentUserById();
|
||||
|
||||
assertThat(businessObjects, hasSize(1));
|
||||
assertThat(businessObjects, contains(object3));
|
||||
assertThat(businessObjects).containsExactly(object3);
|
||||
|
||||
SecurityContextHolder.getContext().setAuthentication(olliAuth);
|
||||
|
||||
businessObjects = secureBusinessObjectRepository.findBusinessObjectsForCurrentUserById();
|
||||
|
||||
assertThat(businessObjects, hasSize(2));
|
||||
assertThat(businessObjects, contains(object1, object2));
|
||||
assertThat(businessObjects).containsExactly(object1, object2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -125,8 +118,7 @@ public class SecurityIntegrationTests {
|
||||
|
||||
List<BusinessObject> businessObjects = secureBusinessObjectRepository.findBusinessObjectsForCurrentUserById();
|
||||
|
||||
assertThat(businessObjects, hasSize(3));
|
||||
assertThat(businessObjects, contains(object1, object2, object3));
|
||||
assertThat(businessObjects).containsExactly(object1, object2, object3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -138,8 +130,8 @@ public class SecurityIntegrationTests {
|
||||
|
||||
for (BusinessObject bo : businessObjectRepository.findAll()) {
|
||||
|
||||
assertThat(bo.getLastModifiedDate(), is(notNullValue()));
|
||||
assertThat(bo.getLastModifiedBy().getFirstname(), is("admin"));
|
||||
assertThat(bo.getLastModifiedDate()).isNotNull();
|
||||
assertThat(bo.getLastModifiedBy().getFirstname()).isEqualTo("admin");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
/**
|
||||
*
|
||||
/*
|
||||
* Copyright 2020-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package example.springdata.jpa.showcase;
|
||||
|
||||
@@ -18,7 +30,7 @@ import org.springframework.test.context.support.DirtiesContextTestExecutionListe
|
||||
import org.springframework.test.context.web.ServletTestExecutionListener;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Divya Srivastava
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@TestExecutionListeners({ ServletTestExecutionListener.class, DirtiesContextBeforeModesTestExecutionListener.class,
|
||||
|
||||
@@ -24,6 +24,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* @author Oliver Gierke
|
||||
* @author Divya Srivastava
|
||||
*/
|
||||
@SpringBootTest
|
||||
@Transactional
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
/**
|
||||
*
|
||||
/*
|
||||
* Copyright 2020-2021 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package example.springdata.jpa.showcase;
|
||||
|
||||
@@ -24,28 +36,28 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Divya Srivastava
|
||||
*/
|
||||
@TestExecutionListeners(listeners = { ServletTestExecutionListener.class,
|
||||
DirtiesContextBeforeModesTestExecutionListener.class, DependencyInjectionTestExecutionListener.class,
|
||||
DirtiesContextTestExecutionListener.class, TransactionalTestExecutionListener.class,
|
||||
SqlScriptsTestExecutionListener.class, EventPublishingTestExecutionListener.class }, inheritListeners = false)
|
||||
@Transactional
|
||||
public class AbstractTransactionalShowcaseContextTests extends AbstractShowcaseContextTests{
|
||||
|
||||
@Transactional
|
||||
public class AbstractTransactionalShowcaseContextTests extends AbstractShowcaseContextTests {
|
||||
|
||||
/**
|
||||
* The {@code JdbcTemplate} that this base class manages, available to subclasses.
|
||||
*
|
||||
* @since 3.2
|
||||
*/
|
||||
protected final JdbcTemplate jdbcTemplate = new JdbcTemplate();
|
||||
|
||||
@Nullable
|
||||
private String sqlScriptEncoding;
|
||||
|
||||
@Nullable private String sqlScriptEncoding;
|
||||
|
||||
/**
|
||||
* Set the {@code DataSource}, typically provided via Dependency Injection.
|
||||
* <p>This method also instantiates the {@link #jdbcTemplate} instance variable.
|
||||
* <p>
|
||||
* This method also instantiates the {@link #jdbcTemplate} instance variable.
|
||||
*/
|
||||
@Autowired
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
@@ -54,6 +66,7 @@ public class AbstractTransactionalShowcaseContextTests extends AbstractShowcaseC
|
||||
|
||||
/**
|
||||
* Specify the encoding for SQL scripts, if different from the platform encoding.
|
||||
*
|
||||
* @see #executeSqlScript
|
||||
*/
|
||||
public void setSqlScriptEncoding(String sqlScriptEncoding) {
|
||||
@@ -62,6 +75,7 @@ public class AbstractTransactionalShowcaseContextTests extends AbstractShowcaseC
|
||||
|
||||
/**
|
||||
* Convenience method for counting the rows in the given table.
|
||||
*
|
||||
* @param tableName table name to count rows in
|
||||
* @return the number of rows in the table
|
||||
* @see JdbcTestUtils#countRowsInTable
|
||||
@@ -71,13 +85,13 @@ public class AbstractTransactionalShowcaseContextTests extends AbstractShowcaseC
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method for counting the rows in the given table, using the
|
||||
* provided {@code WHERE} clause.
|
||||
* <p>See the Javadoc for {@link JdbcTestUtils#countRowsInTableWhere} for details.
|
||||
* Convenience method for counting the rows in the given table, using the provided {@code WHERE} clause.
|
||||
* <p>
|
||||
* See the Javadoc for {@link JdbcTestUtils#countRowsInTableWhere} for details.
|
||||
*
|
||||
* @param tableName the name of the table to count rows in
|
||||
* @param whereClause the {@code WHERE} clause to append to the query
|
||||
* @return the number of rows in the table that match the provided
|
||||
* {@code WHERE} clause
|
||||
* @return the number of rows in the table that match the provided {@code WHERE} clause
|
||||
* @since 3.2
|
||||
* @see JdbcTestUtils#countRowsInTableWhere
|
||||
*/
|
||||
@@ -87,7 +101,9 @@ public class AbstractTransactionalShowcaseContextTests extends AbstractShowcaseC
|
||||
|
||||
/**
|
||||
* Convenience method for deleting all rows from the specified tables.
|
||||
* <p>Use with caution outside of a transaction!
|
||||
* <p>
|
||||
* Use with caution outside of a transaction!
|
||||
*
|
||||
* @param names the names of the tables from which to delete
|
||||
* @return the total number of rows deleted from all specified tables
|
||||
* @see JdbcTestUtils#deleteFromTables
|
||||
@@ -97,17 +113,18 @@ public class AbstractTransactionalShowcaseContextTests extends AbstractShowcaseC
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method for deleting all rows from the given table, using the
|
||||
* provided {@code WHERE} clause.
|
||||
* <p>Use with caution outside of a transaction!
|
||||
* <p>See the Javadoc for {@link JdbcTestUtils#deleteFromTableWhere} for details.
|
||||
* Convenience method for deleting all rows from the given table, using the provided {@code WHERE} clause.
|
||||
* <p>
|
||||
* Use with caution outside of a transaction!
|
||||
* <p>
|
||||
* See the Javadoc for {@link JdbcTestUtils#deleteFromTableWhere} for details.
|
||||
*
|
||||
* @param tableName the name of the table to delete rows from
|
||||
* @param whereClause the {@code WHERE} clause to append to the query
|
||||
* @param args arguments to bind to the query (leaving it to the {@code
|
||||
* PreparedStatement} to guess the corresponding SQL type); may also contain
|
||||
* {@link org.springframework.jdbc.core.SqlParameterValue SqlParameterValue}
|
||||
* objects which indicate not only the argument value but also the SQL type
|
||||
* and optionally the scale.
|
||||
* {@link org.springframework.jdbc.core.SqlParameterValue SqlParameterValue} objects which indicate not only
|
||||
* the argument value but also the SQL type and optionally the scale.
|
||||
* @return the number of rows deleted from the table
|
||||
* @since 4.0
|
||||
* @see JdbcTestUtils#deleteFromTableWhere
|
||||
@@ -118,7 +135,9 @@ public class AbstractTransactionalShowcaseContextTests extends AbstractShowcaseC
|
||||
|
||||
/**
|
||||
* Convenience method for dropping all of the specified tables.
|
||||
* <p>Use with caution outside of a transaction!
|
||||
* <p>
|
||||
* Use with caution outside of a transaction!
|
||||
*
|
||||
* @param names the names of the tables to drop
|
||||
* @since 3.2
|
||||
* @see JdbcTestUtils#dropTables
|
||||
@@ -129,12 +148,15 @@ public class AbstractTransactionalShowcaseContextTests extends AbstractShowcaseC
|
||||
|
||||
/**
|
||||
* Execute the given SQL script.
|
||||
* <p>Use with caution outside of a transaction!
|
||||
* <p>The script will normally be loaded by classpath.
|
||||
* <p><b>Do not use this method to execute DDL if you expect rollback.</b>
|
||||
* <p>
|
||||
* Use with caution outside of a transaction!
|
||||
* <p>
|
||||
* The script will normally be loaded by classpath.
|
||||
* <p>
|
||||
* <b>Do not use this method to execute DDL if you expect rollback.</b>
|
||||
*
|
||||
* @param sqlResourcePath the Spring resource path for the SQL script
|
||||
* @param continueOnError whether or not to continue without throwing an
|
||||
* exception in the event of an error
|
||||
* @param continueOnError whether or not to continue without throwing an exception in the event of an error
|
||||
* @throws DataAccessException if there is an error executing a statement
|
||||
* @see ResourceDatabasePopulator
|
||||
* @see #setSqlScriptEncoding
|
||||
@@ -146,5 +168,5 @@ public class AbstractTransactionalShowcaseContextTests extends AbstractShowcaseC
|
||||
Resource resource = this.applicationContext.getResource(sqlResourcePath);
|
||||
new ResourceDatabasePopulator(continueOnError, false, this.sqlScriptEncoding, resource).execute(ds);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
* Integration tests for Spring Data JPA {@link AccountRepository}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Divya Srivastava
|
||||
*/
|
||||
public class AccountRepositoryIntegrationTest extends AbstractShowcaseTest {
|
||||
|
||||
|
||||
@@ -34,6 +34,7 @@ import org.springframework.data.domain.PageRequest;
|
||||
* Integration tests for Spring Data JPA {@link CustomerRepository}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Divya Srivastava
|
||||
*/
|
||||
public class CustomerRepositoryIntegrationTest extends AbstractShowcaseTest {
|
||||
|
||||
|
||||
@@ -15,21 +15,27 @@
|
||||
*/
|
||||
package example.springdata.jpa.showcase.before;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
import example.springdata.jpa.showcase.AbstractShowcaseTest;
|
||||
import example.springdata.jpa.showcase.core.Account;
|
||||
import example.springdata.jpa.showcase.core.Customer;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.notNullValue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import example.springdata.jpa.showcase.AbstractShowcaseTest;
|
||||
import example.springdata.jpa.showcase.core.Account;
|
||||
import example.springdata.jpa.showcase.core.Customer;
|
||||
|
||||
/**
|
||||
* Integration test for {@link AccountService}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Divya Srivastava
|
||||
* @author Jens Schauder
|
||||
*/
|
||||
public class AccountServiceIntegrationTest extends AbstractShowcaseTest {
|
||||
|
||||
|
||||
@@ -31,6 +31,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
* Integration test for {@link CustomerService}.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Divya Srivastava
|
||||
*/
|
||||
public class CustomerServiceIntegrationTest extends AbstractShowcaseTest {
|
||||
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
* Integration tests for {@link PersonRepository} showing Vavr support at repository query methods.
|
||||
*
|
||||
* @author Oliver Gierke
|
||||
* @author Divya Srivastava
|
||||
*/
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@Transactional
|
||||
|
||||
Reference in New Issue
Block a user