2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ============LICENSE_END=========================================================
18 package org.onap.dcae.runtime.core;
20 import org.junit.Before;
21 import org.junit.Test;
23 import java.util.HashSet;
26 import static org.junit.Assert.*;
28 public class TestFlowGraph {
30 private FlowGraph<Node, Edge> flowGraph;
35 public void setUp() throws Exception{
36 flowGraph = new FlowGraph("random_id","anyName",true,"someDescription");
37 node_1 = new Node("comp1234", "component_1", "<comp-string>");
38 node_2 = new Node("comp5678", "component_2", "<comp-string>");
39 flowGraph.addNode(node_1);
40 flowGraph.addNode(node_2);
44 public void testFlowGraphProperties() throws Exception{
45 assertEquals("random_id",flowGraph.getId());
46 assertEquals("anyName",flowGraph.getName());
47 assertEquals("someDescription",flowGraph.getDescription());
48 assertTrue(flowGraph.isMain());
52 public void testAddNodeToGraph() throws Exception{
53 Set<Node> nodes = new HashSet<Node>();
57 assertEquals(2,flowGraph.getNodeSize());
58 assertEquals(nodes,flowGraph.getNodes());
63 public void testAddEdgeToGraph() throws Exception{
64 Edge edge_1 = Helper.getTestEdge();
65 flowGraph.addEdge(node_1,node_2,edge_1);
66 assertEquals(1, flowGraph.getEdgeSize());
67 assertEquals(edge_1, flowGraph.getEdge(node_1,node_2));
71 public void testRemoveNodeFromGraph() throws Exception{
72 flowGraph.removeNode(node_1);
73 assertEquals(1,flowGraph.getNodeSize());
74 assertEquals(node_2,flowGraph.getNodes().toArray()[0]);
78 public void testRemoveEdgeFromGraph() throws Exception{
79 Edge edge_1 = Helper.getTestEdge();
80 flowGraph.addEdge(node_1,node_2,edge_1);
81 flowGraph.removeEdge(edge_1);
82 assertEquals(0,flowGraph.getEdgeSize());
86 public void testDummyNodeInEdge() throws Exception{
87 Node node_dummy = new Node("dummy", "component_dummy", "<comp-string>");
88 Edge edge_1 = Helper.getTestEdge();
89 Edge edge_2 = Helper.getTestEdge();
90 Edge edge_3 = Helper.getTestEdge();
91 flowGraph.addEdge(node_dummy,node_2,edge_1);
92 flowGraph.addEdge(node_2,node_dummy,edge_2);
93 flowGraph.addEdge(node_1,node_dummy,edge_3);
94 System.out.println(flowGraph.getNodes());
95 System.out.println(flowGraph.getEdges());