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;
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;
import org.springframework.test.context.jdbc.Sql;
import org.springframework.test.context.junit4.SpringRunner;
-
@RunWith(SpringRunner.class)
@SpringBootTest
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();
@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)
}
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();
}
}