Add mod/runtimeapi
[dcaegen2/platform.git] / mod / runtimeapi / runtime-core / src / test / java / org / onap / dcae / runtime / core / TestFlowGraph.java
1 /*-
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
8  * 
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  * 
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=========================================================
17  */
18 package org.onap.dcae.runtime.core;
19
20 import org.junit.Before;
21 import org.junit.Test;
22
23 import java.util.HashSet;
24 import java.util.Set;
25
26 import static org.junit.Assert.*;
27
28 public class TestFlowGraph {
29
30     private FlowGraph<Node, Edge> flowGraph;
31     private Node node_1;
32     private Node node_2;
33
34     @Before
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);
41     }
42
43     @Test
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());
49     }
50
51     @Test
52     public void testAddNodeToGraph() throws Exception{
53         Set<Node> nodes = new HashSet<Node>();
54         nodes.add(node_1);
55         nodes.add(node_2);
56
57         assertEquals(2,flowGraph.getNodeSize());
58         assertEquals(nodes,flowGraph.getNodes());
59
60     }
61
62     @Test
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));
68     }
69
70     @Test
71     public void testRemoveNodeFromGraph() throws Exception{
72         flowGraph.removeNode(node_1);
73         assertEquals(1,flowGraph.getNodeSize());
74         assertEquals(node_2,flowGraph.getNodes().toArray()[0]);
75     }
76
77     @Test
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());
83     }
84
85     @Test
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());
96     }
97 }