update link to upper-constraints.txt
[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.onap.dmaap.datarouter.node.config.NodeConfig;
30 import org.onap.dmaap.datarouter.node.config.PathFinder;
31 import org.powermock.modules.junit4.PowerMockRunner;
32
33 @RunWith(PowerMockRunner.class)
34 public class PathFinderTest {
35
36     @Test
37     public void Given_Unknown_From_Node_Returns_Null() {
38         new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
39                 new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-4", "dr-node-3", "dr-node-2")});
40     }
41
42     @Test
43     public void Given_Unknown_Destination_Node_Returns_Null() {
44         new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
45                 new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-1", "dr-node-5", "dr-node-2")});
46     }
47
48     @Test
49     public void Given_Duplicate_Next_Hop_Returns_Null() {
50         PathFinder p = new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
51                 new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-1", "dr-node-3", "dr-node-2"),
52                         new NodeConfig.ProvHop("dr-node-1", "dr-node-3", "dr-node-2")});
53         assertThat(p.getErrors().length, is(1));
54         assertNotNull(p.getPath("dr-node-3"));
55         assertThat(p.getPath("dr-node-5").length(), is(0));
56     }
57
58     @Test
59     public void Given_Unknown_Via_Node_Returns_Null() {
60         new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
61                 new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-1", "dr-node-3", "dr-node-4")});
62     }
63
64     @Test
65     public void Given_Dest_Equals_Via_Bad_Hop_Defined() {
66         new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
67                 new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-1", "dr-node-2", "dr-node-2")});
68     }
69
70     @Test
71     public void Given_Valid_Path_Defined_Success() {
72         new PathFinder("dr-node-1", new String[]{"dr-node-1", "dr-node-2", "dr-node-3"},
73                 new NodeConfig.ProvHop[]{new NodeConfig.ProvHop("dr-node-1", "dr-node-3+", "dr-node-2")});
74     }
75
76
77 }