Reactive Spring Boot with R2DBC with TDD using PostGreSql

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-r2dbc</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
</dependency>

<dependency>
<groupId>io.r2dbc</groupId>
<artifactId>r2dbc-postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Employee {

@Id
private Integer id;
private String firstName;
private String LastName;

}
public class EmployeeTest {
@Test
public void test_createEmployeeBean(){

Employee employee=new Employee(1001,"Jack", "Smith");
Assertions.assertEquals(employee.getId(),1001);
Assertions.assertEquals(employee.getFirstName(),"Jack");
Assertions.assertEquals(employee.getLastName(),"Smith");
}
}
public interface EmployeeRepository extends ReactiveCrudRepository<EmployeeRepository, Integer> {
}


spring:
r2dbc:
url: r2dbc:postgres://localhost/emp
username: postgres
password: *******
@ExtendWith(SpringExtension.class)
@DataR2dbcTest
public class EmployeeRepositoryTests {

@Autowired
EmployeeRepository employeeRepository;

@Test
public void tests_persisEmployee(){

Flux<Employee> actual = this.employeeRepository.deleteAll()
.thenMany(this.employeeRepository.save(new Employee(null, "Tina", "Fey")))
.thenMany(this.employeeRepository.findAll());

StepVerifier.create(actual)
.expectNextMatches(result->result.getFirstName().equalsIgnoreCase("tina"))
.verifyComplete();
}

}

--

--

--

Technology enthusiast exploring smart ways of building enterprise software(s) , a marathon run addict and a water-colour artist

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Opencart Folder structure ..Changing the .tpl to .twig

Is IAM outdated? Why you need to study alternatives

Deleting Records with Associations

Chapter 5 — Extra-strength Methods

How can I become a website developer expert?

itechscripts.com

All the basics of Cascading Style Sheets (CSS)

Bool cool == true

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
abhinav singhal

abhinav singhal

Technology enthusiast exploring smart ways of building enterprise software(s) , a marathon run addict and a water-colour artist

More from Medium

What is Spring Framework & IoC (Inversion Of Control) in Spring?

Spring Boot with PostgreSQL and Hibernate — Part 2

SpringBoot and AWS Elastic Beanstalk

Making Avro field names in-stream small and adding key in KSQLDB