JAVA-14288 Rename spring-5-reactive-modules to spring-reactive-modules (#12659)

* JAVA-14288 Rename spring-5-reactive-modules to spring-reactive-modules

* JAVA-14288 Remove failing module

* JAVA-14288 Revert commenting spring-cloud-openfeign-2 module
This commit is contained in:
anuragkumawat
2022-09-02 21:50:42 +05:30
committed by GitHub
parent 18f456b179
commit d429f0f064
303 changed files with 12 additions and 12 deletions

View File

@@ -0,0 +1,17 @@
package com.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.r2dbc.R2dbcApplication;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = R2dbcApplication.class)
public class SpringContextTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}

View File

@@ -0,0 +1,54 @@
package com.baeldung.couchbase.domain.repository;
import com.baeldung.couchbase.configuration.CouchbaseProperties;
import com.couchbase.mock.Bucket;
import com.couchbase.mock.BucketConfiguration;
import com.couchbase.mock.CouchbaseMock;
import org.springframework.boot.test.context.TestConfiguration;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.IOException;
import java.io.UncheckedIOException;
import java.util.Collections;
@TestConfiguration
public class CouchbaseMockConfiguration {
private CouchbaseMock couchbaseMock;
public CouchbaseMockConfiguration(final CouchbaseProperties couchbaseProperties) {
final BucketConfiguration bucketConfiguration = new BucketConfiguration();
bucketConfiguration.numNodes = 1;
bucketConfiguration.numReplicas = 1;
bucketConfiguration.numVBuckets = 1024;
bucketConfiguration.name = couchbaseProperties.getBucketName();
bucketConfiguration.type = Bucket.BucketType.COUCHBASE;
bucketConfiguration.password = couchbaseProperties.getBucketPassword();
try {
couchbaseMock = new CouchbaseMock(couchbaseProperties.getPort(), Collections.singletonList(bucketConfiguration));
} catch (final IOException ex) {
throw new UncheckedIOException(ex);
}
}
@PostConstruct
public void postConstruct() {
try {
couchbaseMock.start();
} catch (final IOException ex) {
throw new UncheckedIOException(ex);
}
try {
couchbaseMock.waitForStartup();
} catch (final InterruptedException ex) {
throw new RuntimeException(ex);
}
}
@PreDestroy
public void preDestroy() {
couchbaseMock.stop();
}
}

View File

@@ -0,0 +1,55 @@
package com.baeldung.couchbase.domain.repository.n1ql;
import com.baeldung.couchbase.domain.Person;
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.test.context.junit4.SpringRunner;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;
import java.util.UUID;
@RunWith(SpringRunner.class)
@SpringBootTest(properties = {"spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration"})
public class N1QLPersonRepositoryLiveTest {
@Autowired private N1QLPersonRepository personRepository;
@Test
public void shouldFindAll_byLastName() {
//Given
final String firstName = "John";
final Person matchingPerson = new Person(UUID.randomUUID(), firstName);
final Person nonMatchingPerson = new Person(UUID.randomUUID(), "NotJohn");
wrap(() -> {
personRepository
.save(matchingPerson)
.subscribe();
personRepository
.save(nonMatchingPerson)
.subscribe();
//When
final Flux<Person> allByFirstName = personRepository.findAllByFirstName(firstName);
//Then
StepVerifier
.create(allByFirstName)
.expectNext(matchingPerson)
.verifyComplete();
}, matchingPerson, nonMatchingPerson);
}
private void wrap(final Runnable runnable, final Person... people) {
try {
runnable.run();
} finally {
for (final Person person : people) {
personRepository
.delete(person)
.subscribe();
}
}
}
}

View File

@@ -0,0 +1,60 @@
package com.baeldung.couchbase.domain.repository.n1ql;
import com.baeldung.couchbase.domain.Person;
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.domain.Sort;
import org.springframework.test.context.junit4.SpringRunner;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;
import java.util.UUID;
@RunWith(SpringRunner.class)
@SpringBootTest(properties = {"spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration"})
public class N1QLSortingPersonRepositoryLiveTest {
@Autowired private N1QLSortingPersonRepository personRepository;
@Test
public void shouldFindAll_sortedByFirstName() {
//Given
final Person firstPerson = new Person(UUID.randomUUID(), "John");
final Person secondPerson = new Person(UUID.randomUUID(), "Mikki");
wrap(() -> {
personRepository
.save(firstPerson)
.subscribe();
personRepository
.save(secondPerson)
.subscribe();
//When
final Flux<Person> allByFirstName = personRepository.findAll(Sort.by(Sort.Direction.DESC, "firstName"));
//Then
StepVerifier
.create(allByFirstName)
.expectNextMatches(person -> person
.getFirstName()
.equals(secondPerson.getFirstName()))
.expectNextMatches(person -> person
.getFirstName()
.equals(firstPerson.getFirstName()))
.verifyComplete();
}, firstPerson, secondPerson);
}
//workaround for deleteAll()
private void wrap(final Runnable runnable, final Person... people) {
try {
runnable.run();
} finally {
for (final Person person : people) {
personRepository
.delete(person)
.subscribe();
}
}
}
}

