@@ -17,111 +17,108 @@ package example.springdata.couchbase.repository;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import example.springdata.couchbase.model.Airline;
|
||||
import example.springdata.couchbase.util.CouchbaseAvailableRule;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.data.couchbase.core.CouchbaseOperations;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import example.springdata.couchbase.model.Airline;
|
||||
import example.springdata.couchbase.util.EnabledOnCouchbaseAvailable;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
/**
|
||||
* Integration tests showing basic CRUD operations through {@link ReactiveAirlineRepository}
|
||||
*
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@EnabledOnCouchbaseAvailable
|
||||
public class ReactiveAirlineRepositoryIntegrationTests {
|
||||
|
||||
@ClassRule //
|
||||
public static CouchbaseAvailableRule COUCHBASE = CouchbaseAvailableRule.onLocalhost();
|
||||
@Autowired
|
||||
ReactiveAirlineRepository airlineRepository;
|
||||
|
||||
@Autowired ReactiveAirlineRepository airlineRepository;
|
||||
@Autowired
|
||||
CouchbaseOperations couchbaseOperations;
|
||||
|
||||
@Autowired CouchbaseOperations couchbaseOperations;
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
if (couchbaseOperations.existsById().one("LH")) {
|
||||
couchbaseOperations.removeById().one("LH");
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
if (couchbaseOperations.existsById().one("LH")) {
|
||||
couchbaseOperations.removeById().one("LH");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The derived query executes a N1QL query emitting a single element.
|
||||
*/
|
||||
@Test
|
||||
public void shouldFindAirlineN1ql() {
|
||||
|
||||
/**
|
||||
* The derived query executes a N1QL query emitting a single element.
|
||||
*/
|
||||
@Test
|
||||
public void shouldFindAirlineN1ql() {
|
||||
airlineRepository.findByIata("TQ") //
|
||||
.as(StepVerifier::create) //
|
||||
.assertNext(it -> {
|
||||
assertThat(it.getCallsign()).isEqualTo("TXW");
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
airlineRepository.findByIata("TQ") //
|
||||
.as(StepVerifier::create) //
|
||||
.assertNext(it -> {
|
||||
assertThat(it.getCallsign()).isEqualTo("TXW");
|
||||
}).verifyComplete();
|
||||
}
|
||||
/**
|
||||
* The derived query executes a N1QL query and the emitted element is used to invoke
|
||||
* {@link org.springframework.data.repository.reactive.ReactiveCrudRepository#findById(Object)} for an Id-based lookup.
|
||||
* Queries without a result do not emit a value.
|
||||
*/
|
||||
@Test
|
||||
public void shouldFindById() {
|
||||
|
||||
/**
|
||||
* The derived query executes a N1QL query and the emitted element is used to invoke
|
||||
* {@link org.springframework.data.repository.reactive.ReactiveCrudRepository#findById(Object)} for an Id-based
|
||||
* lookup. Queries without a result do not emit a value.
|
||||
*/
|
||||
@Test
|
||||
public void shouldFindById() {
|
||||
Mono<Airline> airline = airlineRepository.findByIata("TQ") //
|
||||
.map(Airline::getId) //
|
||||
.flatMap(airlineRepository::findById);
|
||||
|
||||
Mono<Airline> airline = airlineRepository.findByIata("TQ") //
|
||||
.map(Airline::getId) //
|
||||
.flatMap(airlineRepository::findById);
|
||||
airline.as(StepVerifier::create) //
|
||||
.assertNext(it -> {
|
||||
|
||||
airline.as(StepVerifier::create) //
|
||||
.assertNext(it -> {
|
||||
assertThat(it.getCallsign()).isEqualTo("TXW");
|
||||
}).verifyComplete();
|
||||
|
||||
assertThat(it.getCallsign()).isEqualTo("TXW");
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* Find all {@link Airline}s applying the {@code airlines/all} view.
|
||||
*/
|
||||
@Test
|
||||
public void shouldFindAll() {
|
||||
airlineRepository.findAllBy().count() //
|
||||
.as(StepVerifier::create) //
|
||||
.assertNext(count -> {
|
||||
|
||||
/**
|
||||
* Find all {@link Airline}s applying the {@code airlines/all} view.
|
||||
*/
|
||||
@Test
|
||||
public void shouldFindAll() {
|
||||
airlineRepository.findAllBy().count() //
|
||||
.as(StepVerifier::create) //
|
||||
.assertNext(count -> {
|
||||
assertThat(count).isGreaterThan(100);
|
||||
}).verifyComplete();
|
||||
}
|
||||
|
||||
assertThat(count).isGreaterThan(100);
|
||||
}).verifyComplete();
|
||||
}
|
||||
/**
|
||||
* Created elements are emitted by the
|
||||
* {@link org.springframework.data.repository.reactive.ReactiveCrudRepository#save(Object)} method.
|
||||
*/
|
||||
@Test
|
||||
public void shouldCreateAirline() {
|
||||
|
||||
/**
|
||||
* Created elements are emitted by the
|
||||
* {@link org.springframework.data.repository.reactive.ReactiveCrudRepository#save(Object)} method.
|
||||
*/
|
||||
@Test
|
||||
public void shouldCreateAirline() {
|
||||
Airline airline = new Airline();
|
||||
|
||||
Airline airline = new Airline();
|
||||
airline.setId("LH");
|
||||
airline.setIata("LH");
|
||||
airline.setIcao("DLH");
|
||||
airline.setCallsign("Lufthansa");
|
||||
airline.setName("Lufthansa");
|
||||
airline.setCountry("Germany");
|
||||
|
||||
airline.setId("LH");
|
||||
airline.setIata("LH");
|
||||
airline.setIcao("DLH");
|
||||
airline.setCallsign("Lufthansa");
|
||||
airline.setName("Lufthansa");
|
||||
airline.setCountry("Germany");
|
||||
Mono<Airline> airlineMono = airlineRepository.save(airline) //
|
||||
.map(Airline::getId) //
|
||||
.flatMap(airlineRepository::findById);
|
||||
|
||||
Mono<Airline> airlineMono = airlineRepository.save(airline) //
|
||||
.map(Airline::getId) //
|
||||
.flatMap(airlineRepository::findById);
|
||||
|
||||
airlineMono.as(StepVerifier::create) //
|
||||
.expectNext(airline) //
|
||||
.verifyComplete();
|
||||
}
|
||||
airlineMono.as(StepVerifier::create) //
|
||||
.expectNext(airline) //
|
||||
.verifyComplete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,21 +17,18 @@ package example.springdata.couchbase.template;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import example.springdata.couchbase.model.Airline;
|
||||
import example.springdata.couchbase.util.CouchbaseAvailableRule;
|
||||
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.data.couchbase.core.CouchbaseOperations;
|
||||
import org.springframework.data.couchbase.core.ReactiveCouchbaseOperations;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import example.springdata.couchbase.model.Airline;
|
||||
import example.springdata.couchbase.util.EnabledOnCouchbaseAvailable;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
/**
|
||||
* Integration tests showing basic CRUD operations through
|
||||
@@ -40,61 +37,57 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
* @author Mark Paluch
|
||||
* @author Denis Rosa
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@EnabledOnCouchbaseAvailable
|
||||
public class ReactiveJavaCouchbaseOperationsIntegrationTests {
|
||||
|
||||
@ClassRule //
|
||||
public static CouchbaseAvailableRule COUCHBASE = CouchbaseAvailableRule.onLocalhost();
|
||||
@Autowired
|
||||
ReactiveCouchbaseOperations operations;
|
||||
|
||||
@Autowired
|
||||
ReactiveCouchbaseOperations operations;
|
||||
@Autowired
|
||||
CouchbaseOperations couchbaseOperations;
|
||||
|
||||
@Autowired
|
||||
CouchbaseOperations couchbaseOperations;
|
||||
@BeforeEach
|
||||
public void before() {
|
||||
if (couchbaseOperations.existsById().one("LH")) {
|
||||
couchbaseOperations.removeById().one("LH");
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
if (couchbaseOperations.existsById().one("LH")) {
|
||||
couchbaseOperations.removeById().one("LH");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Find all {@link Airline}s applying the _class filter .
|
||||
*/
|
||||
@Test
|
||||
public void shouldFindByAll() {
|
||||
operations.findByQuery(Airline.class).all() //
|
||||
.count() //
|
||||
.as(StepVerifier::create) //
|
||||
.assertNext(count -> {
|
||||
|
||||
/**
|
||||
* Find all {@link Airline}s applying the _class filter .
|
||||
*/
|
||||
@Test
|
||||
public void shouldFindByAll() {
|
||||
operations.findByQuery(Airline.class).all() //
|
||||
.count() //
|
||||
.as(StepVerifier::create) //
|
||||
.assertNext(count -> {
|
||||
assertThat(count).isGreaterThan(100);
|
||||
}) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
assertThat(count).isGreaterThan(100);
|
||||
}) //
|
||||
.verifyComplete();
|
||||
}
|
||||
/**
|
||||
* Created elements are emitted by {@link ReactiveCouchbaseOperations#upsertById(Class)} )}.
|
||||
*/
|
||||
@Test
|
||||
public void shouldCreateAirline() {
|
||||
Airline airline = new Airline();
|
||||
|
||||
/**
|
||||
* Created elements are emitted by {@link ReactiveCouchbaseOperations#upsertById(Class)} )}.
|
||||
*/
|
||||
@Test
|
||||
public void shouldCreateAirline() {
|
||||
Airline airline = new Airline();
|
||||
airline.setId("LH");
|
||||
airline.setIata("LH");
|
||||
airline.setIcao("DLH");
|
||||
airline.setCallsign("Lufthansa");
|
||||
airline.setName("Lufthansa");
|
||||
airline.setCountry("Germany");
|
||||
|
||||
airline.setId("LH");
|
||||
airline.setIata("LH");
|
||||
airline.setIcao("DLH");
|
||||
airline.setCallsign("Lufthansa");
|
||||
airline.setName("Lufthansa");
|
||||
airline.setCountry("Germany");
|
||||
Mono<Airline> airlineMono = operations.upsertById(Airline.class).one(airline) //
|
||||
.map(Airline::getId) //
|
||||
.flatMap(id -> operations.findById(Airline.class).one(id));
|
||||
|
||||
Mono<Airline> airlineMono = operations.upsertById(Airline.class)
|
||||
.one(airline) //
|
||||
.map(Airline::getId) //
|
||||
.flatMap(id -> operations.findById(Airline.class).one(id));
|
||||
|
||||
airlineMono.as(StepVerifier::create) //
|
||||
.expectNext(airline).verifyComplete();
|
||||
}
|
||||
airlineMono.as(StepVerifier::create) //
|
||||
.expectNext(airline).verifyComplete();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user