From e3228d1b699e89df911008f12b9494903ac9a0ef Mon Sep 17 00:00:00 2001 From: Joanna Jeremicz Date: Tue, 26 Jun 2018 09:54:34 +0200 Subject: Add additional junits for LicenseManagerImpl - Positive and negative case Issue-ID: APPC-1024 Change-Id: Ic619553cc305517bebecf0754a7b9f7e8dd7ce51 Signed-off-by: Joanna Jeremicz --- .../appc/licmgr/impl/LicenseManagerImplTest.java | 73 ++++++++++++++++++++-- 1 file changed, 67 insertions(+), 6 deletions(-) (limited to 'appc-dispatcher/appc-license-manager/appc-license-manager-core/src/test') diff --git a/appc-dispatcher/appc-license-manager/appc-license-manager-core/src/test/java/org/onap/appc/licmgr/impl/LicenseManagerImplTest.java b/appc-dispatcher/appc-license-manager/appc-license-manager-core/src/test/java/org/onap/appc/licmgr/impl/LicenseManagerImplTest.java index 6fd9cb192..c025c987b 100644 --- a/appc-dispatcher/appc-license-manager/appc-license-manager-core/src/test/java/org/onap/appc/licmgr/impl/LicenseManagerImplTest.java +++ b/appc-dispatcher/appc-license-manager/appc-license-manager-core/src/test/java/org/onap/appc/licmgr/impl/LicenseManagerImplTest.java @@ -23,38 +23,99 @@ package org.onap.appc.licmgr.impl; import static org.assertj.core.api.Assertions.assertThatExceptionOfType; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.mockito.BDDMockito.given; +import static org.onap.appc.licmgr.Constants.SDC_ARTIFACTS_FIELDS.ARTIFACT_CONTENT; import java.util.Collections; +import java.util.Map; +import java.util.HashMap; +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.licmgr.LicenseDataAccessService; import org.onap.appc.licmgr.exception.DataAccessException; +import org.onap.appc.licmgr.objects.LicenseModel; @RunWith(MockitoJUnitRunner.class) public class LicenseManagerImplTest { + private static final String VNF_TYPE = "default_vnf_type"; + private static final String VNF_VERSION = "default_vnf_version"; + private LicenseManagerImpl licenseManager; + @Mock private LicenseDataAccessService licenseDataAccessService; + @Before + public void setUp() { + licenseManager = new LicenseManagerImpl(); + } + @Test public void retrieveLicenseModel_shouldThrowException_whenRetrieveLicenseModelDataIsEmpty() { // GIVEN - String vnfType = "dummy1"; - String vnfVersion = "dummy2"; String expectedMessage = String - .format("License model not found for vnfType='%s' and vnfVersion='%s'", vnfType, vnfVersion); - given(licenseDataAccessService.retrieveLicenseModelData(vnfType, vnfVersion)).willReturn(Collections.emptyMap()); + .format("License model not found for vnfType='%s' and vnfVersion='%s'", VNF_TYPE, VNF_VERSION); + given(licenseDataAccessService.retrieveLicenseModelData(VNF_TYPE, VNF_VERSION)) + .willReturn(Collections.emptyMap()); // WHEN THEN - LicenseManagerImpl licenseManager = new LicenseManagerImpl(); licenseManager.setDAService(licenseDataAccessService); assertThatExceptionOfType(DataAccessException.class) - .isThrownBy(() -> licenseManager.retrieveLicenseModel(vnfType, vnfVersion)) + .isThrownBy(() -> licenseManager.retrieveLicenseModel(VNF_TYPE, VNF_VERSION)) .withMessage(expectedMessage); } + + @Test + public void retrieveLicenseModel_shouldReturnLicenseModelWithNullValues_whenXmlIsMalformed() { + + // GIVEN + String malformedXml = "xyz"; + + Map licenseModelData = new HashMap<>(); + licenseModelData.put(ARTIFACT_CONTENT.name(), malformedXml); + given(licenseDataAccessService.retrieveLicenseModelData(VNF_TYPE, VNF_VERSION)) + .willReturn(licenseModelData); + + // WHEN + licenseManager.setDAService(licenseDataAccessService); + LicenseModel licenseModel = licenseManager.retrieveLicenseModel(VNF_TYPE, VNF_VERSION); + + // THEN + assertNull(licenseModel.getEntitlementPoolUuid()); + assertNull(licenseModel.getLicenseKeyGroupUuid()); + } + + @Test + public void retrieveLicenseModel_shouldReturnCorrectLicenseModel_whenCorrectXmlExists() { + + // GIVEN + String expectedEntitlementPool = "default_entitlement_pool"; + String expectedKeyGroup = "default_key_group"; + + String correctlyFormedXml = String.format("\n" + + "\n" + + "%s\n" + + "%s\n" + + "", expectedEntitlementPool, expectedKeyGroup); + + Map licenseModelData = new HashMap<>(); + licenseModelData.put(ARTIFACT_CONTENT.name(), correctlyFormedXml); + given(licenseDataAccessService.retrieveLicenseModelData(VNF_TYPE, VNF_VERSION)) + .willReturn(licenseModelData); + + // WHEN + licenseManager.setDAService(licenseDataAccessService); + LicenseModel licenseModel = licenseManager.retrieveLicenseModel(VNF_TYPE, VNF_VERSION); + + // THEN + assertEquals(expectedEntitlementPool, licenseModel.getEntitlementPoolUuid()); + assertEquals(expectedKeyGroup, licenseModel.getLicenseKeyGroupUuid()); + } } \ No newline at end of file -- cgit 1.2.3-korg