Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
@Documented @Inherited @Retention(RUNTIME) @Target({TYPE}) @ResourceLock("com.codename1.backend.test.BackendTest")
public @interface DataJpaTest
Tests persistence without the rest of the application: what Spring’s
@DataJpaTest does.
The slice has the database, the entity manager and the module’s repositories,
and none of its components, controllers or routes. A test injects the
EntityManager, the DataSource or a repository interface and calls it
directly. Components it needs too are named in includes; a dependency of
theirs that the slice lacks fails the build.
The database is the one database names, a fresh in-memory SQLite one by
default, whatever the module’s settings say, so a persistence test never
touches a database that outlives it. The generated daos create their tables
in it, and migrations run as they do on start-up.
Each test method runs in a transaction that is rolled back when it returns,
as Spring’s are, so one test’s rows are not the next one’s. @BeforeEach and
@AfterEach methods run outside it; rollback set to false commits instead.
Methods
public abstract Class<?>[] includes() default {} | Components and configurations of the application to wire into the slice, what Spring’s @Import adds to one. |
public abstract String database() default ":memory:" | The database URL, as cn1.datasource.url takes it. |
public abstract boolean rollback() default true | Whether each test method’s transaction is rolled back. |
public abstract String[] properties() default {} | Settings for this test, as key=value, as BackendTest.properties. |
public abstract String profile() default "test" | The profile, as BackendTest.profile. |
public abstract Class<?>[] classes() default {} | TestConfiguration classes to add, as BackendTest.classes. |
Method details
includes
public abstract Class<?>[] includes() default {}@Import adds to one.database
public abstract String database() default ":memory:"cn1.datasource.url takes it. An in-memory SQLite
database by default, which is gone when the test run ends.rollback
public abstract boolean rollback() default trueproperties
public abstract String[] properties() default {}key=value, as BackendTest.properties.profile
public abstract String profile() default "test"BackendTest.profile.classes
public abstract Class<?>[] classes() default {}TestConfiguration classes to add, as BackendTest.classes.