Migrate Cassandra examples to JUnit 5.

See #583
This commit is contained in:
Mark Paluch
2021-03-23 08:50:52 +01:00
parent 4bcf378114
commit 60385ee4b4
25 changed files with 568 additions and 534 deletions

View File

@@ -22,25 +22,20 @@ import reactor.test.StepVerifier;
import java.time.Instant;
import org.junit.ClassRule;
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.autoconfigure.data.cassandra.DataCassandraTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration tests showing Reactive Auditing with Cassandra in action.
*
* @author Mark Paluch
*/
@RunWith(SpringRunner.class)
@CassandraKeyspace
@DataCassandraTest
public class AuditingIntegrationTests {
@ClassRule public final static CassandraKeyspace CASSANDRA_KEYSPACE = CassandraKeyspace.onLocalhost();
@Autowired OrderRepository orderRepository;
@Test

View File

@@ -23,33 +23,29 @@ import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import rx.RxReactiveStreams;
import org.junit.Before;
import org.junit.ClassRule;
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.context.SpringBootTest;
import org.springframework.data.cassandra.core.ReactiveCassandraTemplate;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration test for {@link ReactiveCassandraTemplate}.
*
* @author Mark Paluch
*/
@RunWith(SpringRunner.class)
@CassandraKeyspace
@SpringBootTest
public class ReactiveCassandraTemplateIntegrationTest {
@ClassRule public final static CassandraKeyspace CASSANDRA_KEYSPACE = CassandraKeyspace.onLocalhost();
class ReactiveCassandraTemplateIntegrationTest {
@Autowired ReactiveCassandraTemplate template;
/**
* Truncate table and insert some rows.
*/
@Before
public void setUp() {
@BeforeEach
void setUp() {
Flux<Person> truncateAndInsert = template.truncate(Person.class) //
.thenMany(Flux.just(new Person("Walter", "White", 50), //
@@ -66,7 +62,7 @@ public class ReactiveCassandraTemplateIntegrationTest {
* the two counts ({@code 4} and {@code 6}) to the console.
*/
@Test
public void shouldInsertAndCountData() {
void shouldInsertAndCountData() {
Mono<Long> saveAndCount = template.count(Person.class) //
.doOnNext(System.out::println) //
@@ -84,7 +80,7 @@ public class ReactiveCassandraTemplateIntegrationTest {
* Note that the all object conversions are performed before the results are printed to the console.
*/
@Test
public void convertReactorTypesToRxJava1() throws Exception {
void convertReactorTypesToRxJava1() throws Exception {
Flux<Person> flux = template.select("SELECT * FROM person WHERE lastname = 'White'", Person.class);

View File

@@ -20,32 +20,28 @@ import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import org.junit.Before;
import org.junit.ClassRule;
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.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration test for {@link ReactivePersonRepository} using Project Reactor types and operators.
*
* @author Mark Paluch
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class ReactivePersonRepositoryIntegrationTest {
@ClassRule public final static CassandraKeyspace CASSANDRA_KEYSPACE = CassandraKeyspace.onLocalhost();
@CassandraKeyspace
class ReactivePersonRepositoryIntegrationTest {
@Autowired ReactivePersonRepository repository;
/**
* Clear table and insert some rows.
*/
@Before
public void setUp() {
@BeforeEach
void setUp() {
Flux<Person> deleteAndInsert = repository.deleteAll() //
.thenMany(repository.saveAll(Flux.just(new Person("Walter", "White", 50), //
@@ -60,7 +56,7 @@ public class ReactivePersonRepositoryIntegrationTest {
* This sample performs a count, inserts data and performs a count again using reactive operator chaining.
*/
@Test
public void shouldInsertAndCountData() {
void shouldInsertAndCountData() {
Mono<Long> saveAndCount = repository.count() //
.doOnNext(System.out::println) //
@@ -78,7 +74,7 @@ public class ReactivePersonRepositoryIntegrationTest {
* prefetch define the amount of fetched records.
*/
@Test
public void shouldPerformConversionBeforeResultProcessing() {
void shouldPerformConversionBeforeResultProcessing() {
StepVerifier.create(repository.findAll().doOnNext(System.out::println)) //
.expectNextCount(4) //
@@ -89,7 +85,7 @@ public class ReactivePersonRepositoryIntegrationTest {
* Fetch data using query derivation.
*/
@Test
public void shouldQueryDataWithQueryDerivation() {
void shouldQueryDataWithQueryDerivation() {
StepVerifier.create(repository.findByLastname("White")).expectNextCount(2).verifyComplete();
}
@@ -97,7 +93,7 @@ public class ReactivePersonRepositoryIntegrationTest {
* Fetch data using a string query.
*/
@Test
public void shouldQueryDataWithStringQuery() {
void shouldQueryDataWithStringQuery() {
StepVerifier.create(repository.findByFirstnameInAndLastname("Walter", "White")).expectNextCount(1).verifyComplete();
}
@@ -105,7 +101,7 @@ public class ReactivePersonRepositoryIntegrationTest {
* Fetch data using query derivation.
*/
@Test
public void shouldQueryDataWithDeferredQueryDerivation() {
void shouldQueryDataWithDeferredQueryDerivation() {
StepVerifier.create(repository.findByLastname(Mono.just("White"))).expectNextCount(2).verifyComplete();
}
@@ -113,7 +109,7 @@ public class ReactivePersonRepositoryIntegrationTest {
* Fetch data using query derivation and deferred parameter resolution.
*/
@Test
public void shouldQueryDataWithMixedDeferredQueryDerivation() {
void shouldQueryDataWithMixedDeferredQueryDerivation() {
StepVerifier.create(repository.findByFirstnameAndLastname(Mono.just("Walter"), "White")) //
.expectNextCount(1) //

View File

@@ -20,14 +20,12 @@ import io.reactivex.Completable;
import io.reactivex.Flowable;
import io.reactivex.Single;
import org.junit.Before;
import org.junit.ClassRule;
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.context.SpringBootTest;
import org.springframework.data.cassandra.core.ReactiveCassandraOperations;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration test for {@link RxJava2PersonRepository} using RxJava1 types. Note that
@@ -36,16 +34,15 @@ import org.springframework.test.context.junit4.SpringRunner;
*
* @author Mark Paluch
*/
@RunWith(SpringRunner.class)
@CassandraKeyspace
@SpringBootTest
public class RxJava2PersonRepositoryIntegrationTest {
@ClassRule public final static CassandraKeyspace CASSANDRA_KEYSPACE = CassandraKeyspace.onLocalhost();
@Autowired RxJava2PersonRepository repository;
@Autowired ReactiveCassandraOperations operations;
@Before
@BeforeEach
public void setUp() throws Exception {
Completable deleteAll = repository.deleteAll();

View File

@@ -24,30 +24,25 @@ import reactor.util.context.Context;
import java.util.Arrays;
import org.junit.Before;
import org.junit.ClassRule;
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.data.cassandra.DataCassandraTest;
import org.springframework.test.context.junit4.SpringRunner;
/**
* Integration tests showing the SpEL context extension in action.
*
* @author Mark Paluch
*/
@RunWith(SpringRunner.class)
@CassandraKeyspace
@DataCassandraTest
public class ExpressionIntegrationTests {
@ClassRule public final static CassandraKeyspace CASSANDRA_KEYSPACE = CassandraKeyspace.onLocalhost();
class ExpressionIntegrationTests {
@Autowired EmployeeRepository employeeRepository;
@Before
public void before() {
@BeforeEach
void before() {
employeeRepository.deleteAll().as(StepVerifier::create).verifyComplete();
@@ -60,7 +55,7 @@ public class ExpressionIntegrationTests {
}
@Test
public void shouldFindByTenantIdAndName() {
void shouldFindByTenantIdAndName() {
employeeRepository.findAllByName("Walter") //
.contextWrite(Context.of(Tenant.class, new Tenant("breaking-bad"))).as(StepVerifier::create) //