summaryrefslogtreecommitdiffstats
path: root/cps-ri/src/test
diff options
context:
space:
mode:
authorToineSiebelink <toine.siebelink@est.tech>2021-01-25 18:46:20 +0000
committerputhuparambil.aditya <aditya.puthuparambil@bell.ca>2021-01-27 16:01:33 +0000
commit099f89eda3b0c94d20612ebf1d62795ab7dc833a (patch)
tree9ac4eeb64c92bdf8b4de1773dcfd195158b30a6c /cps-ri/src/test
parent34afca00d1f8b2fabe7708c76be714687e136d68 (diff)
Draft at proposal where the DataNodeBuilder 'replaces' yang Utils to buidl a DataNode
Most complexity is related to immutable collections and the fact taht we are adding data while recursing over the orignal data in an uncontrolled order. I cleaned it up as best I could with no logic in DataNode. Espcially the handling of LitLeaves requires some specialed handling. Thsi is just a draft solution for that I still propose we get back to that in dedicated user stories for handling the various types of Yang elements Hope this helps... Issue-ID: CPS-137 Signed-off-by: ToineSiebelink <toine.siebelink@est.tech> Change-Id: Iab7cfcff67412c01bcdab95e707e1350bf60fab1
Diffstat (limited to 'cps-ri/src/test')
-rw-r--r--cps-ri/src/test/java/org/onap/cps/spi/impl/CpsDataPersistenceServiceTest.java17
1 files changed, 9 insertions, 8 deletions
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 4501e5f0ce..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;
@@ -35,6 +34,7 @@ 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.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)
@@ -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();
}
}