simter-reactive-test

Simter reactive test encapsulation

License

License

MIT
Categories

Categories

React User Interface Web Frameworks
GroupId

GroupId

tech.simter.reactive
ArtifactId

ArtifactId

simter-reactive-test
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

simter-reactive-test
Simter reactive test encapsulation
Project URL

Project URL

https://github.com/simter/simter-reactive-test
Project Organization

Project Organization

simter
Source Code Management

Source Code Management

https://github.com/simter/simter-reactive-test.git

Download simter-reactive-test

How to add to project

<!-- https://jarcasting.com/artifacts/tech.simter.reactive/simter-reactive-test/ -->
<dependency>
    <groupId>tech.simter.reactive</groupId>
    <artifactId>simter-reactive-test</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/tech.simter.reactive/simter-reactive-test/
implementation 'tech.simter.reactive:simter-reactive-test:0.1.0'
// https://jarcasting.com/artifacts/tech.simter.reactive/simter-reactive-test/
implementation ("tech.simter.reactive:simter-reactive-test:0.1.0")
'tech.simter.reactive:simter-reactive-test:jar:0.1.0'
<dependency org="tech.simter.reactive" name="simter-reactive-test" rev="0.1.0">
  <artifact name="simter-reactive-test" type="jar" />
</dependency>
@Grapes(
@Grab(group='tech.simter.reactive', module='simter-reactive-test', version='0.1.0')
)
libraryDependencies += "tech.simter.reactive" % "simter-reactive-test" % "0.1.0"
[tech.simter.reactive/simter-reactive-test "0.1.0"]

Dependencies

compile (4)

Group / Artifact Type Version
io.projectreactor : reactor-core jar
org.springframework.boot : spring-boot-test-autoconfigure jar
org.springframework : spring-tx Optional jar
javax.persistence : javax.persistence-api Optional jar 2.2

test (8)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter jar
org.springframework.boot : spring-boot-starter-test jar 2.1.6.RELEASE
io.projectreactor : reactor-test jar
com.ninja-squad : springmockk jar 1.1.2
org.springframework : spring-jdbc jar
org.hibernate : hibernate-entitymanager jar 5.4.3.Final
org.hibernate.validator : hibernate-validator jar 6.0.17.Final
com.h2database : h2 jar 1.4.199

Project Modules

There are no modules declared in this project.

simter-reactive-test

Simter reactive test encapsulation.

Reactive JPA encapsulation

This module just create one @ReactiveDataJpaTest annotation class. It's an annotation use to instead of @DataJpaTest for reactive JPA test.

This annotation inherits from DataJpaTest and only disabled Transactional. Because EntityManager could not share between threads, and in reactive world operation do not guarantee run on same thread all the time. So no need to start Transactional on the unit test class. But must consider that transaction would not rollback default, you need to manual manage it by yourself.

Usage:

Maven:

<dependency>
  <groupId>tech.simter.reactive</groupId>
  <artifactId>simter-reactive-jpa</artifactId>
  <version>{version}</version>
</dependency>
<dependency>
  <groupId>tech.simter.reactive</groupId>
  <artifactId>simter-reactive-test</artifactId>
  <version>{version}</version>
</dependency>

Java:

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import reactor.test.test;
import tech.simter.reactive.jpa.ReactiveEntityManager;
import tech.simter.reactive.test.jpa.ReactiveDataJpaTest;

@SpringJUnitConfig(tech.simter.reactive.jpa.ModuleConfiguration.class)
@ReactiveDataJpaTest
public class TheTest {
  @Autowired
  private ReactiveEntityManager rem;

  @Test
  public test() {
    // save
    MyPo po = new MyPo();
    StepVerifier.create(rem.persist(po))
      .expectNext(po).verifyComplete();

    // find one
    StepVerifier.create(
      rem.createQuery("select t from MyPo t where id = :id", MyPo.class)
      .setParameter("id", 123)
      .getSingleResult()
    ).expectNext(po).verifyComplete();

    // find list
    StepVerifier.create(
      rem.createQuery("select t from MyPo t", MyPo.class)
      .getResultList()
    ).expectNext(po).verifyComplete();
  }
}
tech.simter.reactive

Versions

Version
0.1.0