aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/dcae/common/EventSenderTest.java
blob: f49d3cd8ca7e0c059fc754ec8666feba43895840 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * ============LICENSE_START=======================================================
 * PROJECT
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * Copyright (C) 2018 Nokia. All rights reserved.s
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */
package org.onap.dcae.common;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import io.vavr.collection.HashMap;
import io.vavr.collection.Map;
import org.json.JSONArray;
import org.json.JSONObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.onap.dcae.ApplicationSettings;
import org.onap.dcae.common.publishing.EventPublisher;

@RunWith(MockitoJUnitRunner.Silent.class)
public class EventSenderTest {

  private String event = "{\"VESversion\":\"v7\",\"VESuniqueId\":\"fd69d432-5cd5-4c15-9d34-407c81c61c6a-0\",\"event\":{\"commonEventHeader\":{\"startEpochMicrosec\":1544016106000000,\"eventId\":\"fault33\",\"timeZoneOffset\":\"UTC+00.00\",\"priority\":\"Normal\",\"version\":\"4.0.1\",\"nfVendorName\":\"Ericsson\",\"reportingEntityName\":\"1\",\"sequence\":1,\"domain\":\"fault\",\"lastEpochMicrosec\":1544016106000000,\"eventName\":\"Fault_KeyFileFault\",\"vesEventListenerVersion\":\"7.0.1\",\"sourceName\":\"1\"},\"faultFields\":{\"eventSeverity\":\"CRITICAL\",\"alarmCondition\":\"KeyFileFault\",\"faultFieldsVersion\":\"4.0\",\"eventCategory\":\"PROCESSINGERRORALARM\",\"specificProblem\":\"License Key File Fault_1\",\"alarmAdditionalInformation\":{\"probableCause\":\"ConfigurationOrCustomizationError\",\"additionalText\":\"test_1\",\"source\":\"ManagedElement=1,SystemFunctions=1,Lm=1\"},\"eventSourceType\":\"Lm\",\"vfStatus\":\"Active\"}}}\n";

  @Mock
  private EventPublisher eventPublisher;
  @Mock
  private ApplicationSettings settings;

  private EventSender eventSender;


  @Test
  public void shouldntSendEventWhenStreamIdsIsEmpty() {
    when(settings.dMaaPStreamsMapping()).thenReturn(HashMap.empty());
    eventSender = new EventSender(eventPublisher, settings );
    JSONObject jsonObject = new JSONObject(event);
    JSONArray jsonArray = new JSONArray();
    jsonArray.put(jsonObject);
    eventSender.send(jsonArray);
    verify(eventPublisher,never()).sendEvent(any(),any());
  }

  @Test
  public void shouldSendEvent() {
    Map<String, String[]> streams = HashMap.of("fault", new String[]{"ves-fault", "fault-ves"});
    when(settings.dMaaPStreamsMapping()).thenReturn(streams);
    eventSender = new EventSender(eventPublisher, settings );
    JSONObject jsonObject = new JSONObject(event);
    JSONArray jsonArray = new JSONArray();
    jsonArray.put(jsonObject);
    eventSender.send(jsonArray);
    verify(eventPublisher, times(2)).sendEvent(any(),any());
  }
}