/*- * ============LICENSE_START======================================================= * SDC * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. * ================================================================================ * 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. * ============LICENSE_END========================================================= */ package org.openecomp.sdc.vendorlicense; /** * This test just verifies Feature Group Get and List APIs. */ public class VendorLicenseFacadeImplTest { /* //JUnit Test Cases using Mockito private static final Version VERSION01 = new Version(0, 1); public static final String EP1 = "ep1"; public static final String MRN = "mrn"; public static final String VLM_ID = "VLM_ID"; public static final String USER = "USER1"; @Mock private VendorLicenseModelDao vendorLicenseModelDao; @Mock private LicenseAgreementDao licenseAgreementDao; @Mock private FeatureGroupDao featureGroupDao; @Mock private EntitlementPoolDao entitlementPoolDao; @Mock private LicenseKeyGroupDao licenseKeyGroupDao; @Mock private VersioningManager versioningManager; @InjectMocks @Spy private VendorLicenseFacadeImpl vendorLicenseFacadeImpl; @BeforeMethod public void setUp() throws Exception{ MockitoAnnotations.openMocks(this); } @Test public void testGetFeatureGroupWhenMRNNull () { resetFieldModifiers(); FeatureGroupEntity featureGroup = createFeatureGroup(); VersionInfo info = new VersionInfo(); info.getViewableVersions().add(VERSION01); info.setActiveVersion(VERSION01); Set entitlementPoolIds; entitlementPoolIds = new HashSet<>(); entitlementPoolIds.add(EP1); EntitlementPoolEntity ep = createEP(); featureGroup.setEntitlementPoolIds(entitlementPoolIds); doReturn(info).when(vendorLicenseFacadeImpl).getVersionInfo(anyObject(),anyObject(),anyObject()); doReturn(featureGroup).when(featureGroupDao).get(featureGroup); doReturn(ep).when(entitlementPoolDao).get(anyObject()); doReturn(MRN).when(entitlementPoolDao).getManufacturerReferenceNumber(anyObject()); FeatureGroupEntity retrieved = vendorLicenseFacadeImpl.getFeatureGroup(featureGroup, USER); Assert.assertEquals(MRN, retrieved.getManufacturerReferenceNumber()); } @Test public void testListFeatureGroups () { resetFieldModifiers(); FeatureGroupEntity featureGroup = createFeatureGroup(); Collection featureGroups = new ArrayList(); featureGroups.add(featureGroup); VersionInfo info = new VersionInfo(); info.getViewableVersions().add(VERSION01); info.setActiveVersion(VERSION01); EntitlementPoolEntity ep = createEP(); doReturn(info).when(vendorLicenseFacadeImpl).getVersionInfo(anyObject(),anyObject(),anyObject()); doReturn(featureGroup).when(featureGroupDao).get(featureGroup); doReturn(ep).when(entitlementPoolDao).get(anyObject()); doReturn(MRN).when(entitlementPoolDao).getManufacturerReferenceNumber(anyObject()); Collection retrieved = vendorLicenseFacadeImpl.listFeatureGroups(VLM_ID, VERSION01, USER); retrieved.stream().forEach(fg -> Assert.assertEquals(MRN,fg.getManufacturerReferenceNumber())); } @Test public void testSubmitLAWithoutFG() { try { resetFieldModifiers(); VersionInfo info = new VersionInfo(); info.getViewableVersions().add(VERSION01); info.setActiveVersion(VERSION01); LicenseAgreementEntity licenseAgreementEntity = new LicenseAgreementEntity(); List licenseAgreementEntities = new ArrayList(){{ add(licenseAgreementEntity); }}; doReturn(info).when(vendorLicenseFacadeImpl).getVersionInfo(anyObject(),anyObject(),anyObject()); doReturn(licenseAgreementEntities).when(licenseAgreementDao).list(anyObject()); vendorLicenseFacadeImpl.submit(VLM_ID, USER); Assert.fail(); } catch (CoreException exception) { org.testng.Assert.assertEquals(exception.code().message(), SUBMIT_UNCOMPLETED_VLM_MSG_LA_MISSING_FG.getErrorMessage()); } } @Test public void testSubmitLAWithFGWithoutEP() { try { resetFieldModifiers(); VersionInfo info = new VersionInfo(); info.getViewableVersions().add(VERSION01); info.setActiveVersion(VERSION01); LicenseAgreementEntity licenseAgreementEntity = new LicenseAgreementEntity(); FeatureGroupEntity featureGroupEntity = new FeatureGroupEntity(); licenseAgreementEntity.setFeatureGroupIds(new HashSet(){{ add("54654654asdas5"); }}); List licenseAgreementEntities = new ArrayList(){{ add(licenseAgreementEntity); }}; doReturn(info).when(vendorLicenseFacadeImpl).getVersionInfo(anyObject(),anyObject(),anyObject()); doReturn(licenseAgreementEntities).when(licenseAgreementDao).list(anyObject()); doReturn(featureGroupEntity).when(featureGroupDao).get(anyObject()); vendorLicenseFacadeImpl.submit(VLM_ID, USER); Assert.fail(); } catch (CoreException exception) { org.testng.Assert.assertEquals(exception.code().message(), SUBMIT_UNCOMPLETED_VLM_MSG_FG_MISSING_EP.getErrorMessage()); } } private void resetFieldModifiers() { try { Field fgField = VendorLicenseFacadeImpl.class.getDeclaredField("featureGroupDao"); fgField.setAccessible(true); Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(fgField, fgField.getModifiers() & ~Modifier.FINAL); fgField.set(null, featureGroupDao); Field epField = VendorLicenseFacadeImpl.class.getDeclaredField("entitlementPoolDao"); epField.setAccessible(true); modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(epField, epField.getModifiers() & ~Modifier.FINAL); epField.set(null, entitlementPoolDao); Field laField = VendorLicenseFacadeImpl.class.getDeclaredField("licenseAgreementDao"); laField.setAccessible(true); modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(laField, laField.getModifiers() & ~Modifier.FINAL); laField.set(null, licenseAgreementDao); } catch(NoSuchFieldException | IllegalAccessException e) { org.testng.Assert.fail(); } } private FeatureGroupEntity createFeatureGroup() { FeatureGroupEntity featureGroup = new FeatureGroupEntity(VLM_ID, VERSION01, USER); featureGroup.setManufacturerReferenceNumber(null); VersionInfo info = new VersionInfo(); info.getViewableVersions().add(VERSION01); info.setActiveVersion(VERSION01); Set entitlementPoolIds; entitlementPoolIds = new HashSet<>(); entitlementPoolIds.add(EP1); featureGroup.setEntitlementPoolIds(entitlementPoolIds); return featureGroup; } private EntitlementPoolEntity createEP() { EntitlementPoolEntity ep = new EntitlementPoolEntity(VLM_ID,VERSION01, EP1); ep.setManufacturerReferenceNumber(MRN); return ep; } */ }