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