2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.ccsdk.sli.northbound.dmaapclient;
23 import org.apache.commons.io.FileUtils;
24 import org.junit.Test;
27 import java.io.IOException;
28 import java.io.InputStream;
29 import java.lang.reflect.Field;
31 import java.util.Properties;
33 public class TestSdncEsrDmaapReceiver {
34 static String aaiInput = "{\"cambria.partition\":\"AAI\",\n" +
35 " \"event-header\":\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" +
52 " \"thirdparty-sdnc-id\":\"IP-WAN-Controller-1\",\n" +
53 " \"relationship-list\":\n" +
55 " \"relationship\":\n" +
58 " \"related-to\":\"pnf\",\n" +
59 " \"relationship-data\":\n" +
62 " \"relationship-value\":\"a8098c1a-f86e-11da-bd1a-00112444be1e\",\n" +
63 " \"relationship-key\":\"pnf.pnf-name\"\n" +
66 " \"related-link\":\"aai/v11/network/pnfs/pnf/a8098c1a-f86e-11da-bd1a-00112444be1e\"\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" +
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" +
104 public void testProcessMsgInvalidEventType() throws Exception {
105 String DMAAPLISTENERROOT = "DMAAPLISTENERROOT";
106 File directory = new File("lib");
108 if (! directory.exists()){
112 File source = new File("src/main/resources");
113 File dest = new File("lib/");
115 FileUtils.copyDirectory(source, dest);
116 } catch (IOException e) {
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);
130 Properties props = new Properties();
131 InputStream propStr = TestSdncEsrDmaapReceiver.class.getResourceAsStream("/dmaap-consumer-esrsysteminfo.properties");
135 SdncAaiDmaapConsumer consumer = new SdncAaiDmaapConsumer();
137 consumer.init(props, "src/test/resources/dmaap-consumer-esrsysteminfo.properties");
138 consumer.processMsg(aaiInput);