References
- CPS-1379Getting issue details... STATUS
Description
Previously, data was inserted into the database for persistence testing by using SQL scripts. This led to data which cannot conform to any yang model being used for testing purposes. Therefore we want to insert data by using service layer methods. This includes inserting a yang model and data which conforms to it.
Issues & Decisions
# | Issue | Notes | Decision |
---|---|---|---|
1 | Insert data using Service Layer Methods | Validates data with minimal test performance impact if it works | Primary solution |
2 | Insert data using a cps container with test containers | Validates data but can have a bigger performance hit. Also issues relating to which image is used for the image that is spun up | Possible secondary solution |
3 | Insert data using liquibase | No data validation but will be hopefully easier to read. Also cannot add more data/reset data during testing | Not sure if it's worth it, will be similar to the current implementation unless the data can be inserted in json format somehow |
Using Service Layer Methods
https://gerrit.nordix.org/c/onap/cps/+/16357/3 (Patchset 3)
CpsPersistenceSpecBase2.groovy
Since this SpringBootTest does not have the scope of the service layer included, we need to manually tell spring where to find the beans when the test is run. This is done through an inner class with the Configuration annotation and ComponentScan for the relevant modules. The Autowired annotation catches the beans for the other layers and then the Bean annotated methods bring the beans to the outer test class. There are issues with bean instantiation order in this test hence why the Lazy annotation is also included.
@ComponentScan("org.onap.cps.api,org.onap.cps.spi,org.onap.cps.spi.repository,org.onap.cps.notification") @Configuration // @ContextConfiguration(classes = [KafkaAutoConfiguration, KafkaProducerListener, NotificationErrorHandler]) static class TestConfig { @Autowired @Lazy CpsAdminService cpsAdminService @Autowired @Lazy DataspaceRepository dataspaceRepository @Autowired @Lazy AnchorRepository anchorRepository @Autowired @Lazy FragmentRepository fragmentRepository // // @Autowired // @Lazy // NotificationService notificationService // @Autowired @Lazy YangResourceRepository yangResourceRepository @Autowired @Lazy SchemaSetRepository schemaSetRepository @Autowired @Lazy ModuleReferenceRepository moduleReferenceRepository @Autowired @Lazy EntityManagerFactory entityManagerFactory // // @Autowired // @Lazy // KafkaTemplate kafkaTemplate // // @Bean // CpsAdminService cpsAdminService() { // cpsAdminService // return cpsAdminService // } // @Bean DataspaceRepository dataspaceRepository() { return dataspaceRepository } @Bean AnchorRepository anchorRepository() { return anchorRepository } @Bean FragmentRepository fragmentRepository() { return fragmentRepository } @Bean YangResourceRepository yangResourceRepository() { return yangResourceRepository } @Bean SchemaSetRepository schemaSetRepository() { return schemaSetRepository } @Bean ModuleReferenceRepository moduleReferenceRepository() { return moduleReferenceRepository } @Bean EntityManagerFactory entityManagerFactory() { return entityManagerFactory } }
Currently this test results in an ambiguous stackoverflow error which I reckon is due to two beans being created at the same time. Tried renaming the beans and it doesn't seem to have an effect.
java.lang.StackOverflowError at java.base/java.lang.Throwable.getOurStackTrace(Throwable.java:839) at java.base/java.lang.Throwable.getStackTrace(Throwable.java:831) at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:79) at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89) at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89) at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89) at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)...
Using CPS Container
https://gerrit.nordix.org/c/onap/cps/+/16357/4 (Patchset 4)
Using an image of CPS we can insert the data for the tests. We already use a testcontainer for the postgres used. Currently testcontainers is trying to pull docker from nordix which is resulting in an error for this implementation.
Caused by: com.github.dockerjava.api.exception.NotFoundException: Status 404: {"message":"manifest for nexus3.onap.org:10001/library/docker/compose:1.29.2 not found: manifest unknown: manifest unknown"}