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
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.dmaap.datarouter.node;
23 import static org.hamcrest.core.Is.is;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertThat;
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;
33 @RunWith(PowerMockRunner.class)
34 public class PathFinderTest {
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")});
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")});
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));
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")});
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")});
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")});