2 * ============LICENSE_START=======================================================
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
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=========================================================
21 package org.onap.netconfsimulator.websocket.message;
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;
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;
40 class NetconfMessageListenerTest {
42 private static final ConsumerRecord<String, String> KAFKA_RECORD = new ConsumerRecord<>("sampleTopic", 0, 0,
43 "sampleKey", "sampleValue");
46 private RemoteEndpoint.Basic remoteEndpoint;
49 private NetconfMessageListener netconfMessageListener;
59 void shouldProperlyParseAndSendConsumerRecord() throws IOException, EncodeException {
60 netconfMessageListener.onMessage(KAFKA_RECORD);
62 verify(remoteEndpoint).sendObject(any(KafkaMessage.class));
68 void shouldNotPropagateEncodeException() throws IOException, EncodeException {
69 doThrow(new EncodeException("","")).when(remoteEndpoint).sendObject(any(KafkaMessage.class));
71 netconfMessageListener.onMessage(KAFKA_RECORD);