4c7c35f6649c9d66f4f0c27a537704473c3ae1ac
[dcaegen2/services.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : DATALAKE
4  * ================================================================================
5  * Copyright 2019 China Mobile
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.datalake.feeder.service.db;
22
23 import org.elasticsearch.action.ActionListener;
24 import org.elasticsearch.action.bulk.BulkResponse;
25 import org.elasticsearch.client.RestHighLevelClient;
26 import org.json.JSONObject;
27 import org.junit.Test;
28 import org.junit.runner.RunWith;
29 import org.mockito.InjectMocks;
30 import org.mockito.Mock;
31 import org.mockito.junit.MockitoJUnitRunner;
32 import org.onap.datalake.feeder.config.ApplicationConfiguration;
33 import org.onap.datalake.feeder.domain.Topic;
34 import org.onap.datalake.feeder.domain.TopicName;
35 import org.onap.datalake.feeder.service.DbService;
36 import org.onap.datalake.feeder.service.db.ElasticsearchService;
37
38 import java.io.IOException;
39 import java.util.ArrayList;
40 import java.util.List;
41 import static org.mockito.Mockito.when;
42
43 @RunWith(MockitoJUnitRunner.class)
44 public class ElasticsearchServiceTest {
45
46     static String DEFAULT_TOPIC_NAME = "_DL_DEFAULT_";
47
48     @InjectMocks
49     private ElasticsearchService elasticsearchService;
50
51     @Mock
52     private ApplicationConfiguration config;
53
54     @Mock
55     private RestHighLevelClient client;
56
57     @Mock
58     ActionListener<BulkResponse> listener;
59
60     @Mock
61     private DbService dbService;
62
63     @Test(expected = NullPointerException.class)
64     public void testCleanUp() throws IOException {
65
66         elasticsearchService.cleanUp();
67
68     }
69
70     @Test(expected = NullPointerException.class)
71     public void testEnsureTableExist() throws IOException {
72
73         elasticsearchService.ensureTableExist(DEFAULT_TOPIC_NAME);
74     }
75
76     @Test
77     public void testSaveJsons() {
78
79         Topic topic = new Topic();
80         topic.setTopicName(new TopicName("unauthenticated.SEC_FAULT_OUTPUT"));
81         topic.setCorrelateClearedMessage(true);
82         topic.setMessageIdPath("/event/commonEventHeader/eventName,/event/commonEventHeader/reportingEntityName,/event/faultFields/specificProblem");
83         String jsonString = "{\"event\":{\"commonEventHeader\":{\"sourceId\":\"vnf_test_999\",\"startEpochMicrosec\":2222222222222,\"eventId\":\"ab305d54-85b4-a31b-7db2-fb6b9e546016\",\"sequence\":1,\"domain\":\"fautt\",\"lastEpochMicrosec\":1234567890987,\"eventName\":\"Fault_MultiCloud_VMFailure\",\"sourceName\":\"vSBC00\",\"priority\":\"Low\",\"version\":3,\"reportingEntityName\":\"vnf_test_2_rname\"},\"faultFields\":{\"eventSeverity\":\"CRITILLL\",\"alarmCondition\":\"Guest_Os_FaiLLL\",\"faultFieldsVersion\":3,\"specificProblem\":\"Fault_MultiCloud_VMFailure\",\"alarmInterfaceA\":\"aaaa\",\"alarmAdditionalInformation\":[{\"name\":\"objectType3\",\"value\":\"VIN\"},{\"name\":\"objectType4\",\"value\":\"VIN\"}],\"eventSourceType\":\"single\",\"vfStatus\":\"Active\"}}}";
84         String jsonString2 = "{\"event\":{\"commonEventHeader\":{\"sourceId\":\"vnf_test_999\",\"startEpochMicrosec\":2222222222222,\"eventId\":\"ab305d54-85b4-a31b-7db2-fb6b9e546016\",\"sequence\":1,\"domain\":\"fautt\",\"lastEpochMicrosec\":1234567890987,\"eventName\":\"Fault_MultiCloud_VMFailureCleared\",\"sourceName\":\"vSBC00\",\"priority\":\"Low\",\"version\":3,\"reportingEntityName\":\"vnf_test_2_rname\"},\"faultFields\":{\"eventSeverity\":\"CRITILLL\",\"alarmCondition\":\"Guest_Os_FaiLLL\",\"faultFieldsVersion\":3,\"specificProblem\":\"Fault_MultiCloud_VMFailure\",\"alarmInterfaceA\":\"aaaa\",\"alarmAdditionalInformation\":[{\"name\":\"objectType3\",\"value\":\"VIN\"},{\"name\":\"objectType4\",\"value\":\"VIN\"}],\"eventSourceType\":\"single\",\"vfStatus\":\"Active\"}}}";
85
86         JSONObject jsonObject = new JSONObject(jsonString);
87         JSONObject jsonObject2 = new JSONObject(jsonString2);
88
89         List<JSONObject> jsons = new ArrayList<>();
90         jsons.add(jsonObject);
91         jsons.add(jsonObject2);
92 //        when(config.getElasticsearchType()).thenReturn("doc");
93   //      when(config.isAsync()).thenReturn(true);
94
95         //elasticsearchService.saveJsons(topic.getTopicConfig(), jsons);
96
97     }
98 }