Adding more DR-Node unit tests
[dmaap/datarouter.git] / datarouter-node / src / test / java / org / onap / dmaap / datarouter / node / PathFinderTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
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  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.dmaap.datarouter.node;
22
23 import static org.hamcrest.core.Is.is;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertThat;
26
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.powermock.modules.junit4.PowerMockRunner;
30
31 @RunWith(PowerMockRunner.class)
32 public class PathFinderTest {
33
34     @Test
35     public void Given_Unknown_From_Node_Returns_Null() {
36         new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
37                 new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-4", "dr-node-3", "dr-node-2")});
38     }
39
40     @Test
41     public void Given_Unknown_Destination_Node_Returns_Null() {
42         new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
43                 new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-1", "dr-node-5", "dr-node-2")});
44     }
45
46     @Test
47     public void Given_Duplicate_Next_Hop_Returns_Null() {
48         PathFinder p = new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
49                 new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-1", "dr-node-3", "dr-node-2"),
50                         new NodeConfig.ProvHop("dr-node-1", "dr-node-3", "dr-node-2")});
51         assertThat(p.getErrors().length, is(1));
52         assertNotNull(p.getPath("dr-node-3"));
53         assertThat(p.getPath("dr-node-5").length(), is(0));
54     }
55
56     @Test
57     public void Given_Unknown_Via_Node_Returns_Null() {
58         new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
59                 new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-1", "dr-node-3", "dr-node-4")});
60     }
61
62     @Test
63     public void Given_Dest_Equals_Via_Bad_Hop_Defined() {
64         new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
65                 new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-1", "dr-node-2", "dr-node-2")});
66     }
67
68     @Test
69     public void Given_Valid_Path_Defined_Success() {
70         new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
71                 new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-1", "dr-node-3+", "dr-node-2")});
72     }
73
74
75 }