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=========================================================
20 package org.onap.dmaap.datarouter.node;
23 import static junit.framework.Assert.assertEquals;
24 import static junit.framework.Assert.assertNull;
26 import java.io.ByteArrayInputStream;
27 import java.io.InputStreamReader;
28 import java.io.Reader;
29 import java.nio.charset.StandardCharsets;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32 import org.powermock.modules.junit4.PowerMockRunner;
34 @RunWith(PowerMockRunner.class)
35 public class ProvDataTest {
39 public void Validate_Values_Are_Set_Correctly_Through_ProvData_Constuctor() throws Exception {
40 String InternalProvData =
49 "\"from\":\"172.10.10.10\"," +
50 "\"to\":\"172.10.10.12\"," +
51 "\"via\":\"172.10.10.11\"" +
53 "\"subscriptions\":[{" +
55 "\"suspend\":false," +
58 "\"password\":\"PASSWORD\"," +
59 "\"user\":\"LOGIN\"," +
60 "\"url\":\"http://172.18.0.2:7070\"" +
62 "\"last_mod\":1553608460000," +
63 "\"subscriber\":\"PMMAPER\"," +
65 "\"decompress\":false," +
67 "\"metadataOnly\":false," +
68 "\"follow_redirect\":false," +
70 "\"feed\":\"https://dmaap-dr-prov/feed/1\"" +
71 ",\"log\":\"https://dmaap-dr-prov/sublog/1\"" +
72 ",\"self\":\"https://dmaap-dr-prov/subs/1\"" +
74 "\"created_date\":1553608460000," +
75 "\"privilegedSubscriber\":false" +
78 "\"suspend\":false," +
80 "\"description\":\"Default feed\"," +
81 "\"version\":\"m1.0\"," +
82 "\"authorization\":{" +
83 "\"endpoint_addrs\":[\"172.10.10.20\"]," +
84 "\"classification\":\"unclassified\"," +
85 "\"endpoint_ids\":[{" +
86 "\"password\":\"password\"," +
90 "\"last_mod\":1553608454000," +
91 "\"deleted\":false," +
93 "\"name\":\"CSIT_Test2\"" +
94 ",\"business_description\":\"Default Feed\"" +
95 ",\"publisher\":\"dradmin\"" +
97 "\"subscribe\":\"https://dmaap-dr-prov/subscribe/1\"," +
98 "\"log\":\"https://dmaap-dr-prov/feedlog/1\"," +
99 "\"publish\":\"https://dmaap-dr-prov/publish/1\"," +
100 "\"self\":\"https://dmaap-dr-prov/feed/1\"" +
102 "\"created_date\":1553608454000" +
106 "\"NODES\":[\"dmaap-dr-node\"]," +
107 "\"PROV_DOMAIN\":\"\"" +
113 Reader r = new InputStreamReader(new ByteArrayInputStream(InternalProvData.getBytes(StandardCharsets.UTF_8)));
114 ProvData pd = new ProvData(r);
116 assertEquals(pd.getNodes().length, 1);
117 assertEquals(pd.getNodes()[0].getCName(), "dmaap-dr-node.");
119 assertEquals(pd.getFeedUsers().length, 1);
120 assertEquals(pd.getFeedUsers()[0].getUser(), "user");
121 assertEquals(pd.getFeedUsers()[0].getFeedId(), "1");
122 assertEquals(pd.getFeeds().length, 1);
123 assertEquals(pd.getFeeds()[0].getId(), "1");
124 assertEquals(pd.getFeedSubnets().length, 1);
125 assertEquals(pd.getFeedSubnets()[0].getFeedId(), "1");
126 assertEquals(pd.getFeedSubnets()[0].getCidr(), "172.10.10.20");
127 assertEquals(pd.getFeedSubnets()[0].getCidr(), "172.10.10.20");
128 assertEquals(pd.getSubscriptions()[0].getFeedId(), "1");
129 assertEquals(pd.getSubscriptions()[0].getSubId(), "1");
130 assertEquals(pd.getSubscriptions()[0].getAuthUser(), "LOGIN");
131 assertEquals(pd.getSubscriptions()[0].getURL(), "http://172.18.0.2:7070");
132 assertEquals(pd.getForceEgress().length, 1);
133 assertEquals(pd.getForceEgress()[0].getNode(), "1");
134 assertEquals(pd.getForceEgress()[0].getSubId(), "1");
135 assertEquals(pd.getForceIngress().length, 1);
136 assertEquals(pd.getForceIngress()[0].getFeedId(), "1");
137 assertNull(pd.getForceIngress()[0].getSubnet());
138 assertNull(pd.getForceIngress()[0].getUser());
139 assertEquals(pd.getHops().length, 1);
140 assertEquals(pd.getHops()[0].getFrom(), "172.10.10.10");
141 assertEquals(pd.getHops()[0].getTo(), "172.10.10.12");
142 assertEquals(pd.getHops()[0].getVia(), "172.10.10.11");
143 assertEquals(pd.getParams().length, 1);
144 assertEquals(pd.getParams()[0].getName(), "PROV_DOMAIN");