diff options
Diffstat (limited to 'cps-ri')
-rwxr-xr-x | cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java | 4 | ||||
-rw-r--r-- | cps-ri/src/test/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceTest.java | 21 |
2 files changed, 13 insertions, 12 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java index 6fc956c44d..bf551723f8 100755 --- a/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/FragmentRepository.java @@ -28,7 +28,7 @@ import org.checkerframework.checker.nullness.qual.NonNull; import org.onap.cps.spi.entities.AnchorEntity;
import org.onap.cps.spi.entities.DataspaceEntity;
import org.onap.cps.spi.entities.FragmentEntity;
-import org.onap.cps.spi.exceptions.NotFoundInDataspaceException;
+import org.onap.cps.spi.exceptions.DataNodeNotFoundException;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
@@ -44,7 +44,7 @@ public interface FragmentRepository extends JpaRepository<FragmentEntity, Long> default FragmentEntity getByDataspaceAndAnchorAndXpath(@NonNull DataspaceEntity dataspaceEntity,
@NonNull AnchorEntity anchorEntity, @NonNull String xpath) {
return findByDataspaceAndAnchorAndXpath(dataspaceEntity, anchorEntity, xpath)
- .orElseThrow(() -> new NotFoundInDataspaceException(dataspaceEntity.getName(), xpath));
+ .orElseThrow(() -> new DataNodeNotFoundException(dataspaceEntity.getName(), anchorEntity.getName(), xpath));
}
@Modifying
diff --git a/cps-ri/src/test/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceTest.java b/cps-ri/src/test/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceTest.java index de0942c3c3..5c402917d4 100644 --- a/cps-ri/src/test/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceTest.java +++ b/cps-ri/src/test/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceTest.java @@ -23,7 +23,6 @@ import static junit.framework.TestCase.assertEquals; import com.google.common.collect.ImmutableSet; import java.util.Arrays; -import java.util.Collections; import org.assertj.core.api.Assertions; import org.junit.ClassRule; import org.junit.Test; @@ -32,9 +31,10 @@ import org.onap.cps.DatabaseTestContainer; import org.onap.cps.spi.CpsDataPersistenceService; import org.onap.cps.spi.entities.FragmentEntity; import org.onap.cps.spi.exceptions.AnchorNotFoundException; +import org.onap.cps.spi.exceptions.DataNodeNotFoundException; import org.onap.cps.spi.exceptions.DataspaceNotFoundException; -import org.onap.cps.spi.exceptions.NotFoundInDataspaceException; import org.onap.cps.spi.model.DataNode; +import org.onap.cps.spi.model.DataNodeBuilder; import org.onap.cps.spi.repository.FragmentRepository; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -42,7 +42,6 @@ import org.springframework.dao.DataIntegrityViolationException; import org.springframework.test.context.jdbc.Sql; import org.springframework.test.context.junit4.SpringRunner; - @RunWith(SpringRunner.class) @SpringBootTest public class CpsDataPersistenceServiceTest { @@ -67,7 +66,6 @@ public class CpsDataPersistenceServiceTest { private static final long GRAND_CHILD_ID_4006 = 4006; private static final String GRAND_CHILD_XPATH1 = "/parent-1/child-1/grandchild-1"; - @ClassRule public static DatabaseTestContainer databaseTestContainer = DatabaseTestContainer.getInstance(); @@ -91,14 +89,16 @@ public class CpsDataPersistenceServiceTest { @Sql({CLEAR_DATA, SET_DATA}) public void testStoreDataNodeAtNonExistingDataspace() { cpsDataPersistenceService - .storeDataNode("Non Existing Dataspace Name", ANCHOR_NAME1, new DataNode()); + .storeDataNode("Non Existing Dataspace Name", ANCHOR_NAME1, + new DataNodeBuilder().build()); } @Test(expected = AnchorNotFoundException.class) @Sql({CLEAR_DATA, SET_DATA}) public void testStoreDataNodeAtNonExistingAnchor() { cpsDataPersistenceService - .storeDataNode(DATASPACE_NAME, "Non Existing Anchor Name", new DataNode()); + .storeDataNode(DATASPACE_NAME, "Non Existing Anchor Name", + new DataNodeBuilder().build()); } @Test(expected = DataIntegrityViolationException.class) @@ -159,7 +159,7 @@ public class CpsDataPersistenceServiceTest { .addChildDataNode(DATASPACE_NAME, ANCHOR_NAME1, PARENT_XPATH1, createDataNodeTree(CHILD_XPATH1)); } - @Test(expected = NotFoundInDataspaceException.class) + @Test(expected = DataNodeNotFoundException.class) @Sql({CLEAR_DATA, SET_DATA}) public void testAddAChildWithToAParentThatDoesNotExist() { cpsDataPersistenceService @@ -188,12 +188,13 @@ public class CpsDataPersistenceServiceTest { } private static DataNode createDataNodeTree(final String... xpaths) { - final DataNode dataNode = DataNode.builder().xpath(xpaths[0]).childDataNodes(Collections.emptySet()).build(); + final DataNodeBuilder dataNodeBuilder = new DataNodeBuilder().withXpath(xpaths[0]); if (xpaths.length > 1) { final String[] xPathsDescendant = Arrays.copyOfRange(xpaths, 1, xpaths.length); final DataNode childDataNode = createDataNodeTree(xPathsDescendant); - dataNode.setChildDataNodes(ImmutableSet.of(childDataNode)); + dataNodeBuilder.withChildDataNodes(ImmutableSet.of(childDataNode)); + } - return dataNode; + return dataNodeBuilder.build(); } } |