From 8b9acafc674a3e9a833e1a1a78583fc78c922b2c Mon Sep 17 00:00:00 2001 From: Oleg Mitsura Date: Wed, 10 Apr 2019 09:58:21 -0400 Subject: netconf-executor: Moving NetconfSessionListenerImpl out of NetconfSessionImpl, and adding test for it. Issue-ID: CCSDK-1126 Change-Id: I8674c247e64efdf48faf35b8d21eae5eaed14d95 Signed-off-by: Oleg Mitsura --- .../core/NetconfSessionListenerImplTest.kt | 87 ++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionListenerImplTest.kt (limited to 'ms/blueprintsprocessor/functions/netconf-executor/src/test') diff --git a/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionListenerImplTest.kt b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionListenerImplTest.kt new file mode 100644 index 000000000..f3817b7fc --- /dev/null +++ b/ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/netconf/executor/core/NetconfSessionListenerImplTest.kt @@ -0,0 +1,87 @@ +/* + * Copyright © 2019 Bell Canada + * + * 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. + */ + +package org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.core + +import org.junit.Test +import io.mockk.every +import io.mockk.mockk +import io.mockk.verifyAll +import org.junit.Before +import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo +import org.onap.ccsdk.cds.blueprintsprocessor.functions.netconf.executor.api.NetconfReceivedEvent + +class NetconfSessionListenerImplTest { + //Note: mockk's verifyAll is akin to verify with verifyNoMoreInteractions in Mockito + private val netconSession = mockk() + + @Before + fun init() { + every { netconSession.disconnect() } returns Unit + every { netconSession.addDeviceErrorReply(any()) } returns Unit + every { netconSession.addDeviceReply(any(), any()) } returns Unit + } + + @Test + //NetconfReceivedEvent wth DEVICE_UNREGISTERED TYPE should call disconnect() on the NetconfSession + fun deviceUnregisteredMessageShouldCallSessionDisconnect() { + val netconfSessionListener = NetconfSessionListenerImpl(netconSession) + val event: NetconfReceivedEvent = genEventByType(NetconfReceivedEvent.Type.DEVICE_UNREGISTERED) + netconfSessionListener.accept(event) + verifyAll { netconSession.disconnect() } + } + + @Test + //NetconfReceivedEvent wth SESSION_CLOSED TYPE should ALSO call disconnect() on the NetconfSession + fun sessionClosedMessageShouldCallSesionDisconnect() { + val netconfSessionListener = NetconfSessionListenerImpl(netconSession) + val event: NetconfReceivedEvent = genEventByType(NetconfReceivedEvent.Type.SESSION_CLOSED) + netconfSessionListener.accept(event) + verifyAll { netconSession.disconnect() } + } + + @Test + //NetconfReceivedEvent wth DEVICE_ERROR TYPE should call addDeviceErrorReply() on the NetconfSession + //with the event message payload + fun deviceErrorMessageShouldCallAddDeviceErrorReply() { + val netconfSessionListener = NetconfSessionListenerImpl(netconSession) + val event: NetconfReceivedEvent = genEventByType(NetconfReceivedEvent.Type.DEVICE_ERROR) + netconfSessionListener.accept(event) + verifyAll { netconSession.addDeviceErrorReply(event.messagePayload) } + } + + @Test + //NetconfReceivedEvent wth DEVICE_REPLY TYPE should call addDeviceReply(messageId, payload) on the NetconfSession + fun deviceReplyMessageShouldCallAddDeviceReply() { + val netconfSessionListener = NetconfSessionListenerImpl(netconSession) + val event: NetconfReceivedEvent = genEventByType(NetconfReceivedEvent.Type.DEVICE_REPLY) + netconfSessionListener.accept(event) + verifyAll { netconSession.addDeviceReply(event.messageId, event.messagePayload) } + } + + /** + * Helper to generate {@link NetconfReceivedEvent} object based on the {@link NetconfReceivedEvent.Type} + * @param type {@link NetconfReceivedEvent.Type} of event + */ + private fun genEventByType(type: NetconfReceivedEvent.Type): NetconfReceivedEvent { + return NetconfReceivedEvent( + type, + "messagePayload", + "messageId", + DeviceInfo() + ) + } +} \ No newline at end of file -- cgit 1.2.3-korg