2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.vendorlicense;
24 * This test just verifies Feature Group Get and List APIs.
26 public class VendorLicenseFacadeImplTest {
29 //JUnit Test Cases using Mockito
30 private static final Version VERSION01 = new Version(0, 1);
31 public static final String EP1 = "ep1";
32 public static final String MRN = "mrn";
33 public static final String VLM_ID = "VLM_ID";
34 public static final String USER = "USER1";
38 private VendorLicenseModelDao vendorLicenseModelDao;
41 private LicenseAgreementDao licenseAgreementDao;
44 private FeatureGroupDao featureGroupDao;
47 private EntitlementPoolDao entitlementPoolDao;
50 private LicenseKeyGroupDao licenseKeyGroupDao;
53 private VersioningManager versioningManager;
57 private VendorLicenseFacadeImpl vendorLicenseFacadeImpl;
60 public void setUp() throws Exception{
61 MockitoAnnotations.initMocks(this);
65 public void testGetFeatureGroupWhenMRNNull () {
66 resetFieldModifiers();
68 FeatureGroupEntity featureGroup = createFeatureGroup();
70 VersionInfo info = new VersionInfo();
71 info.getViewableVersions().add(VERSION01);
72 info.setActiveVersion(VERSION01);
74 Set<String> entitlementPoolIds;
75 entitlementPoolIds = new HashSet<>();
76 entitlementPoolIds.add(EP1);
78 EntitlementPoolEntity ep = createEP();
80 featureGroup.setEntitlementPoolIds(entitlementPoolIds);
82 doReturn(info).when(vendorLicenseFacadeImpl).getVersionInfo(anyObject(),anyObject(),anyObject());
83 doReturn(featureGroup).when(featureGroupDao).get(featureGroup);
84 doReturn(ep).when(entitlementPoolDao).get(anyObject());
85 doReturn(MRN).when(entitlementPoolDao).getManufacturerReferenceNumber(anyObject());
86 FeatureGroupEntity retrieved = vendorLicenseFacadeImpl.getFeatureGroup(featureGroup, USER);
87 Assert.assertEquals(MRN, retrieved.getManufacturerReferenceNumber());
91 public void testListFeatureGroups () {
92 resetFieldModifiers();
94 FeatureGroupEntity featureGroup = createFeatureGroup();
96 Collection<FeatureGroupEntity> featureGroups = new ArrayList<FeatureGroupEntity>();
97 featureGroups.add(featureGroup);
99 VersionInfo info = new VersionInfo();
100 info.getViewableVersions().add(VERSION01);
101 info.setActiveVersion(VERSION01);
103 EntitlementPoolEntity ep = createEP();
105 doReturn(info).when(vendorLicenseFacadeImpl).getVersionInfo(anyObject(),anyObject(),anyObject());
106 doReturn(featureGroup).when(featureGroupDao).get(featureGroup);
107 doReturn(ep).when(entitlementPoolDao).get(anyObject());
108 doReturn(MRN).when(entitlementPoolDao).getManufacturerReferenceNumber(anyObject());
109 Collection<FeatureGroupEntity> retrieved = vendorLicenseFacadeImpl.listFeatureGroups(VLM_ID,
111 retrieved.stream().forEach(fg -> Assert.assertEquals(MRN,fg.getManufacturerReferenceNumber()));
115 public void testSubmitLAWithoutFG()
118 resetFieldModifiers();
120 VersionInfo info = new VersionInfo();
121 info.getViewableVersions().add(VERSION01);
122 info.setActiveVersion(VERSION01);
124 LicenseAgreementEntity licenseAgreementEntity = new LicenseAgreementEntity();
125 List<LicenseAgreementEntity> licenseAgreementEntities = new ArrayList<LicenseAgreementEntity>(){{
126 add(licenseAgreementEntity);
129 doReturn(info).when(vendorLicenseFacadeImpl).getVersionInfo(anyObject(),anyObject(),anyObject());
130 doReturn(licenseAgreementEntities).when(licenseAgreementDao).list(anyObject());
132 vendorLicenseFacadeImpl.submit(VLM_ID, USER);
134 } catch (CoreException exception) {
135 org.testng.Assert.assertEquals(exception.code().message(), SUBMIT_UNCOMPLETED_VLM_MSG_LA_MISSING_FG.getErrorMessage());
140 public void testSubmitLAWithFGWithoutEP()
143 resetFieldModifiers();
145 VersionInfo info = new VersionInfo();
146 info.getViewableVersions().add(VERSION01);
147 info.setActiveVersion(VERSION01);
149 LicenseAgreementEntity licenseAgreementEntity = new LicenseAgreementEntity();
150 FeatureGroupEntity featureGroupEntity = new FeatureGroupEntity();
151 licenseAgreementEntity.setFeatureGroupIds(new HashSet<String>(){{
152 add("54654654asdas5");
154 List<LicenseAgreementEntity> licenseAgreementEntities = new ArrayList<LicenseAgreementEntity>(){{
155 add(licenseAgreementEntity);
158 doReturn(info).when(vendorLicenseFacadeImpl).getVersionInfo(anyObject(),anyObject(),anyObject());
159 doReturn(licenseAgreementEntities).when(licenseAgreementDao).list(anyObject());
160 doReturn(featureGroupEntity).when(featureGroupDao).get(anyObject());
162 vendorLicenseFacadeImpl.submit(VLM_ID, USER);
165 } catch (CoreException exception) {
166 org.testng.Assert.assertEquals(exception.code().message(), SUBMIT_UNCOMPLETED_VLM_MSG_FG_MISSING_EP.getErrorMessage());
170 private void resetFieldModifiers() {
172 Field fgField = VendorLicenseFacadeImpl.class.getDeclaredField("featureGroupDao");
173 fgField.setAccessible(true);
174 Field modifiersField = Field.class.getDeclaredField("modifiers");
175 modifiersField.setAccessible(true);
176 modifiersField.setInt(fgField, fgField.getModifiers() & ~Modifier.FINAL);
177 fgField.set(null, featureGroupDao);
179 Field epField = VendorLicenseFacadeImpl.class.getDeclaredField("entitlementPoolDao");
180 epField.setAccessible(true);
181 modifiersField = Field.class.getDeclaredField("modifiers");
182 modifiersField.setAccessible(true);
183 modifiersField.setInt(epField, epField.getModifiers() & ~Modifier.FINAL);
184 epField.set(null, entitlementPoolDao);
186 Field laField = VendorLicenseFacadeImpl.class.getDeclaredField("licenseAgreementDao");
187 laField.setAccessible(true);
188 modifiersField = Field.class.getDeclaredField("modifiers");
189 modifiersField.setAccessible(true);
190 modifiersField.setInt(laField, laField.getModifiers() & ~Modifier.FINAL);
191 laField.set(null, licenseAgreementDao);
192 } catch(NoSuchFieldException | IllegalAccessException e)
194 org.testng.Assert.fail();
198 private FeatureGroupEntity createFeatureGroup() {
199 FeatureGroupEntity featureGroup = new FeatureGroupEntity(VLM_ID, VERSION01, USER);
200 featureGroup.setManufacturerReferenceNumber(null);
201 VersionInfo info = new VersionInfo();
202 info.getViewableVersions().add(VERSION01);
203 info.setActiveVersion(VERSION01);
205 Set<String> entitlementPoolIds;
206 entitlementPoolIds = new HashSet<>();
207 entitlementPoolIds.add(EP1);
209 featureGroup.setEntitlementPoolIds(entitlementPoolIds);
213 private EntitlementPoolEntity createEP() {
214 EntitlementPoolEntity ep = new EntitlementPoolEntity(VLM_ID,VERSION01, EP1);
215 ep.setManufacturerReferenceNumber(MRN);