Remove the dependency-cycle between beans
[cps.git] / integration-test / src / test / groovy / org / onap / cps / integration / base / CpsIntegrationSpecBase.groovy
index a1e0352..6dec3db 100644 (file)
 
 package org.onap.cps.integration.base
 
+import org.onap.cps.api.CpsAnchorService
+import org.onap.cps.api.CpsDataService
+import org.onap.cps.api.CpsDataspaceService
+import org.onap.cps.api.CpsModuleService
 import org.onap.cps.api.CpsQueryService
-import org.onap.cps.api.impl.CpsAdminServiceImpl
-import org.onap.cps.api.impl.CpsDataServiceImpl
-import org.onap.cps.api.impl.CpsModuleServiceImpl
 import org.onap.cps.integration.DatabaseTestContainer
 import org.onap.cps.spi.config.CpsSessionFactory
 import org.onap.cps.spi.exceptions.DataspaceNotFoundException
@@ -44,7 +45,7 @@ import spock.lang.Specification
 
 import java.time.OffsetDateTime
 
-@SpringBootTest(classes = [TestConfig, CpsAdminServiceImpl, CpsValidatorImpl, SessionManager, CpsSessionFactory])
+@SpringBootTest(classes = [TestConfig, CpsValidatorImpl, SessionManager, CpsSessionFactory])
 @Testcontainers
 @EnableAutoConfiguration
 @EnableJpaRepositories(basePackageClasses = [DataspaceRepository])
@@ -57,15 +58,19 @@ class CpsIntegrationSpecBase extends Specification {
 
     @Autowired
     @Lazy
-    CpsAdminServiceImpl cpsAdminService
+    CpsDataspaceService cpsDataspaceService
 
     @Autowired
     @Lazy
-    CpsDataServiceImpl cpsDataService
+    CpsAnchorService cpsAnchorService
 
     @Autowired
     @Lazy
-    CpsModuleServiceImpl cpsModuleService
+    CpsDataService cpsDataService
+
+    @Autowired
+    @Lazy
+    CpsModuleService cpsModuleService
 
     @Autowired
     @Lazy
@@ -79,10 +84,11 @@ class CpsIntegrationSpecBase extends Specification {
     def static BOOKSTORE_SCHEMA_SET = 'bookstoreSchemaSet'
 
     def static initialized = false
+    def now = OffsetDateTime.now()
 
     def setup() {
         if (!initialized) {
-            cpsAdminService.createDataspace(GENERAL_TEST_DATASPACE)
+            cpsDataspaceService.createDataspace(GENERAL_TEST_DATASPACE)
             def bookstoreModelFileContent = readResourceDataFile('bookstore/bookstore.yang')
             cpsModuleService.createSchemaSet(GENERAL_TEST_DATASPACE, BOOKSTORE_SCHEMA_SET, [bookstore : bookstoreModelFileContent])
             initialized = true;
@@ -107,8 +113,8 @@ class CpsIntegrationSpecBase extends Specification {
 
     def dataspaceExists(dataspaceName) {
         try {
-            cpsAdminService.getDataspace(dataspaceName)
-        } catch (DataspaceNotFoundException e) {
+            cpsDataspaceService.getDataspace(dataspaceName)
+        } catch (DataspaceNotFoundException dataspaceNotFoundException) {
             return false
         }
         return true
@@ -116,8 +122,35 @@ class CpsIntegrationSpecBase extends Specification {
 
     def addAnchorsWithData(numberOfAnchors, dataspaceName, schemaSetName, anchorNamePrefix, data) {
         (1..numberOfAnchors).each {
-            cpsAdminService.createAnchor(dataspaceName, schemaSetName, anchorNamePrefix + it)
-            cpsDataService.saveData(dataspaceName, anchorNamePrefix + it, data, OffsetDateTime.now())
+            cpsAnchorService.createAnchor(dataspaceName, schemaSetName, anchorNamePrefix + it)
+            cpsDataService.saveData(dataspaceName, anchorNamePrefix + it, data.replace("Easons", "Easons-"+it.toString()), OffsetDateTime.now())
+        }
+    }
+
+    def createJsonArray(name, numberOfElements, keyName, keyValuePrefix, dataPerKey) {
+        def json = '{"' + name + '":['
+        (1..numberOfElements).each {
+            json += '{"' + keyName + '":"' + keyValuePrefix + '-' + it + '"'
+            if (!dataPerKey.isEmpty()) {
+                json += ',' + dataPerKey
+            }
+            json += '}'
+            if (it < numberOfElements) {
+                json += ','
+            }
         }
+        json += ']}'
     }
+
+    def createLeafList(name, numberOfElements, valuePrefix) {
+        def json = '"' + name + '":['
+        (1..numberOfElements).each {
+            json += '"' + valuePrefix + '-' + it + '"'
+            if (it < numberOfElements) {
+                json += ','
+            }
+        }
+        json += ']'
+    }
+
 }