bb040d1e313ad3311c80ab3c7a214804faa2ffd1
[integration.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * Simulator
4  * ================================================================================
5  * Copyright (C) 2019 Nokia. All rights reserved.
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.netconfsimulator.websocket.message;
22
23
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.Mockito.doThrow;
26 import static org.mockito.Mockito.verify;
27 import static org.mockito.MockitoAnnotations.initMocks;
28
29 import java.io.IOException;
30 import javax.websocket.EncodeException;
31 import javax.websocket.RemoteEndpoint;
32 import org.apache.kafka.clients.consumer.ConsumerRecord;
33 import org.junit.jupiter.api.BeforeEach;
34 import org.junit.jupiter.api.Test;
35 import org.mockito.InjectMocks;
36 import org.mockito.Mock;
37 import org.onap.netconfsimulator.kafka.model.KafkaMessage;
38
39
40 class NetconfMessageListenerTest {
41
42     private static final ConsumerRecord<String, String> KAFKA_RECORD = new ConsumerRecord<>("sampleTopic", 0, 0,
43         "sampleKey", "sampleValue");
44
45     @Mock
46     private RemoteEndpoint.Basic remoteEndpoint;
47
48     @InjectMocks
49     private NetconfMessageListener netconfMessageListener;
50
51
52     @BeforeEach
53     void setUp() {
54         initMocks(this);
55     }
56
57
58     @Test
59     void shouldProperlyParseAndSendConsumerRecord() throws IOException, EncodeException {
60         netconfMessageListener.onMessage(KAFKA_RECORD);
61
62         verify(remoteEndpoint).sendObject(any(KafkaMessage.class));
63     }
64
65
66
67     @Test
68     void shouldNotPropagateEncodeException() throws IOException, EncodeException {
69         doThrow(new EncodeException("","")).when(remoteEndpoint).sendObject(any(KafkaMessage.class));
70
71         netconfMessageListener.onMessage(KAFKA_RECORD);
72     }
73 }