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