ef28f1f6041aad190c1b86cd92c2025ed01282f5
[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;
22
23 import com.mongodb.MongoClient;
24 import com.mongodb.client.MongoCollection;
25 import com.mongodb.client.MongoDatabase;
26 import org.bson.Document;
27 import org.json.JSONObject;
28 import org.junit.Test;
29 import org.junit.runner.RunWith;
30 import org.mockito.InjectMocks;
31 import org.mockito.Mock;
32 import org.mockito.junit.MockitoJUnitRunner;
33 import org.onap.datalake.feeder.config.ApplicationConfiguration;
34 import org.onap.datalake.feeder.domain.Topic;
35
36 import static org.mockito.Mockito.when;
37
38 import java.util.ArrayList;
39 import java.util.HashMap;
40 import java.util.List;
41 import java.util.Map;
42 import java.util.concurrent.locks.ReentrantReadWriteLock;
43
44 @RunWith(MockitoJUnitRunner.class)
45 public class MongodbServiceTest {
46
47     @InjectMocks
48     private MongodbService mongodbService;
49
50     @Mock
51     private ApplicationConfiguration config;
52
53     @Mock
54     private DbService dbService;
55
56     @Mock
57     private MongoDatabase database;
58
59     @Mock
60     private MongoClient mongoClient;
61
62     @Mock
63     private Map<String, MongoCollection<Document>> mongoCollectionMap = new HashMap<>();
64
65
66     @Test
67     public void cleanUp() {
68                 when(config.getShutdownLock()).thenReturn(new ReentrantReadWriteLock());
69         mongodbService.cleanUp();
70     }
71
72     @Test
73     public void saveJsons() {
74
75         Topic topic = new Topic();
76         topic.setName("unauthenticated.SEC_FAULT_OUTPUT");
77         topic.setCorrelateClearedMessage(true);
78         topic.setMessageIdPath("/event/commonEventHeader/eventName,/event/commonEventHeader/reportingEntityName,/event/faultFields/specificProblem");
79         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\"}}}";
80         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\"}}}";
81
82         JSONObject jsonObject = new JSONObject(jsonString);
83         JSONObject jsonObject2 = new JSONObject(jsonString2);
84
85         List<JSONObject> jsons = new ArrayList<>();
86         jsons.add(jsonObject);
87         jsons.add(jsonObject2);
88
89         mongodbService.saveJsons(topic.getTopicConfig(), jsons);
90     }
91 }