1 package org.openecomp.sdc.vendorlicense;
4 * This test just verifies Feature Group Get and List APIs.
6 public class VendorLicenseFacadeImplTest {
9 //JUnit Test Cases using Mockito
10 private static final Version VERSION01 = new Version(0, 1);
11 public static final String EP1 = "ep1";
12 public static final String MRN = "mrn";
13 public static final String VLM_ID = "VLM_ID";
14 public static final String USER = "USER1";
18 private VendorLicenseModelDao vendorLicenseModelDao;
21 private LicenseAgreementDao licenseAgreementDao;
24 private FeatureGroupDao featureGroupDao;
27 private EntitlementPoolDao entitlementPoolDao;
30 private LicenseKeyGroupDao licenseKeyGroupDao;
33 private VersioningManager versioningManager;
37 private VendorLicenseFacadeImpl vendorLicenseFacadeImpl;
40 public void setUp() throws Exception{
41 MockitoAnnotations.initMocks(this);
45 public void testGetFeatureGroupWhenMRNNull () {
46 resetFieldModifiers();
48 FeatureGroupEntity featureGroup = createFeatureGroup();
50 VersionInfo info = new VersionInfo();
51 info.getViewableVersions().add(VERSION01);
52 info.setActiveVersion(VERSION01);
54 Set<String> entitlementPoolIds;
55 entitlementPoolIds = new HashSet<>();
56 entitlementPoolIds.add(EP1);
58 EntitlementPoolEntity ep = createEP();
60 featureGroup.setEntitlementPoolIds(entitlementPoolIds);
62 doReturn(info).when(vendorLicenseFacadeImpl).getVersionInfo(anyObject(),anyObject(),anyObject());
63 doReturn(featureGroup).when(featureGroupDao).get(featureGroup);
64 doReturn(ep).when(entitlementPoolDao).get(anyObject());
65 doReturn(MRN).when(entitlementPoolDao).getManufacturerReferenceNumber(anyObject());
66 FeatureGroupEntity retrieved = vendorLicenseFacadeImpl.getFeatureGroup(featureGroup, USER);
67 Assert.assertEquals(MRN, retrieved.getManufacturerReferenceNumber());
71 public void testListFeatureGroups () {
72 resetFieldModifiers();
74 FeatureGroupEntity featureGroup = createFeatureGroup();
76 Collection<FeatureGroupEntity> featureGroups = new ArrayList<FeatureGroupEntity>();
77 featureGroups.add(featureGroup);
79 VersionInfo info = new VersionInfo();
80 info.getViewableVersions().add(VERSION01);
81 info.setActiveVersion(VERSION01);
83 EntitlementPoolEntity ep = createEP();
85 doReturn(info).when(vendorLicenseFacadeImpl).getVersionInfo(anyObject(),anyObject(),anyObject());
86 doReturn(featureGroup).when(featureGroupDao).get(featureGroup);
87 doReturn(ep).when(entitlementPoolDao).get(anyObject());
88 doReturn(MRN).when(entitlementPoolDao).getManufacturerReferenceNumber(anyObject());
89 Collection<FeatureGroupEntity> retrieved = vendorLicenseFacadeImpl.listFeatureGroups(VLM_ID,
91 retrieved.stream().forEach(fg -> Assert.assertEquals(MRN,fg.getManufacturerReferenceNumber()));
95 public void testSubmitLAWithoutFG()
98 resetFieldModifiers();
100 VersionInfo info = new VersionInfo();
101 info.getViewableVersions().add(VERSION01);
102 info.setActiveVersion(VERSION01);
104 LicenseAgreementEntity licenseAgreementEntity = new LicenseAgreementEntity();
105 List<LicenseAgreementEntity> licenseAgreementEntities = new ArrayList<LicenseAgreementEntity>(){{
106 add(licenseAgreementEntity);
109 doReturn(info).when(vendorLicenseFacadeImpl).getVersionInfo(anyObject(),anyObject(),anyObject());
110 doReturn(licenseAgreementEntities).when(licenseAgreementDao).list(anyObject());
112 vendorLicenseFacadeImpl.submit(VLM_ID, USER);
114 } catch (CoreException exception) {
115 org.testng.Assert.assertEquals(exception.code().message(), SUBMIT_UNCOMPLETED_VLM_MSG_LA_MISSING_FG.getErrorMessage());
120 public void testSubmitLAWithFGWithoutEP()
123 resetFieldModifiers();
125 VersionInfo info = new VersionInfo();
126 info.getViewableVersions().add(VERSION01);
127 info.setActiveVersion(VERSION01);
129 LicenseAgreementEntity licenseAgreementEntity = new LicenseAgreementEntity();
130 FeatureGroupEntity featureGroupEntity = new FeatureGroupEntity();
131 licenseAgreementEntity.setFeatureGroupIds(new HashSet<String>(){{
132 add("54654654asdas5");
134 List<LicenseAgreementEntity> licenseAgreementEntities = new ArrayList<LicenseAgreementEntity>(){{
135 add(licenseAgreementEntity);
138 doReturn(info).when(vendorLicenseFacadeImpl).getVersionInfo(anyObject(),anyObject(),anyObject());
139 doReturn(licenseAgreementEntities).when(licenseAgreementDao).list(anyObject());
140 doReturn(featureGroupEntity).when(featureGroupDao).get(anyObject());
142 vendorLicenseFacadeImpl.submit(VLM_ID, USER);
145 } catch (CoreException exception) {
146 org.testng.Assert.assertEquals(exception.code().message(), SUBMIT_UNCOMPLETED_VLM_MSG_FG_MISSING_EP.getErrorMessage());
150 private void resetFieldModifiers() {
152 Field fgField = VendorLicenseFacadeImpl.class.getDeclaredField("featureGroupDao");
153 fgField.setAccessible(true);
154 Field modifiersField = Field.class.getDeclaredField("modifiers");
155 modifiersField.setAccessible(true);
156 modifiersField.setInt(fgField, fgField.getModifiers() & ~Modifier.FINAL);
157 fgField.set(null, featureGroupDao);
159 Field epField = VendorLicenseFacadeImpl.class.getDeclaredField("entitlementPoolDao");
160 epField.setAccessible(true);
161 modifiersField = Field.class.getDeclaredField("modifiers");
162 modifiersField.setAccessible(true);
163 modifiersField.setInt(epField, epField.getModifiers() & ~Modifier.FINAL);
164 epField.set(null, entitlementPoolDao);
166 Field laField = VendorLicenseFacadeImpl.class.getDeclaredField("licenseAgreementDao");
167 laField.setAccessible(true);
168 modifiersField = Field.class.getDeclaredField("modifiers");
169 modifiersField.setAccessible(true);
170 modifiersField.setInt(laField, laField.getModifiers() & ~Modifier.FINAL);
171 laField.set(null, licenseAgreementDao);
172 } catch(NoSuchFieldException | IllegalAccessException e)
174 org.testng.Assert.fail();
178 private FeatureGroupEntity createFeatureGroup() {
179 FeatureGroupEntity featureGroup = new FeatureGroupEntity(VLM_ID, VERSION01, USER);
180 featureGroup.setManufacturerReferenceNumber(null);
181 VersionInfo info = new VersionInfo();
182 info.getViewableVersions().add(VERSION01);
183 info.setActiveVersion(VERSION01);
185 Set<String> entitlementPoolIds;
186 entitlementPoolIds = new HashSet<>();
187 entitlementPoolIds.add(EP1);
189 featureGroup.setEntitlementPoolIds(entitlementPoolIds);
193 private EntitlementPoolEntity createEP() {
194 EntitlementPoolEntity ep = new EntitlementPoolEntity(VLM_ID,VERSION01, EP1);
195 ep.setManufacturerReferenceNumber(MRN);