diff options
author | Joss Armstrong <joss.armstrong@ericsson.com> | 2019-02-19 16:34:23 +0000 |
---|---|---|
committer | Takamune Cho <takamune.cho@att.com> | 2019-02-19 19:25:47 +0000 |
commit | e182bed98fdd8b413f2f6573318b9f74996477d1 (patch) | |
tree | 92dd09d35251e2300622b2471a4c30e306e50d25 | |
parent | ed83f5fb01499c62954a7451b04a9dd9800a5822 (diff) |
Test coverage in EventHandlerImpl
Added test cases for untested code
Issue-ID: APPC-1462
Change-Id: I492721a9c40678bb8700d30782cfa5949c1f22e9
Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
2 files changed, 42 insertions, 7 deletions
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/EventHandlerImpl.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/EventHandlerImpl.java index 74193c2b8..6a859426e 100644 --- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/EventHandlerImpl.java +++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/impl/EventHandlerImpl.java @@ -5,6 +5,8 @@ * Copyright (C) 2017-2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications Copyright (C) 2019 Ericsson * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +28,6 @@ package org.onap.appc.listener.impl; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; -import org.onap.appc.adapter.factory.DmaapMessageAdapterFactoryImpl; import org.onap.appc.adapter.factory.MessageService; import org.onap.appc.adapter.message.Consumer; import org.onap.appc.adapter.message.MessageAdapterFactory; diff --git a/appc-event-listener/appc-event-listener-bundle/src/test/java/org/onap/appc/listener/impl/EventHandlerImplTest.java b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/onap/appc/listener/impl/EventHandlerImplTest.java index c022e0622..3b60710d5 100644 --- a/appc-event-listener/appc-event-listener-bundle/src/test/java/org/onap/appc/listener/impl/EventHandlerImplTest.java +++ b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/onap/appc/listener/impl/EventHandlerImplTest.java @@ -5,6 +5,8 @@ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs + * ================================================================================ + * Modifications Copyright (C) 2019 Ericsson * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,28 +30,28 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.anyInt; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonSerialize; import java.io.IOException; import java.io.Serializable; +import java.util.ArrayList; +import java.util.Arrays; import java.util.HashSet; import java.util.List; import java.util.Properties; import java.util.Set; -import java.util.function.Function; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.runners.MockitoJUnitRunner; import org.onap.appc.adapter.message.Consumer; import org.onap.appc.adapter.message.Producer; import org.onap.appc.listener.ListenerProperties; +import org.powermock.reflect.Whitebox; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonSerialize; /** * Test the ProviderAdapter implementation. @@ -170,6 +172,38 @@ public class EventHandlerImplTest { verify(mockProducer).close(); } + @Test + public void testGetEvents() { + EventHandlerImpl adapter = new EventHandlerImpl(properties); + Consumer consumer = Mockito.mock(Consumer.class); + Mockito.when(consumer.fetch(Mockito.anyInt(), Mockito.anyInt())) + .thenReturn(new ArrayList<String>(Arrays.asList("TEST1"))); + Whitebox.setInternalState(adapter, "reader", consumer); + assertEquals("TEST1", adapter.getIncomingEvents().get(0)); + } + + @Test + public void testGetEventsClass() { + EventHandlerImpl adapter = new EventHandlerImpl(properties); + Consumer consumer = Mockito.mock(Consumer.class); + Mockito.when(consumer.fetch(Mockito.anyInt(), Mockito.anyInt())) + .thenReturn(new ArrayList<String>(Arrays.asList("1"))); + Whitebox.setInternalState(adapter, "reader", consumer); + assertEquals(Integer.valueOf(1), adapter.getIncomingEvents(Integer.class).get(0)); + } + + @Test + public void testSetters() { + EventHandlerImpl adapter = new EventHandlerImpl(properties); + adapter.setResponseProblemBlacklistTime("1"); + assertEquals("1", Whitebox.getInternalState(adapter, "responseProblemBlacklistTime")); + adapter.setServerProblemBlacklistTime("1"); + assertEquals("1", Whitebox.getInternalState(adapter, "serverProblemBlacklistTime")); + adapter.setDnsIssueBlacklistTime("1"); + assertEquals("1", Whitebox.getInternalState(adapter, "dnsIssueBlacklistTime")); + adapter.setIOExceptionBlacklistTime("1"); + assertEquals("1", Whitebox.getInternalState(adapter, "ioExceptionBlacklistTime")); + } // @Test public void testRun() { |