summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/test
diff options
context:
space:
mode:
authorRuslan Kashapov <ruslan.kashapov@pantheon.tech>2020-11-24 11:13:43 +0200
committerRuslan Kashapov <ruslan.kashapov@pantheon.tech>2020-12-17 14:40:53 +0200
commit8a1e3c9f90d2111835460fc042b4a63f93b80384 (patch)
treec26fa83be590816686d239580e161cc04e298197 /cps-ri/src/test
parent84ac94d2f3f9ebd6a3a7befa244beef851eac126 (diff)
Associate anchor to schema set
- db schema updated - db layer tests provided for ancor create and reading by dataspace - anchor model is removed from rest api as extra - api/spi updated to use string references instead of object Issue-ID: CPS-99 Change-Id: Ideeb83fa9e91ec1816308d8327a6589b999c64c5 Signed-off-by: Ruslan Kashapov <ruslan.kashapov@pantheon.tech>
Diffstat (limited to 'cps-ri/src/test')
-rw-r--r--cps-ri/src/test/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceTest.java143
-rw-r--r--cps-ri/src/test/resources/data/anchor.sql9
-rw-r--r--cps-ri/src/test/resources/data/clear-all.sql1
3 files changed, 153 insertions, 0 deletions
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
new file mode 100644
index 0000000000..455369d2cf
--- /dev/null
+++ b/cps-ri/src/test/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceTest.java
@@ -0,0 +1,143 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2020 Pantheon.tech
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.spi.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collection;
+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.entities.Dataspace;
+import org.onap.cps.spi.entities.Fragment;
+import org.onap.cps.spi.exceptions.AnchorAlreadyDefinedException;
+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.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;
+import org.springframework.test.context.jdbc.Sql;
+import org.springframework.test.context.jdbc.SqlGroup;
+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";
+
+ private static final String DATASPACE_NAME = "DATASPACE-001";
+ private static final String EMPTY_DATASPACE_NAME = "DATASPACE-002";
+ private static final String NON_EXISTING_DATASPACE_NAME = "NON EXISTING DATASPACE";
+ private static final String NON_EXISTING_SCHEMA_SET_NAME = "NON EXISTING SCHEMA SET";
+ private static final String SCHEMA_SET_NAME1 = "SCHEMA-SET-001";
+ private static final String SCHEMA_SET_NAME2 = "SCHEMA-SET-002";
+ private static final String ANCHOR_NAME1 = "ANCHOR-001";
+ private static final String ANCHOR_NAME2 = "ANCHOR-002";
+ private static final String ANCHOR_NAME_NEW = "ANCHOR-NEW";
+
+ @ClassRule
+ public static DatabaseTestContainer databaseTestContainer = DatabaseTestContainer.getInstance();
+
+ @Autowired
+ private CpsAdminPersistenceService cpsAdminPersistenceService;
+
+ @Autowired
+ private FragmentRepository fragmentRepository;
+
+ @Autowired
+ private DataspaceRepository dataspaceRepository;
+
+ @Autowired
+ private SchemaSetRepository schemaSetRepository;
+
+ @Test
+ @SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
+ public void testCreateAnchor() {
+ cpsAdminPersistenceService.createAnchor(DATASPACE_NAME, SCHEMA_SET_NAME2, ANCHOR_NAME_NEW);
+
+ // validate anchor persisted
+ final Dataspace dataspace = dataspaceRepository.findByName(DATASPACE_NAME).orElseThrow();
+ final Fragment anchor =
+ fragmentRepository.findByDataspaceAndAnchorName(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());
+ }
+
+ @Test(expected = DataspaceNotFoundException.class)
+ @SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
+ public void testCreateAnchorAtNonExistingDataspace() {
+ cpsAdminPersistenceService.createAnchor(NON_EXISTING_DATASPACE_NAME, SCHEMA_SET_NAME2, ANCHOR_NAME_NEW);
+ }
+
+ @Test(expected = SchemaSetNotFoundException.class)
+ @SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
+ public void testCreateAnchorWithNonExistingSchemaSet() {
+ cpsAdminPersistenceService.createAnchor(DATASPACE_NAME, NON_EXISTING_SCHEMA_SET_NAME, ANCHOR_NAME_NEW);
+ }
+
+ @Test(expected = AnchorAlreadyDefinedException.class)
+ @SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
+ public void testCreateAnchorWithNameAlreadyDefined() {
+ cpsAdminPersistenceService.createAnchor(DATASPACE_NAME, SCHEMA_SET_NAME2, ANCHOR_NAME1);
+ }
+
+ @Test
+ @SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
+ public void testGetAnchorsByDataspace() {
+ final Collection<Anchor> anchors = cpsAdminPersistenceService.getAnchors(DATASPACE_NAME);
+
+ assertNotNull(anchors);
+ assertEquals(2, anchors.size());
+ assertTrue(anchors.contains(
+ Anchor.builder().name(ANCHOR_NAME1).schemaSetName(SCHEMA_SET_NAME1).dataspaceName(DATASPACE_NAME).build()
+ ));
+ assertTrue(anchors.contains(
+ Anchor.builder().name(ANCHOR_NAME2).schemaSetName(SCHEMA_SET_NAME2).dataspaceName(DATASPACE_NAME).build()
+ ));
+ }
+
+ @Test(expected = DataspaceNotFoundException.class)
+ @SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
+ public void testGetAnchorsByNonExistingDataspace() {
+ cpsAdminPersistenceService.getAnchors(NON_EXISTING_DATASPACE_NAME);
+ }
+
+ @Test
+ @SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
+ public void testGetAnchorsFromEmptyDataspace() {
+ final Collection<Anchor> anchors = cpsAdminPersistenceService.getAnchors(EMPTY_DATASPACE_NAME);
+
+ assertNotNull(anchors);
+ assertTrue(anchors.isEmpty());
+ }
+
+}
diff --git a/cps-ri/src/test/resources/data/anchor.sql b/cps-ri/src/test/resources/data/anchor.sql
new file mode 100644
index 0000000000..55075596be
--- /dev/null
+++ b/cps-ri/src/test/resources/data/anchor.sql
@@ -0,0 +1,9 @@
+INSERT INTO DATASPACE (ID, NAME) VALUES
+ (1001, 'DATASPACE-001'), (1002, 'DATASPACE-002');
+
+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
diff --git a/cps-ri/src/test/resources/data/clear-all.sql b/cps-ri/src/test/resources/data/clear-all.sql
index 3d93825ba1..522f9e617e 100644
--- a/cps-ri/src/test/resources/data/clear-all.sql
+++ b/cps-ri/src/test/resources/data/clear-all.sql
@@ -1,3 +1,4 @@
+DELETE FROM FRAGMENT;
-- clear all via dataspace table cleanup
-- all other data will be removed by cascade
DELETE FROM DATASPACE;