2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 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=========================================================
22 package org.openecomp.sdc.vendorlicense.impl;
24 import org.mockito.InjectMocks;
25 import org.mockito.Mock;
26 import org.mockito.MockitoAnnotations;
27 import org.mockito.Spy;
28 import org.openecomp.sdc.vendorlicense.VendorLicenseConstants;
29 import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao;
30 import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao;
31 import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDao;
32 import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao;
33 import org.openecomp.sdc.vendorlicense.dao.LimitDao;
34 import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDao;
35 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
36 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
37 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
38 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
39 import org.openecomp.sdc.versioning.VersioningManager;
40 import org.openecomp.sdc.versioning.dao.types.Version;
41 import org.testng.Assert;
42 import org.testng.annotations.BeforeMethod;
43 import org.testng.annotations.Test;
45 import java.util.Arrays;
46 import java.util.Collection;
47 import java.util.HashSet;
50 import static org.mockito.Matchers.anyObject;
51 import static org.mockito.Mockito.doNothing;
52 import static org.mockito.Mockito.doReturn;
53 import static org.mockito.Mockito.verify;
56 * Created by KATYR on 4/10/2016
59 public class FeatureGroupTest {
60 //JUnit Test Cases using Mockito
61 private static final Version VERSION01 = new Version(0, 1);
62 private static final Version VERSION10 = new Version(1, 0);
63 private final String FG1_NAME = "FG1 name";
64 private static final String USER1 = "TestUser1";
65 private static final String USER2 = "TestUser2";
67 private static String vlm1_id = "vlm1_id";
68 private static String vlm2_id = "vlm2_id";
69 private static String lkg1_id = "lkg1_id";
70 private static String lkg2_id = "lkg2_id";
71 private static String fg1_id = "fg1_id";
72 private static String fg2_id = "fg2_id";
73 private static String ep1_id = "ep1_id";
74 private static String ep2_id = "ep2_id";
77 private VendorLicenseFacade vendorLicenseFacadeMcok;
80 private LimitDao limitDaoMcok;
83 private VendorLicenseModelDao vendorLicenseModelDao;
86 private LicenseAgreementDao licenseAgreementDao;
89 private FeatureGroupDao featureGroupDao;
92 private EntitlementPoolDao entitlementPoolDao;
95 private LicenseKeyGroupDao licenseKeyGroupDao;
98 private VersioningManager versioningManager;
102 private VendorLicenseManagerImpl vendorLicenseManagerImpl;
104 public FeatureGroupEntity updateFeatureGroup(String vlmId, Version version, String id,
105 String name, String desc,
107 String manufacturerReferenceNumber, Set<String>
109 Set<String> entitlementPoolIds, Set<String>
110 referencingLicenseAgreements) {
111 FeatureGroupEntity featureGroup = new FeatureGroupEntity(vlmId, version, id);
112 featureGroup.setVendorLicenseModelId(vlmId);
113 featureGroup.setVersion(version);
114 featureGroup.setId(id);
115 featureGroup.setName(name);
116 featureGroup.setDescription(desc);
117 featureGroup.setPartNumber(partNumber);
118 //featureGroup.setManufacturerReferenceNumber(manufacturerReferenceNumber);
119 featureGroup.setLicenseKeyGroupIds(licenseKeyGroupIds);
120 featureGroup.setEntitlementPoolIds(entitlementPoolIds);
121 featureGroup.setReferencingLicenseAgreements(referencingLicenseAgreements);
127 public void setUp() throws Exception {
128 MockitoAnnotations.initMocks(this);
132 public void testUpdate() {
133 Set<String> licenseKeyGroupIds;
134 licenseKeyGroupIds = new HashSet<>();
135 licenseKeyGroupIds.add("lkg1");
137 Set<String> entitlementPoolIds;
138 entitlementPoolIds = new HashSet<>();
139 entitlementPoolIds.add("ep1");
141 Set<String> referencingLicenseAgreements;
142 referencingLicenseAgreements = new HashSet<>();
143 referencingLicenseAgreements.add("la1");
145 FeatureGroupEntity featureGroupEntity =
146 updateFeatureGroup("vlmId", VERSION01, "fgId", FG1_NAME, "fg1 desc",
147 "partNumber", "MRN", licenseKeyGroupIds, entitlementPoolIds,
148 referencingLicenseAgreements);
150 doReturn(featureGroupEntity).when(featureGroupDao).get(anyObject());
152 /*if(featureGroupEntity.getManufacturerReferenceNumber() != null)
153 featureGroupDao.update(featureGroupEntity);
154 verify(featureGroupDao).update(anyObject());*/
158 public void testUpdateWithoutManufacturingReferenceNumber() {
159 Set<String> licenseKeyGroupIds;
160 licenseKeyGroupIds = new HashSet<>();
161 licenseKeyGroupIds.add("lkg1");
163 Set<String> entitlementPoolIds;
164 entitlementPoolIds = new HashSet<>();
165 entitlementPoolIds.add("ep1");
167 Set<String> referencingLicenseAgreements;
168 referencingLicenseAgreements = new HashSet<>();
169 referencingLicenseAgreements.add("la1");
171 FeatureGroupEntity featureGroupEntity =
172 updateFeatureGroup("vlmId", VERSION01, "fgId", FG1_NAME, "fg1 desc",
173 "partNumber", null, licenseKeyGroupIds, entitlementPoolIds,
174 referencingLicenseAgreements);
176 doReturn(featureGroupEntity).when(featureGroupDao).get(anyObject());
178 /*if(featureGroupEntity.getManufacturerReferenceNumber() != null)
179 featureGroupDao.update(featureGroupEntity);
180 verify(featureGroupDao, never()).update(anyObject());*/
184 public void testListFeatureGroups() {
185 doReturn(Arrays.asList(
186 createFeatureGroup(vlm1_id, VERSION01, fg1_id, "FG1", "FG1 desc", new HashSet<String>(),
187 new HashSet<String>()),
188 createFeatureGroup(vlm1_id, VERSION01, fg2_id, "FG2", "FG2 desc", new HashSet<String>(),
189 new HashSet<String>())))
190 .when(vendorLicenseFacadeMcok).listFeatureGroups(vlm1_id, VERSION01);
192 Collection<FeatureGroupEntity> FGs =
193 vendorLicenseManagerImpl.listFeatureGroups(vlm1_id, VERSION01);
195 verify(vendorLicenseFacadeMcok).listFeatureGroups(vlm1_id, VERSION01);
196 Assert.assertEquals(FGs.size(), 2);
197 FGs.forEach(fg -> Assert.assertTrue(fg.getId().matches(fg1_id + "|" + fg2_id)));
201 public void testCreateFeatureGroup() {
202 FeatureGroupEntity featureGroupEntity = new FeatureGroupEntity(vlm1_id, VERSION01,
205 doReturn(featureGroupEntity).when(vendorLicenseFacadeMcok).createFeatureGroup
206 (featureGroupEntity);
208 vendorLicenseManagerImpl.createFeatureGroup(featureGroupEntity);
210 verify(vendorLicenseFacadeMcok).createFeatureGroup(featureGroupEntity);
215 public void testUpdateFeatureGroup() {
216 FeatureGroupEntity existingFG = new FeatureGroupEntity(vlm1_id, VERSION01, fg1_id);
218 existingFG.setEntitlementPoolIds(new HashSet<String>());
219 existingFG.setLicenseKeyGroupIds(new HashSet<String>());
221 doReturn(existingFG).when(featureGroupDao).get(existingFG);
223 Set<String> removedEPs = new HashSet<>();
224 Set<String> addedEPs = new HashSet<>();
226 addedEPs.add(ep1_id);
227 addedEPs.add(ep2_id);
228 EntitlementPoolEntity ep1 = new EntitlementPoolEntity(vlm1_id, VERSION01, ep1_id);
229 EntitlementPoolEntity ep2 = new EntitlementPoolEntity(vlm1_id, VERSION01, ep2_id);
230 doReturn(ep1).when(entitlementPoolDao).get(ep1);
231 doReturn(ep2).when(entitlementPoolDao).get(ep2);
233 Set<String> removedLKGs = new HashSet<>();
234 Set<String> addedLKGs = new HashSet<>();
236 addedLKGs.add(lkg1_id);
237 addedLKGs.add(lkg2_id);
238 LicenseKeyGroupEntity lkg1 = new LicenseKeyGroupEntity(vlm1_id, VERSION01, lkg1_id);
239 LicenseKeyGroupEntity lkg2 = new LicenseKeyGroupEntity(vlm1_id, VERSION01, lkg2_id);
240 doReturn(lkg1).when(licenseKeyGroupDao).get(lkg1);
241 doReturn(lkg2).when(licenseKeyGroupDao).get(lkg2);
243 doNothing().when(vendorLicenseManagerImpl).updateUniqueName(anyObject(), anyObject(),
244 anyObject(), anyObject(), anyObject());
246 vendorLicenseManagerImpl.updateFeatureGroup(existingFG, addedLKGs, removedLKGs, addedEPs,
249 verify(vendorLicenseManagerImpl).addLicenseKeyGroupsToFeatureGroupsRef(addedLKGs,
251 verify(vendorLicenseManagerImpl).removeLicenseKeyGroupsToFeatureGroupsRef(removedLKGs,
253 verify(vendorLicenseManagerImpl).addEntitlementPoolsToFeatureGroupsRef(addedEPs, existingFG);
254 verify(vendorLicenseManagerImpl).removeEntitlementPoolsToFeatureGroupsRef(removedEPs,
257 verify(featureGroupDao)
258 .updateFeatureGroup(existingFG, addedEPs, removedEPs, addedLKGs, removedLKGs);
263 public void testGetFeatureGroup() {
264 FeatureGroupEntity featureGroupEntity = new FeatureGroupEntity(vlm1_id, VERSION01, fg1_id);
265 vendorLicenseManagerImpl.getFeatureGroupModel(featureGroupEntity);
266 verify(vendorLicenseFacadeMcok).getFeatureGroupModel(featureGroupEntity);
270 public void deleteFeatureGroupTest() {
272 FeatureGroupEntity existingFG = new FeatureGroupEntity(vlm1_id, VERSION01, fg1_id);
273 existingFG.setName("FG_name");
274 existingFG.setLicenseKeyGroupIds(new HashSet<String>());
275 existingFG.setEntitlementPoolIds(new HashSet<String>());
276 existingFG.setLicenseKeyGroupIds(new HashSet<String>());
278 doReturn(existingFG).when(featureGroupDao).get(anyObject());
280 doNothing().when(vendorLicenseManagerImpl).deleteUniqueName(VendorLicenseConstants
281 .UniqueValues.FEATURE_GROUP_NAME, vlm1_id, VERSION01.toString(), existingFG.getName());
283 vendorLicenseManagerImpl.deleteFeatureGroup(existingFG);
285 verify(featureGroupDao).delete(existingFG);
287 verify(vendorLicenseManagerImpl).removeLicenseKeyGroupsToFeatureGroupsRef(existingFG
288 .getLicenseKeyGroupIds(), existingFG);
289 verify(vendorLicenseManagerImpl).removeEntitlementPoolsToFeatureGroupsRef(existingFG
290 .getEntitlementPoolIds(), existingFG);
291 verify(vendorLicenseManagerImpl).deleteUniqueName(VendorLicenseConstants
292 .UniqueValues.FEATURE_GROUP_NAME, vlm1_id, VERSION01.toString(), existingFG.getName());
295 private FeatureGroupEntity createFeatureGroup(String vendorId, Version version, String id,
296 String name, String description,
297 Set<String> entitlementPoolIds,
298 Set<String> licenseKeyGroupIds) {
299 FeatureGroupEntity featureGroup = new FeatureGroupEntity();
300 featureGroup.setVendorLicenseModelId(vendorId);
301 featureGroup.setVersion(version);
302 featureGroup.setId(id);
303 featureGroup.setName(name);
304 featureGroup.setDescription(description);
305 featureGroup.setEntitlementPoolIds(entitlementPoolIds);
306 featureGroup.setLicenseKeyGroupIds(licenseKeyGroupIds);