Add collaboration feature
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-license-manager / src / test / java / org / openecomp / sdc / vendorlicense / VendorLicenseFacadeImplTest.java
1 package org.openecomp.sdc.vendorlicense;
2
3 /**
4  * This test just verifies Feature Group Get and List APIs.
5  */
6 public class VendorLicenseFacadeImplTest {
7     /*
8
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";
15
16
17     @Mock
18     private VendorLicenseModelDao vendorLicenseModelDao;
19
20     @Mock
21     private LicenseAgreementDao licenseAgreementDao;
22
23     @Mock
24     private FeatureGroupDao featureGroupDao;
25
26     @Mock
27     private EntitlementPoolDao entitlementPoolDao;
28
29     @Mock
30     private LicenseKeyGroupDao licenseKeyGroupDao;
31
32     @Mock
33     private VersioningManager versioningManager;
34
35     @InjectMocks
36     @Spy
37     private VendorLicenseFacadeImpl vendorLicenseFacadeImpl;
38
39     @BeforeMethod
40     public void setUp() throws Exception{
41         MockitoAnnotations.initMocks(this);
42     }
43
44     @Test
45     public void testGetFeatureGroupWhenMRNNull () {
46         resetFieldModifiers();
47
48         FeatureGroupEntity featureGroup = createFeatureGroup();
49
50         VersionInfo info = new VersionInfo();
51         info.getViewableVersions().add(VERSION01);
52         info.setActiveVersion(VERSION01);
53
54         Set<String> entitlementPoolIds;
55         entitlementPoolIds = new HashSet<>();
56         entitlementPoolIds.add(EP1);
57
58         EntitlementPoolEntity ep = createEP();
59
60         featureGroup.setEntitlementPoolIds(entitlementPoolIds);
61
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());
68     }
69
70     @Test
71     public void testListFeatureGroups () {
72         resetFieldModifiers();
73
74         FeatureGroupEntity featureGroup = createFeatureGroup();
75
76         Collection<FeatureGroupEntity> featureGroups = new ArrayList<FeatureGroupEntity>();
77         featureGroups.add(featureGroup);
78
79         VersionInfo info = new VersionInfo();
80         info.getViewableVersions().add(VERSION01);
81         info.setActiveVersion(VERSION01);
82
83         EntitlementPoolEntity ep = createEP();
84
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,
90             VERSION01, USER);
91         retrieved.stream().forEach(fg -> Assert.assertEquals(MRN,fg.getManufacturerReferenceNumber()));
92     }
93
94     @Test
95     public void testSubmitLAWithoutFG()
96     {
97         try {
98             resetFieldModifiers();
99
100             VersionInfo info = new VersionInfo();
101             info.getViewableVersions().add(VERSION01);
102             info.setActiveVersion(VERSION01);
103
104             LicenseAgreementEntity licenseAgreementEntity = new LicenseAgreementEntity();
105             List<LicenseAgreementEntity> licenseAgreementEntities = new ArrayList<LicenseAgreementEntity>(){{
106                 add(licenseAgreementEntity);
107             }};
108
109             doReturn(info).when(vendorLicenseFacadeImpl).getVersionInfo(anyObject(),anyObject(),anyObject());
110             doReturn(licenseAgreementEntities).when(licenseAgreementDao).list(anyObject());
111
112             vendorLicenseFacadeImpl.submit(VLM_ID, USER);
113             Assert.fail();
114         } catch (CoreException exception) {
115             org.testng.Assert.assertEquals(exception.code().message(), SUBMIT_UNCOMPLETED_VLM_MSG_LA_MISSING_FG.getErrorMessage());
116         }
117     }
118
119     @Test
120     public void testSubmitLAWithFGWithoutEP()
121     {
122         try {
123             resetFieldModifiers();
124
125             VersionInfo info = new VersionInfo();
126             info.getViewableVersions().add(VERSION01);
127             info.setActiveVersion(VERSION01);
128
129             LicenseAgreementEntity licenseAgreementEntity = new LicenseAgreementEntity();
130             FeatureGroupEntity featureGroupEntity = new FeatureGroupEntity();
131             licenseAgreementEntity.setFeatureGroupIds(new HashSet<String>(){{
132                 add("54654654asdas5");
133             }});
134             List<LicenseAgreementEntity> licenseAgreementEntities = new ArrayList<LicenseAgreementEntity>(){{
135                 add(licenseAgreementEntity);
136             }};
137
138             doReturn(info).when(vendorLicenseFacadeImpl).getVersionInfo(anyObject(),anyObject(),anyObject());
139             doReturn(licenseAgreementEntities).when(licenseAgreementDao).list(anyObject());
140             doReturn(featureGroupEntity).when(featureGroupDao).get(anyObject());
141
142             vendorLicenseFacadeImpl.submit(VLM_ID, USER);
143
144             Assert.fail();
145         } catch (CoreException exception) {
146             org.testng.Assert.assertEquals(exception.code().message(), SUBMIT_UNCOMPLETED_VLM_MSG_FG_MISSING_EP.getErrorMessage());
147         }
148     }
149
150     private void resetFieldModifiers() {
151         try {
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);
158
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);
165
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)
173         {
174             org.testng.Assert.fail();
175         }
176     }
177
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);
184
185         Set<String> entitlementPoolIds;
186         entitlementPoolIds = new HashSet<>();
187         entitlementPoolIds.add(EP1);
188
189         featureGroup.setEntitlementPoolIds(entitlementPoolIds);
190         return featureGroup;
191     }
192
193     private EntitlementPoolEntity createEP() {
194         EntitlementPoolEntity ep = new EntitlementPoolEntity(VLM_ID,VERSION01, EP1);
195         ep.setManufacturerReferenceNumber(MRN);
196         return ep;
197     }
198 */
199 }