Unit test cases for DeadLockDetectionUtil, CipherUtil and CassaLockStore
[music.git] / music-core / src / test / java / org / onap / music / main / DeadlockDetectionUtilTest.java
1 /*
2  * ============LICENSE_START==========================================
3  * org.onap.music
4  * ===================================================================
5  * Copyright (c) 2019 IBM Intellectual Property
6  * ===================================================================
7  *  Licensed under the Apache License, Version 2.0 (the "License");
8  *  you may not use this file except in compliance with the License.
9  *  You may obtain a copy of the License at
10  *
11  *     http://www.apache.org/licenses/LICENSE-2.0
12  *
13  *  Unless required by applicable law or agreed to in writing, software
14  *  distributed under the License is distributed on an "AS IS" BASIS,
15  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  *  See the License for the specific language governing permissions and
17  *  limitations under the License.
18  *
19  * ============LICENSE_END=============================================
20  * ====================================================================
21  */
22
23 package org.onap.music.main;
24
25 import static org.junit.Assert.assertEquals;
26
27 import java.io.ByteArrayOutputStream;
28 import java.io.PrintStream;
29
30 import org.junit.Before;
31 import org.junit.Test;
32 //import org.junit.experimental.runners.Enclosed;
33 //import org.junit.runner.RunWith;
34 import org.onap.music.main.DeadlockDetectionUtil.OwnershipType;
35
36 //@RunWith(Enclosed.class)
37 public class DeadlockDetectionUtilTest {
38         private DeadlockDetectionUtil ddu;
39
40         @Before
41         public void setup() {
42                 ddu = new DeadlockDetectionUtil();
43         }
44
45         @Test
46         public void testListAllNodes() {
47                 ddu = new DeadlockDetectionUtil();
48                 ddu.setExisting("r1", "o2", OwnershipType.ACQUIRED);
49                 ddu.setExisting("r3", "o2", OwnershipType.ACQUIRED);
50
51                 ByteArrayOutputStream outContent = new ByteArrayOutputStream();
52                 System.setOut(new PrintStream(outContent));
53                 ddu.listAllNodes();
54
55                 /*
56                  * String expectedOutput = "In DeadlockDetectionUtil: \n" +
57                  * "            o2 : Node [id=o2, links=r3, visited=false, onStack=false]\n" +
58                  * "            r3 : Node [id=r3, links=, visited=false, onStack=false]\n" +
59                  * "            r1 : Node [id=r1, links=o2, visited=false, onStack=false]\n";
60                  * assertEquals(expectedOutput, outContent.toString());
61                  * 
62                  * ddu = new DeadlockDetectionUtil(); ddu.setExisting("111", "222",
63                  * OwnershipType.CREATED); ddu.setExisting("333", "222", OwnershipType.CREATED);
64                  * outContent = new ByteArrayOutputStream(); System.setOut(new
65                  * PrintStream(outContent)); ddu.listAllNodes(); expectedOutput =
66                  * "In DeadlockDetectionUtil: \n" +
67                  * "    o222 : Node [id=o222, links=r111r333, visited=false, onStack=false]\n" +
68                  * "    r333 : Node [id=r333, links=, visited=false, onStack=false]\n" +
69                  * "    r111 : Node [id=r111, links=, visited=false, onStack=false]";
70                  * assertEquals(expectedOutput, outContent.toString());
71                  */
72         }
73
74         @Test
75         public void testcheckForDeadlock() {
76                 ddu = new DeadlockDetectionUtil();
77                 ddu.setExisting("111", "222", DeadlockDetectionUtil.OwnershipType.ACQUIRED);
78                 ddu.setExisting("333", "444", DeadlockDetectionUtil.OwnershipType.ACQUIRED);
79                 assertEquals(false, ddu.checkForDeadlock("111", "444", DeadlockDetectionUtil.OwnershipType.CREATED));
80
81                 ddu = new DeadlockDetectionUtil();
82                 ddu.setExisting("111", "222", DeadlockDetectionUtil.OwnershipType.ACQUIRED);
83                 ddu.setExisting("333", "444", DeadlockDetectionUtil.OwnershipType.ACQUIRED);
84                 ddu.setExisting("333", "222", DeadlockDetectionUtil.OwnershipType.CREATED);
85                 assertEquals(true, ddu.checkForDeadlock("111", "444", DeadlockDetectionUtil.OwnershipType.CREATED));
86         }
87 }