...
Due to ports exposed for a test containers (part of DB_URL) are variable (to allow concurrent tests executions and to avoid conflicts with
existing containers) the expected variables are set after the test container being initialized directly from TestContainer wrapper artifact
...
Test class
...
template
Below is the an example of test class (setup ) which can be used as a template /reference for new database tests being added to CPS project.
Code Block | ||
---|---|---|
| ||
package org.onap.cps.spi.impl; import org.junit.ClassRule; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.cps.DatabaseTestContainer; import org.onap.cps.spi.CpsAdminPersistenceService; import org.onap.cps.spi.repository.DataspaceRepository; import org.onap.cps.spi.repository.SchemaSetRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest public class CpsAdminPersistenceServiceTest { private static final String CLEAR_DATA = "/data/clear-all.sql"; private static final String SET_DATA = "/data/anchor.sql"; @ClassRule public static DatabaseTestContainer databaseTestContainer = DatabaseTestContainer.getInstance(); @Autowired private CpsAdminPersistenceService cpsAdminPersistenceService; @Autowired private DataspaceRepository dataspaceRepository; @Autowired private SchemaSetRepository schemaSetRepository; @Test @Sql({CLEAR_DATA, SET_DATA}) public void testCreateAnchor() { // test ... } } |
Resources
Frameworks and libraries:
...