Fixing falling unit test in provData
[dmaap/datarouter.git] / datarouter-node / src / test / java / org / onap / dmaap / datarouter / node / ProvDataTest.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 package org.onap.dmaap.datarouter.node;
21
22
23 import org.junit.Assert;
24 import org.junit.Test;
25 import org.junit.runner.RunWith;
26 import org.powermock.modules.junit4.PowerMockRunner;
27
28 import java.io.ByteArrayInputStream;
29 import java.io.InputStreamReader;
30 import java.io.Reader;
31 import java.nio.charset.StandardCharsets;
32
33 import static junit.framework.Assert.assertEquals;
34 import static junit.framework.Assert.assertNull;
35
36 @RunWith(PowerMockRunner.class)
37 public class ProvDataTest {
38
39
40     @Test
41     public void Validate_Values_Are_Set_Correctly_Through_ProvData_Constuctor() throws Exception {
42         String InternalProvData =
43                 "{" +
44                 "\"ingress\":[{" +
45                   "\"feedid\":1," +
46                   "\"subnet\":\"\"," +
47                   "\"user\":\"\"," +
48                   "\"node\":\"node\"" +
49                 "}]," +
50                 "\"routing\":[{" +
51                   "\"from\":\"172.10.10.10\"," +
52                   "\"to\":\"172.10.10.12\"," +
53                   "\"via\":\"172.10.10.11\"" +
54                 "}]," +
55                 "\"subscriptions\":[{" +
56                   "\"subid\":1," +
57                   "\"suspend\":false," +
58                   "\"delivery\":{" +
59                     "\"use100\":true," +
60                     "\"password\":\"PASSWORD\"," +
61                     "\"user\":\"LOGIN\"," +
62                     "\"url\":\"http://172.18.0.2:7070\"" +
63                   "}," +
64                   "\"last_mod\":1553608460000," +
65                   "\"subscriber\":\"PMMAPER\"," +
66                   "\"feedid\":1," +
67                   "\"decompress\":false," +
68                   "\"groupid\":1," +
69                   "\"metadataOnly\":false," +
70                   "\"follow_redirect\":false," +
71                   "\"links\":{" +
72                     "\"feed\":\"https://dmaap-dr-prov/feed/1\"" +
73                     ",\"log\":\"https://dmaap-dr-prov/sublog/1\"" +
74                     ",\"self\":\"https://dmaap-dr-prov/subs/1\"" +
75                   "}," +
76                   "\"created_date\":1553608460000," +
77                   "\"privilegedSubscriber\":false" +
78                 "}]," +
79                 "\"feeds\":[{" +
80                   "\"suspend\":false," +
81                   "\"groupid\":0," +
82                   "\"description\":\"Default feed\"," +
83                   "\"version\":\"m1.0\"," +
84                   "\"authorization\":{" +
85                     "\"endpoint_addrs\":[\"172.10.10.20\"]," +
86                     "\"classification\":\"unclassified\"," +
87                     "\"endpoint_ids\":[{" +
88                       "\"password\":\"password\"," +
89                       "\"id\":\"user\"" +
90                     "}]" +
91                   "}," +
92                   "\"last_mod\":1553608454000," +
93                   "\"deleted\":false," +
94                   "\"feedid\":1," +
95                   "\"name\":\"CSIT_Test2\"" +
96                   ",\"business_description\":\"Default Feed\"" +
97                   ",\"publisher\":\"dradmin\"" +
98                   ",\"links\":{" +
99                     "\"subscribe\":\"https://dmaap-dr-prov/subscribe/1\"," +
100                     "\"log\":\"https://dmaap-dr-prov/feedlog/1\"," +
101                     "\"publish\":\"https://dmaap-dr-prov/publish/1\"," +
102                     "\"self\":\"https://dmaap-dr-prov/feed/1\"" +
103                   "}," +
104                   "\"created_date\":1553608454000" +
105                 "}]," +
106                 "\"groups\":[]," +
107                 "\"parameters\":{" +
108                   "\"NODES\":[\"dmaap-dr-node\"]," +
109                   "\"PROV_DOMAIN\":\"\"" +
110                 "}," +
111                 "\"egress\":{" +
112                 "\"1\":1" +
113                 "}" +
114                 "}" ;
115         Reader r = new InputStreamReader(new ByteArrayInputStream(InternalProvData.getBytes(StandardCharsets.UTF_8)));
116         ProvData pd = new ProvData(r);
117
118         assertEquals(pd.getNodes().length, 1);
119         assertEquals(pd.getNodes()[0].getCName(), "dmaap-dr-node.");
120
121         assertEquals(pd.getFeedUsers().length, 1);
122         assertEquals(pd.getFeedUsers()[0].getUser(), "user");
123         assertEquals(pd.getFeedUsers()[0].getFeedId(), "1");
124         assertEquals(pd.getFeeds().length, 1);
125         assertEquals(pd.getFeeds()[0].getId(), "1");
126         assertEquals(pd.getFeedSubnets().length, 1);
127         assertEquals(pd.getFeedSubnets()[0].getFeedId(), "1");
128         assertEquals(pd.getFeedSubnets()[0].getCidr(), "172.10.10.20");
129         assertEquals(pd.getFeedSubnets()[0].getCidr(), "172.10.10.20");
130         assertEquals(pd.getSubscriptions()[0].getFeedId(), "1");
131         assertEquals(pd.getSubscriptions()[0].getSubId(), "1");
132         assertEquals(pd.getSubscriptions()[0].getAuthUser(), "LOGIN");
133         assertEquals(pd.getSubscriptions()[0].getURL(), "http://172.18.0.2:7070");
134         assertEquals(pd.getForceEgress().length, 1);
135         assertEquals(pd.getForceEgress()[0].getNode(), "1");
136         assertEquals(pd.getForceEgress()[0].getSubId(), "1");
137         assertEquals(pd.getForceIngress().length, 1);
138         assertEquals(pd.getForceIngress()[0].getFeedId(), "1");
139         assertNull(pd.getForceIngress()[0].getSubnet());
140         assertNull(pd.getForceIngress()[0].getUser());
141         assertEquals(pd.getHops().length, 1);
142         assertEquals(pd.getHops()[0].getFrom(), "172.10.10.10");
143         assertEquals(pd.getHops()[0].getTo(), "172.10.10.12");
144         assertEquals(pd.getHops()[0].getVia(), "172.10.10.11");
145         assertEquals(pd.getParams().length, 1);
146         assertEquals(pd.getParams()[0].getName(), "PROV_DOMAIN");
147     }
148 }