2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright 2018 TechMahindra
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=========================================================
20 package org.onap.universalvesadapter.service;
22 import static org.junit.Assert.*;
23 import static org.mockito.Mockito.doNothing;
24 import static org.mockito.Mockito.doReturn;
26 import java.io.IOException;
27 import java.util.Arrays;
28 import java.util.Collections;
30 import org.junit.Before;
31 import org.junit.Ignore;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.ArgumentCaptor;
35 import org.mockito.InjectMocks;
36 import org.mockito.Mock;
37 import org.mockito.Mockito;
38 import org.mockito.MockitoAnnotations;
39 import org.onap.universalvesadapter.Application;
40 import org.onap.universalvesadapter.exception.DMaapException;
41 import org.onap.universalvesadapter.service.DMaapService;
42 import org.onap.universalvesadapter.service.VesService;
43 import org.onap.universalvesadapter.utils.ParallelTasks;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46 import org.springframework.beans.factory.annotation.Autowired;
47 import org.springframework.boot.test.context.SpringBootTest;
48 import org.springframework.test.context.junit4.SpringRunner;
50 import com.att.nsa.mr.client.MRConsumer;
52 @RunWith(SpringRunner.class)
53 @SpringBootTest(classes = Application.class)
54 public class VesServiceTest {
58 private VesService vesService;
61 private DMaapService dmaapService;
63 private final Logger eLOGGER = LoggerFactory.getLogger(this.getClass());
67 MockitoAnnotations.initMocks(this);
72 public void testStart() throws IOException {
74 String[] incomingMessages = {"{ "
75 + " \"protocol version \": \"v2c \", "
76 + " \"notify OID \": \".1.3.6.1.4.1.74.2.46.12.1.1AAA \", "
77 + " \"cambria.partition \": \"dcae-snmp.client.research.att.com \", "
78 + " \"trap category \": \"UCSNMP-HEARTBEAT \", "
79 + " \"epoch_serno \": 15161177410000, "
80 + " \"community \": \"public \", "
81 + " \"time received \": 1516117741, "
82 + " \"agent name \": \"localhost \", "
83 + " \"agent address \": \"127.0.0.1 \", "
84 + " \"community len \": 6, "
85 + " \"notify OID len \": 12, "
86 + " \"varbinds \": [{ "
87 + " \"varbind_type \": \"octet \", "
88 + " \"varbind_oid \": \".1.3.6.1.4.1.74.2.46.12.1.1.1 \", "
89 + " \"varbind_value \": \"ucsnmp heartbeat - ignore \" "
91 + " \"varbind_type \": \"octet \", "
92 + " \"varbind_oid \": \".1.3.6.1.4.1.74.2.46.12.1.1.2 \", "
93 + " \"varbind_value \": \"Tue Jan 16 10:49:01 EST 2018 \" "
97 // Mockito.when(dmaapService.fetchAndPublishInDMaaP(null,null)).thenReturn(Arrays.asList(incomingMessages)).thenReturn(() -> Collections.emptyIterator());
98 } catch (Exception e) {
99 eLOGGER.error("Error occurred : " + e.getMessage());
102 ArgumentCaptor<?> valueCapture = ArgumentCaptor.forClass(String.class);
104 //doNothing().when(dmaapService).fetchAndPublishInDMaaP((String) valueCapture.capture());
105 } catch (DMaapException e) {
106 eLOGGER.error("Error occurred : " + e.getMessage());
110 new Thread(new Runnable() {
114 // TODO Auto-generated method stub
121 } catch (InterruptedException e) {
122 // TODO Auto-generated catch block
125 new Thread(new Runnable() {
129 // TODO Auto-generated method stub
134 String result = "{\"event\":{\"commonEventHeader\":{},\"faultFields\":{},\"measurementsForVfScalingFields\":{\"additionalMeasurements\":[]}}}";
135 assertEquals(result, valueCapture.getValue());
139 public void testStop() {
140 fail("Not yet implemented");