From 07ecb52a74c75c85e69d65cf19328f7ac58f8d9a Mon Sep 17 00:00:00 2001 From: Michal Kabaj Date: Fri, 15 Jun 2018 11:53:55 +0200 Subject: Unit tests in dg-util Replace powermock usage with mockito. Add assertj test dependency for assertions. Change-Id: I8b268aaf4fe51f1709479a60919b987696f1a9a6 Issue-ID: APPC-1008 Signed-off-by: Michal Kabaj --- appc-dg-util/appc-dg-util-bundle/pom.xml | 10 ++--- .../onap/appc/dg/util/AppcDgUtilActivatorTest.java | 27 +++++-------- .../appc/dg/util/impl/UpgradeStubNodeImplTest.java | 47 ++++++++++++++++------ 3 files changed, 50 insertions(+), 34 deletions(-) (limited to 'appc-dg-util/appc-dg-util-bundle') diff --git a/appc-dg-util/appc-dg-util-bundle/pom.xml b/appc-dg-util/appc-dg-util-bundle/pom.xml index faf77e4f0..bc032ecb2 100644 --- a/appc-dg-util/appc-dg-util-bundle/pom.xml +++ b/appc-dg-util/appc-dg-util-bundle/pom.xml @@ -95,11 +95,6 @@ httpclient 4.5.3 - - junit - junit - test - org.onap.ccsdk.sli.core sli-common @@ -189,6 +184,11 @@ mockito-core test + + org.assertj + assertj-core + test + org.powermock powermock-api-mockito diff --git a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/AppcDgUtilActivatorTest.java b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/AppcDgUtilActivatorTest.java index 447013733..910987cf9 100644 --- a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/AppcDgUtilActivatorTest.java +++ b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/AppcDgUtilActivatorTest.java @@ -5,7 +5,9 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Copyright (C) 2017 Amdocs - * ============================================================================= + * ================================================================================ + * Copyright (C) 2018 Nokia + * ================================================================================ * 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 @@ -23,36 +25,29 @@ package org.onap.appc.dg.util; -import org.junit.Before; +import static org.mockito.Mockito.verifyZeroInteractions; + import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; import org.osgi.framework.BundleContext; -import org.powermock.api.mockito.PowerMockito; -import org.powermock.modules.junit4.PowerMockRunner; -@RunWith(PowerMockRunner.class) +@RunWith(MockitoJUnitRunner.class) public class AppcDgUtilActivatorTest { @Mock private BundleContext bundleContext; - private AppcDgUtilActivator appcDgUtilActivator; - - @Before - public void setUp() throws Exception { - appcDgUtilActivator = new AppcDgUtilActivator(); - } - @Test public void start() { - appcDgUtilActivator.start(bundleContext); - PowerMockito.verifyStatic(); + new AppcDgUtilActivator().start(bundleContext); + verifyZeroInteractions(bundleContext); } @Test public void stop() { - appcDgUtilActivator.stop(bundleContext); - PowerMockito.verifyStatic(); + new AppcDgUtilActivator().stop(bundleContext); + verifyZeroInteractions(bundleContext); } } \ No newline at end of file diff --git a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/UpgradeStubNodeImplTest.java b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/UpgradeStubNodeImplTest.java index 8bb1451dd..c59d5d488 100644 --- a/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/UpgradeStubNodeImplTest.java +++ b/appc-dg-util/appc-dg-util-bundle/src/test/java/org/onap/appc/dg/util/impl/UpgradeStubNodeImplTest.java @@ -6,6 +6,8 @@ * ================================================================================ * Copyright (C) 2017 Amdocs * ============================================================================= + * Copyright (C) 2018 Nokia + * ============================================================================= * 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 @@ -23,40 +25,59 @@ package org.onap.appc.dg.util.impl; +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.mockito.Mockito.verifyZeroInteractions; + +import java.util.HashMap; +import java.util.Map; import org.junit.Before; import org.junit.Test; +import org.junit.runner.RunWith; import org.mockito.Mock; +import org.mockito.runners.MockitoJUnitRunner; +import org.onap.appc.dg.util.UpgradeStubNode; import org.onap.appc.exceptions.APPCException; import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import org.onap.ccsdk.sli.core.sli.SvcLogicResource; -import org.onap.ccsdk.sli.adaptors.aai.AAIClient; -import org.onap.ccsdk.sli.adaptors.aai.AAIService; - -import java.util.HashMap; -import java.util.Map; +@RunWith(MockitoJUnitRunner.class) public class UpgradeStubNodeImplTest { + @Mock private SvcLogicContext svcLogicContext; - private UpgradeStubNodeImpl upgradeStubNode; + private UpgradeStubNode upgradeStubNode; @Before - public void setUp() throws Exception { + public void setUp() { upgradeStubNode = new UpgradeStubNodeImpl(); } @Test - public void testHandleUpgradeStubSuccess() throws APPCException { + public void handleUpgradeStub_shouldCompleteSuccessfully_whenFailureIndicatorIsNull() throws APPCException { Map params = new HashMap<>(); upgradeStubNode.handleUpgradeStub(params, svcLogicContext); + verifyZeroInteractions(svcLogicContext); } - @Test(expected = APPCException.class) - public void testHandleUpgradeStubException() throws APPCException { + @Test + public void handleUpgradeStub_shouldCompleteSuccessfully_whenFailureIndicatorIsFalse() throws APPCException { + // GIVEN Map params = new HashMap<>(); - params.put("failureIndicator", "true"); + params.put("failureIndicator", "false"); + // WHEN upgradeStubNode.handleUpgradeStub(params, svcLogicContext); + // THEN + verifyZeroInteractions(svcLogicContext); + } + + @Test + public void handleUpgradeStub_shouldThrowAPPCException_whenFailureIndicatorIsTrue() throws APPCException { + // GIVEN + Map params = new HashMap<>(); + params.put("failureIndicator", "true"); + // WHEN // THEN + assertThatExceptionOfType(APPCException.class) + .isThrownBy(() -> upgradeStubNode.handleUpgradeStub(params, svcLogicContext)); + verifyZeroInteractions(svcLogicContext); } } \ No newline at end of file -- cgit 1.2.3-korg