@@ -17,94 +17,91 @@ 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 java.util.List;
|
||||
|
||||
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.test.context.junit4.SpringRunner;
|
||||
|
||||
import example.springdata.couchbase.model.Airline;
|
||||
import example.springdata.couchbase.util.EnabledOnCouchbaseAvailable;
|
||||
|
||||
/**
|
||||
* Integration tests showing basic CRUD operations through {@link AirlineRepository}.
|
||||
*
|
||||
* @author Denis Rosa
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@EnabledOnCouchbaseAvailable
|
||||
public class AirlineRepositoryIntegrationTests {
|
||||
|
||||
@ClassRule //
|
||||
public static CouchbaseAvailableRule COUCHBASE = CouchbaseAvailableRule.onLocalhost();
|
||||
@Autowired
|
||||
AirlineRepository airlineRepository;
|
||||
|
||||
@Autowired AirlineRepository 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() {
|
||||
List<Airline> airlines = airlineRepository.findByIata("TQ");
|
||||
assertThat(airlines.get(0).getCallsign()).isEqualTo("TXW");
|
||||
}
|
||||
|
||||
List<Airline> airlines = airlineRepository.findByIata("TQ");
|
||||
assertThat(airlines.get(0).getCallsign()).isEqualTo("TXW");
|
||||
}
|
||||
/**
|
||||
* 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() {
|
||||
Airline airline = airlineRepository.findByIata("TQ").get(0);
|
||||
assertThat(airlineRepository.findById(airline.getId()).isPresent());
|
||||
}
|
||||
|
||||
Airline airline = airlineRepository.findByIata("TQ").get(0);
|
||||
assertThat(airlineRepository.findById(airline.getId()).isPresent());
|
||||
}
|
||||
/**
|
||||
* Find all {@link Airline}s applying the {@code airlines/all} view.
|
||||
*/
|
||||
@Test
|
||||
public void shouldFindByView() {
|
||||
|
||||
/**
|
||||
* Find all {@link Airline}s applying the {@code airlines/all} view.
|
||||
*/
|
||||
@Test
|
||||
public void shouldFindByView() {
|
||||
List<Airline> airlines = airlineRepository.findAllBy();
|
||||
|
||||
List<Airline> airlines = airlineRepository.findAllBy();
|
||||
assertThat(airlines).hasSizeGreaterThan(100);
|
||||
}
|
||||
|
||||
assertThat(airlines).hasSizeGreaterThan(100);
|
||||
}
|
||||
/**
|
||||
* 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");
|
||||
airlineRepository.save(airline);
|
||||
|
||||
airlineRepository.save(airline);
|
||||
|
||||
assertThat(airlineRepository.findById("LH")).contains(airline);
|
||||
}
|
||||
assertThat(airlineRepository.findById("LH")).contains(airline);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user