Decouple anchor from fragment in persistence module

Issue-ID: CPS-161
Change-Id: Ia446b26ee4eca9281e86bd2be3dd6836aa201597
Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
diff --git a/cps-ri/src/test/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceTest.java b/cps-ri/src/test/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceTest.java
index 7497526..e5aac1e 100644
--- a/cps-ri/src/test/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceTest.java
+++ b/cps-ri/src/test/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceTest.java
@@ -29,15 +29,15 @@
 import org.junit.runner.RunWith;
 import org.onap.cps.DatabaseTestContainer;
 import org.onap.cps.spi.CpsAdminPersistenceService;
+import org.onap.cps.spi.entities.AnchorEntity;
 import org.onap.cps.spi.entities.Dataspace;
-import org.onap.cps.spi.entities.Fragment;
 import org.onap.cps.spi.exceptions.AnchorAlreadyDefinedException;
 import org.onap.cps.spi.exceptions.DataspaceAlreadyDefinedException;
 import org.onap.cps.spi.exceptions.DataspaceNotFoundException;
 import org.onap.cps.spi.exceptions.SchemaSetNotFoundException;
 import org.onap.cps.spi.model.Anchor;
+import org.onap.cps.spi.repository.AnchorRepository;
 import org.onap.cps.spi.repository.DataspaceRepository;
-import org.onap.cps.spi.repository.FragmentRepository;
 import org.onap.cps.spi.repository.SchemaSetRepository;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
@@ -69,7 +69,7 @@
     private CpsAdminPersistenceService cpsAdminPersistenceService;
 
     @Autowired
-    private FragmentRepository fragmentRepository;
+    private AnchorRepository anchorRepository;
 
     @Autowired
     private DataspaceRepository dataspaceRepository;
@@ -102,13 +102,13 @@
 
         // validate anchor persisted
         final Dataspace dataspace = dataspaceRepository.findByName(DATASPACE_NAME).orElseThrow();
-        final Fragment anchor =
-            fragmentRepository.findByDataspaceAndAnchorName(dataspace, ANCHOR_NAME_NEW).orElseThrow();
+        final AnchorEntity anchorEntity =
+            anchorRepository.findByDataspaceAndName(dataspace, ANCHOR_NAME_NEW).orElseThrow();
 
-        assertNotNull(anchor.getId());
-        assertEquals(ANCHOR_NAME_NEW, anchor.getAnchorName());
-        assertEquals(DATASPACE_NAME, anchor.getDataspace().getName());
-        assertEquals(SCHEMA_SET_NAME2, anchor.getSchemaSet().getName());
+        assertNotNull(anchorEntity.getId());
+        assertEquals(ANCHOR_NAME_NEW, anchorEntity.getName());
+        assertEquals(DATASPACE_NAME, anchorEntity.getDataspace().getName());
+        assertEquals(SCHEMA_SET_NAME2, anchorEntity.getSchemaSet().getName());
     }
 
     @Test(expected = DataspaceNotFoundException.class)
diff --git a/cps-ri/src/test/resources/data/anchor.sql b/cps-ri/src/test/resources/data/anchor.sql
index 5507559..1d9b4b1 100644
--- a/cps-ri/src/test/resources/data/anchor.sql
+++ b/cps-ri/src/test/resources/data/anchor.sql
@@ -4,6 +4,6 @@
 INSERT INTO SCHEMA_SET (ID, NAME, DATASPACE_ID) VALUES
     (2001, 'SCHEMA-SET-001', 1001), (2002, 'SCHEMA-SET-002', 1001);
 
-INSERT INTO FRAGMENT (ID, XPATH, ANCHOR_NAME, DATASPACE_ID, SCHEMA_SET_ID) VALUES
-    (3001, 'ANCHOR-001', 'ANCHOR-001', 1001, 2001),
-    (3002, 'ANCHOR-002', 'ANCHOR-002', 1001, 2002);
\ No newline at end of file
+INSERT INTO ANCHOR (ID, NAME, DATASPACE_ID, SCHEMA_SET_ID) VALUES
+    (3001, 'ANCHOR-001', 1001, 2001),
+    (3002, 'ANCHOR-002', 1001, 2002);
\ No newline at end of file
diff --git a/cps-ri/src/test/resources/data/clear-all.sql b/cps-ri/src/test/resources/data/clear-all.sql
index 522f9e6..9aee604 100644
--- a/cps-ri/src/test/resources/data/clear-all.sql
+++ b/cps-ri/src/test/resources/data/clear-all.sql
@@ -1,6 +1,7 @@
 DELETE FROM FRAGMENT;
--- clear all via dataspace table cleanup
--- all other data will be removed by cascade
+DELETE FROM ANCHOR;
 DELETE FROM DATASPACE;
--- explicit clear
+-- following tables are cleared by CASCADE constraint:
+-- SCHEMA_SET
+-- SCHEMA_SET_YANG_RESOURCES
 DELETE FROM YANG_RESOURCE;