3ad47f0a26c17c6774c9aaa70d12d3061aa9ee8c
[dcaegen2/services/mapper.git] / UniversalVesAdapter / src / test / java / org / onap / universalvesadapter / service / VesServiceTest.java
1 /*
2 * ============LICENSE_START=======================================================
3 * ONAP : DCAE
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
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 package org.onap.universalvesadapter.service;
21
22 import static org.junit.Assert.*;
23 import static org.mockito.Mockito.doNothing;
24 import static org.mockito.Mockito.doReturn;
25
26 import java.io.IOException;
27 import java.util.Arrays;
28 import java.util.Collections;
29
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;
49
50 import com.att.nsa.mr.client.MRConsumer;
51 @Ignore
52 @RunWith(SpringRunner.class)
53 @SpringBootTest(classes = Application.class)
54 public class VesServiceTest {
55
56     @InjectMocks
57     @Autowired
58     private VesService vesService;
59     
60     @Mock
61     private DMaapService dmaapService;
62     
63     private final Logger eLOGGER = LoggerFactory.getLogger(this.getClass());    
64     
65     @Before
66     public void init() {
67         MockitoAnnotations.initMocks(this);
68     } 
69     
70     
71     @Test
72     public void testStart() throws IOException {
73         
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 \" "
90                 + " }, { "
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 \" "
94                 + " }] "
95                 + "}"};
96         try {
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());
100         }
101         
102         ArgumentCaptor<?> valueCapture = ArgumentCaptor.forClass(String.class);
103         try {
104             //doNothing().when(dmaapService).fetchAndPublishInDMaaP((String) valueCapture.capture());
105         } catch (DMaapException e) {
106             eLOGGER.error("Error occurred : " + e.getMessage());
107         }
108         
109         
110         new Thread(new Runnable() {
111             
112             @Override
113             public void run() {
114                 // TODO Auto-generated method stub
115                 vesService.start();
116                 
117             }
118         }).start();
119         try {
120             Thread.sleep(5000);
121         } catch (InterruptedException e) {
122             // TODO Auto-generated catch block
123             e.printStackTrace();
124         }
125         new Thread(new Runnable() {
126             
127             @Override
128             public void run() {
129                 // TODO Auto-generated method stub
130                 vesService.stop();
131                 
132             }
133         }).start();
134         String result = "{\"event\":{\"commonEventHeader\":{},\"faultFields\":{},\"measurementsForVfScalingFields\":{\"additionalMeasurements\":[]}}}";
135         assertEquals(result, valueCapture.getValue());
136     }
137
138     @Test
139     public void testStop() {
140         fail("Not yet implemented");
141     }
142
143 }
144 */