View File

@@ -0,0 +1,81 @@
package com.baeldung.couchbase.domain.repository.view;
import com.baeldung.couchbase.configuration.CouchbaseProperties;
import com.baeldung.couchbase.configuration.ViewReactiveCouchbaseConfiguration;
import com.baeldung.couchbase.domain.Person;
import com.baeldung.couchbase.domain.repository.CouchbaseMockConfiguration;
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.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import java.util.UUID;
@RunWith(SpringRunner.class)
@SpringBootTest(properties = { "spring.couchbase.port=10010", "spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration,org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration" },
classes = { CouchbaseMockConfiguration.class, ViewReactiveCouchbaseConfiguration.class, CouchbaseProperties.class })
public class ViewPersonRepositoryIntegrationTest {
@Autowired private ViewPersonRepository personRepository;
@Test
public void shouldSavePerson_findById_thenDeleteIt() {
//Given
final UUID id = UUID.randomUUID();
final Person person = new Person(id, "John");
wrap(() -> {
personRepository
.save(person)
.subscribe();
//When
final Mono<Person> byId = personRepository.findById(id);
//Then
StepVerifier
.create(byId)
.expectNextMatches(result -> result
.getId()
.equals(id))
.expectComplete()
.verify();
}, person);
}
@Test
public void shouldFindAll_thenDeleteIt() {
//Given
final Person person = new Person(UUID.randomUUID(), "John");
final Person secondPerson = new Person(UUID.randomUUID(), "Mikki");
wrap(() -> {
personRepository
.save(person)
.subscribe();
personRepository
.save(secondPerson)
.subscribe();
//When
final Flux<Person> all = personRepository.findAll();
//Then
StepVerifier
.create(all)
.expectNextCount(2)
.verifyComplete();
}, person, secondPerson);
}
private void wrap(final Runnable runnable, final Person... people) {
try {
runnable.run();
} finally {
for (final Person person : people) {
personRepository
.delete(person)
.subscribe();
}
}
}
}

View File

@@ -0,0 +1,124 @@
package com.baeldung.r2dbc;
import com.baeldung.r2dbc.model.Player;
import com.baeldung.r2dbc.repository.PlayerRepository;
import io.r2dbc.h2.H2ConnectionFactory;
import org.junit.Before;
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.r2dbc.core.DatabaseClient;
import org.springframework.test.context.junit4.SpringRunner;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Hooks;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import java.util.Arrays;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest
public class R2dbcApplicationIntegrationTest {
@Autowired
PlayerRepository playerRepository;
@Autowired
DatabaseClient client;
@Autowired
H2ConnectionFactory factory;
@Before
public void setup() {
Hooks.onOperatorDebug();
List<String> statements = Arrays.asList(//
"DROP TABLE IF EXISTS player;",
"CREATE table player (id INT AUTO_INCREMENT NOT NULL, name VARCHAR2, age INT NOT NULL);");
statements.forEach(it -> client.execute(it) //
.fetch() //
.rowsUpdated() //
.as(StepVerifier::create) //
.expectNextCount(1) //
.verifyComplete());
}
@Test
public void whenDeleteAll_then0IsExpected() {
playerRepository.deleteAll()
.as(StepVerifier::create)
.expectNextCount(0)
.verifyComplete();
}
@Test
public void whenInsert6_then6AreExpected() {
insertPlayers();
playerRepository.findAll()
.as(StepVerifier::create)
.expectNextCount(6)
.verifyComplete();
}
@Test
public void whenSearchForCR7_then1IsExpected() {
insertPlayers();
playerRepository.findAllByName("CR7")
.as(StepVerifier::create)
.expectNextCount(1)
.verifyComplete();
}
@Test
public void whenSearchFor32YearsOld_then2AreExpected() {
insertPlayers();
playerRepository.findByAge(32)
.as(StepVerifier::create)
.expectNextCount(2)
.verifyComplete();
}
@Test
public void whenBatchHas2Operations_then2AreExpected() {
Mono.from(factory.create())
.flatMapMany(connection -> Flux.from(connection
.createBatch()
.add("select * from player")
.add("select * from player")
.execute()))
.as(StepVerifier::create)
.expectNextCount(2)
.verifyComplete();
}
private void insertPlayers() {
List<Player> players = Arrays.asList(
new Player(null, "Kaka", 37),
new Player(null, "Messi", 32),
new Player(null, "Mbappé", 20),
new Player(null, "CR7", 34),
new Player(null, "Lewandowski", 30),
new Player(null, "Cavani", 32)
);
playerRepository.saveAll(players).subscribe();
}
}