623c964262aa5b251c1ee83bcc11a000b73d3590
[ccsdk/sli.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - CCSDK
4  * ================================================================================
5  * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.ccsdk.sli.northbound.dmaapclient;
22
23 import org.apache.commons.io.FileUtils;
24 import org.junit.Test;
25
26 import java.io.File;
27 import java.io.IOException;
28 import java.io.InputStream;
29 import java.lang.reflect.Field;
30 import java.util.Map;
31 import java.util.Properties;
32
33 public class TestSdncEsrDmaapReceiver {
34     static String aaiInput = "{\"cambria.partition\":\"AAI\",\n" +
35             "    \"event-header\":\n" +
36             "    {\n" +
37             "      \"severity\":\"NORMAL\",\n" +
38             "      \"entity-type\":\"esr-thirdparty-sdnc\",\n" +
39             "      \"top-entity-type\":\"esr-thirdparty-sdnc\",\n" +
40             "      \"entity-link\":\"aai/v11/external-system/esr-thirdparty-sdnc-list/esr-thirdparty-sdnc/IP-WAN-Controller-1\",\n" +
41             "      \"event-type\":\"AAI-EVENT\",\n" +
42             "      \"domain\":\"dev\",\n" +
43             "      \"action\":\"UPDATE\",\n" +
44             "      \"sequence-number\":\"0\",\n" +
45             "      \"id\":\"bf4df797-759a-4684-a63c-393b7d40ed55\",\n" +
46             "      \"source-name\":\"postman\",\n" +
47             "      \"version\":\"v11\",\n" +
48             "      \"timestamp\":\"20180104-09:57:58:721\"\n" +
49             "    },\n" +
50             "    \"entity\":\n" +
51             "    {\n" +
52             "      \"thirdparty-sdnc-id\":\"IP-WAN-Controller-1\",\n" +
53             "      \"relationship-list\":\n" +
54             "        {\n" +
55             "          \"relationship\":\n" +
56             "          [\n" +
57             "            {\n" +
58             "              \"related-to\":\"pnf\",\n" +
59             "      \"relationship-data\":\n" +
60             "              [\n" +
61             "              {\n" +
62             "                \"relationship-value\":\"a8098c1a-f86e-11da-bd1a-00112444be1e\",\n" +
63             "                \"relationship-key\":\"pnf.pnf-name\"\n" +
64             "              }\n" +
65             "              ],\n" +
66             "              \"related-link\":\"aai/v11/network/pnfs/pnf/a8098c1a-f86e-11da-bd1a-00112444be1e\"\n" +
67             "            }\n" +
68             "          ]\n" +
69             "        },\n" +
70             "      \"resource-version\":\"1515059878654\",\n" +
71             "      \"location\":\"Core\",\n" +
72             "      \"product-name\":\"AC-WAN\",\n" +
73             "      \"esr-system-info-list\":\n" +
74             "      {\"esr-system-info\":\n" +
75             "      [\n" +
76             "        {\n" +
77             "          \"esr-system-info-id\":\"IP-WAN-Controller-ESR-1\",\n" +
78             "          \"system-type\":\"example-system-type-val-12078\",\n" +
79             "          \"service-url\":\"https://182.2.61.24:18002\",\n" +
80             "          \"ssl-cacert\":\"example-ssl-cacert-val-20589\",\n" +
81             "          \"type\":\"WAN\",\n" +
82             "          \"ssl-insecure\":true,\n" +
83             "          \"system-status\":\"example-system-status-val-23435\",\n" +
84             "          \"version\":\"V3R1\",\n" +
85             "          \"passive\":true,\n" +
86             "          \"password\":\"Admin@12345\",\n" +
87             "          \"protocol\":\"RESTCONF\",\n" +
88             "          \"ip-address\":\"182.2.61.24\",\n" +
89             "          \"cloud-domain\":\"example-cloud-domain-val-76077\",\n" +
90             "          \"user-name\":\"admin\",\n" +
91             "          \"system-name\":\"IP-WAN-Controller\",\n" +
92             "          \"port\":\"18002\",\n" +
93             "          \"vendor\":\"IP-WAN\",\n" +
94             "          \"resource-version\":\"1515059878666\",\n" +
95             "          \"remote-path\":\"example-remotepath-val-5833\",\n" +
96             "          \"default-tenant\":\"example-default-tenant-val-71148\"\n" +
97             "        }\n" +
98             "      ]\n" +
99             "    }\n" +
100             "  }\n" +
101             " }";
102
103     @Test
104     public void testProcessMsgInvalidEventType() throws Exception {
105         String DMAAPLISTENERROOT = "DMAAPLISTENERROOT";
106         File directory = new File("lib");
107
108         if (! directory.exists()){
109             directory.mkdir();
110         }
111
112         File source = new File("src/main/resources");
113         File dest = new File("lib/");
114         try {
115             FileUtils.copyDirectory(source, dest);
116         } catch (IOException e) {
117             e.printStackTrace();
118         }
119
120         try {
121             Map<String, String> env = System.getenv();
122             Class<?> cl = env.getClass();
123             Field field = cl.getDeclaredField("m");
124             field.setAccessible(true);
125             Map<String, String> writableEnv = (Map<String, String>) field.get(env);
126             writableEnv.put(DMAAPLISTENERROOT, ".");
127         } catch (Exception e) {
128             throw new IllegalStateException("Failed to set environment variable", e);
129         }
130         Properties props = new Properties();
131         InputStream propStr = TestSdncEsrDmaapReceiver.class.getResourceAsStream("/dmaap-consumer-esrsysteminfo.properties");
132
133         props.load(propStr);
134
135         SdncAaiDmaapConsumer consumer = new SdncAaiDmaapConsumer();
136
137         consumer.init(props, "src/test/resources/dmaap-consumer-esrsysteminfo.properties");
138         consumer.processMsg(aaiInput);
139     }
140 }