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;
24 import org.openecomp.core.util.UniqueValueUtil;
25 import org.openecomp.core.utilities.CommonMethods;
26 import org.openecomp.sdc.common.errors.CoreException;
27 import org.openecomp.sdc.vendorlicense.dao.types.AggregationFunction;
28 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementMetric;
29 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementPoolEntity;
30 import org.openecomp.sdc.vendorlicense.dao.types.EntitlementTime;
31 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity;
32 import org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupModel;
33 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyGroupEntity;
34 import org.openecomp.sdc.vendorlicense.dao.types.LicenseKeyType;
35 import org.openecomp.sdc.vendorlicense.dao.types.MultiChoiceOrOther;
36 import org.openecomp.sdc.vendorlicense.dao.types.OperationalScope;
37 import org.openecomp.sdc.vendorlicense.dao.types.ThresholdUnit;
38 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
39 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacadeFactory;
40 import org.openecomp.sdc.vendorlicense.impl.VendorLicenseManagerImpl;
41 import org.openecomp.sdc.versioning.dao.types.Version;
42 import org.testng.Assert;
43 import org.testng.annotations.Test;
45 import java.util.ArrayList;
46 import java.util.Collection;
47 import java.util.Collections;
48 import java.util.HashSet;
49 import java.util.List;
54 * Created by KATYR on 4/10/2016
57 public class FeatureGroupTest {
58 protected static final Version VERSION01 = new Version(0, 1);
59 protected static final String USER1 = "FeatureGroupTest_User1";
60 protected static VendorLicenseManager vendorLicenseManager = new VendorLicenseManagerImpl();
61 protected static VendorLicenseFacade vendorLicenseFacade =
62 VendorLicenseFacadeFactory.getInstance().createInterface();
66 public void testListFeatureGroups() throws Exception {
67 String vlmId = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest
68 .createVendorLicenseModel("vlmId_" + CommonMethods.nextUuId(), "vlm2Id desc", "icon2"),
71 fg22 = LicenseAgreementTest
72 .createFeatureGroup(vlmId, VERSION01, "fg2", "FG2", "FG2 desc", null, null);
73 String fg22Id = vendorLicenseManager.createFeatureGroup(fg22, USER1).getId();
74 FeatureGroupEntity fg33 = LicenseAgreementTest
75 .createFeatureGroup(vlmId, VERSION01, "fg3", "FG3", "FG3 desc", null, null);
76 String fg33Id = vendorLicenseManager.createFeatureGroup(fg33, USER1).getId();
78 Collection<FeatureGroupEntity> featureGroupEntities =
79 vendorLicenseManager.listFeatureGroups(vlmId, null, USER1);
81 Assert.assertEquals(featureGroupEntities.size(), 2);
82 Set<String> actualIds = new HashSet<>();
83 for (FeatureGroupEntity featureGroupEntity : featureGroupEntities) {
84 actualIds.add(featureGroupEntity.getId());
87 Set<String> expectedIds = new HashSet<>();
88 expectedIds.add(fg22Id);
89 expectedIds.add(fg33Id);
90 for (String id : actualIds) {
91 Assert.assertTrue(expectedIds.contains(id));
97 public void testCreateFeatureGroup() throws Exception {
98 String testName = "testCreateFeatureGroup";
99 String vlmId = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest
100 .createVendorLicenseModel(testName + CommonMethods.nextUuId(), testName, "icon1"), USER1)
102 Set<OperationalScope> opScopeChoices = new HashSet<>();
103 opScopeChoices.add(OperationalScope.Other);
104 opScopeChoices.add(OperationalScope.Data_Center);
105 opScopeChoices.add(OperationalScope.Network_Wide);
106 EntitlementPoolEntity
107 ep = EntitlementPoolTest
108 .createEntitlementPool(vlmId, VERSION01, "EP1" + CommonMethods.nextUuId(), "EP1 dec", 80,
109 ThresholdUnit.Absolute, EntitlementMetric.Core, null, "inc1", AggregationFunction.Other,
110 "agg func1", opScopeChoices, null, EntitlementTime.Hour, null, "sku1");
111 String epId = vendorLicenseManager.createEntitlementPool(ep, USER1).getId();
112 Set<OperationalScope> opScopeChoicesLKG = new HashSet<>();
113 opScopeChoicesLKG.add(OperationalScope.CPU);
114 opScopeChoicesLKG.add(OperationalScope.VM);
115 opScopeChoicesLKG.add(OperationalScope.Availability_Zone);
116 opScopeChoicesLKG.add(OperationalScope.Data_Center);
118 LicenseKeyGroupEntity
119 lkg = LicenseKeyGroupTest
120 .createLicenseKeyGroup(vlmId, VERSION01, "LKG1", "LKG1 dec", LicenseKeyType.One_Time,
121 new MultiChoiceOrOther<>(opScopeChoicesLKG, null));
122 String lkgId = vendorLicenseManager.createLicenseKeyGroup(lkg, USER1).getId();
124 FeatureGroupEntity fg1 =
125 createFGForTest(vlmId, "created" + CommonMethods.nextUuId(), Collections.singleton(epId),
126 Collections.singleton(lkgId));
127 FeatureGroupEntity fg1FromDB =
128 vendorLicenseManager.getFeatureGroupModel(fg1, USER1).getFeatureGroup();
129 Assert.assertTrue(fg1FromDB.equals(fg1));
134 public void testCreateWithExistingName_negative() {
135 String testName = "createExistingName";
136 String vlmId = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest
137 .createVendorLicenseModel(testName + CommonMethods.nextUuId(), testName, "icon1"), USER1)
139 createFGForTest(vlmId, "created", Collections.emptySet(), Collections.emptySet());
141 FeatureGroupEntity created = LicenseAgreementTest
142 .createFeatureGroup(vlmId, null, "created", "created", "created desc",
143 Collections.emptySet(), Collections.emptySet());
144 vendorLicenseManager.createFeatureGroup(created, USER1);
146 } catch (CoreException exception) {
147 Assert.assertEquals(exception.code().id(), UniqueValueUtil.UNIQUE_VALUE_VIOLATION);
151 private FeatureGroupEntity createFGForTest(String vlmId, String fgName, Set<String> epIds,
152 Set<String> lkgIds) {
153 FeatureGroupEntity created = LicenseAgreementTest
154 .createFeatureGroup(vlmId, null, null, fgName, "created desc", epIds, lkgIds);
155 return vendorLicenseManager.createFeatureGroup(created, USER1);
159 public void testUpdateFeatureGroup_addEP_andGET() throws Exception {
160 String testName = "testUpdateFeatureGroup_addEP_andGET";
161 String vlmId = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest
162 .createVendorLicenseModel(testName + CommonMethods.nextUuId(), testName, "icon1"), USER1)
165 FeatureGroupEntity fg5 = LicenseAgreementTest
166 .createFeatureGroup(vlmId, VERSION01, "id" + CommonMethods.nextUuId(),
167 "created" + CommonMethods.nextUuId(), "created desc", null, null);
168 vendorLicenseManager.createFeatureGroup(fg5, USER1).getId();
171 Set<OperationalScope> opScopeChoices = new HashSet<>();
172 opScopeChoices.add(OperationalScope.Other);
173 opScopeChoices.add(OperationalScope.Data_Center);
175 EntitlementPoolEntity epToAdd = EntitlementPoolTest
176 .createEntitlementPool(vlmId, VERSION01, "epToAdd", "epToAdd dec", 80,
177 ThresholdUnit.Absolute, EntitlementMetric.Core, null, "inc1", AggregationFunction.Other,
178 "agg func1", opScopeChoices, null, EntitlementTime.Hour, null, "sku1");
179 String epToAddId = vendorLicenseManager.createEntitlementPool(epToAdd, USER1).getId();
182 .updateFeatureGroup(fg5, null, null, CommonMethods.toSingleElementSet(epToAddId), null,
184 FeatureGroupModel updatedFG = vendorLicenseManager.getFeatureGroupModel(fg5, USER1);
185 Set<EntitlementPoolEntity> updatedEPs = updatedFG.getEntitlementPools();
187 epToAdd.setReferencingFeatureGroups(CommonMethods.toSingleElementSet(fg5.getId()));
189 Assert.assertEquals(updatedEPs.size(), 1);
190 for (EntitlementPoolEntity updatedEP : updatedEPs) {
191 Assert.assertTrue(updatedEP.getReferencingFeatureGroups().contains(fg5.getId()));
192 Assert.assertEquals(updatedEP.getId(), epToAddId);
197 public void testUpdateFeatureGroup_removeLKG_andGET() throws Exception {
198 String testName = "testUpdateFeatureGroup_removeLKG_andGET";
199 String vlmId = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest
200 .createVendorLicenseModel(testName + CommonMethods.nextUuId(), testName, "icon1"), USER1)
203 Set<OperationalScope> opScopeChoicesLKG = new HashSet<>();
204 opScopeChoicesLKG.add(OperationalScope.CPU);
205 opScopeChoicesLKG.add(OperationalScope.VM);
206 opScopeChoicesLKG.add(OperationalScope.Availability_Zone);
207 opScopeChoicesLKG.add(OperationalScope.Data_Center);
208 LicenseKeyGroupEntity lkg = LicenseKeyGroupTest
209 .createLicenseKeyGroup(vlmId, VERSION01, "lkg" + CommonMethods.nextUuId(), "lkg desc",
210 LicenseKeyType.Unique, new MultiChoiceOrOther<>(opScopeChoicesLKG, null));
211 String lkgId = vendorLicenseManager.createLicenseKeyGroup(lkg, USER1).getId();
214 LicenseKeyGroupEntity lkg_1 = LicenseKeyGroupTest
215 .createLicenseKeyGroup(vlmId, VERSION01, "lkg" + CommonMethods.nextUuId(), "lkg_1 desc",
216 LicenseKeyType.Unique, new MultiChoiceOrOther<>(opScopeChoicesLKG, null));
217 String lkgId_1 = vendorLicenseManager.createLicenseKeyGroup(lkg_1, USER1).getId();
220 Set<OperationalScope> opScopeChoices = new HashSet<>();
221 opScopeChoices.add(OperationalScope.Other);
222 opScopeChoices.add(OperationalScope.Data_Center);
223 opScopeChoices.add(OperationalScope.Network_Wide);
224 EntitlementPoolEntity ep = EntitlementPoolTest
225 .createEntitlementPool(vlmId, VERSION01, "EP1" + CommonMethods.nextUuId(), "EP1 dec", 80,
226 ThresholdUnit.Absolute, EntitlementMetric.Core, null, "inc1", AggregationFunction.Other,
227 "agg func1", opScopeChoices, null, EntitlementTime.Hour, null, "sku1");
228 String epId = vendorLicenseManager.createEntitlementPool(ep, USER1).getId();
230 Set<String> lkgs = new HashSet<>();
234 FeatureGroupEntity fg = LicenseAgreementTest
235 .createFeatureGroup(vlmId, VERSION01, "fg11" + CommonMethods.nextUuId(), "FG1", "FG1 desc",
236 CommonMethods.toSingleElementSet(epId), lkgs);
237 String fgId = vendorLicenseManager.createFeatureGroup(fg, USER1).getId();
239 .updateFeatureGroup(fg, null, CommonMethods.toSingleElementSet(lkgId), null, null, USER1);
241 FeatureGroupModel featureGroup = vendorLicenseManager.getFeatureGroupModel(fg, USER1);
242 Set<LicenseKeyGroupEntity> licenseKeyGroups = featureGroup.getLicenseKeyGroups();
243 Assert.assertEquals(licenseKeyGroups.size(), 1);
244 List<String> lkgIds = new ArrayList<>();
245 for (LicenseKeyGroupEntity licenseKeyGroup : licenseKeyGroups) {
246 lkgIds.add(licenseKeyGroup.getId());
249 Assert.assertTrue(lkgIds.contains(lkgId_1));
250 Assert.assertFalse(lkgIds.contains(lkgId));
256 public void testDeleteFeatureGroup() throws Exception {
257 String testName = "testDeleteFeatureGroup";
258 String vlmId = vendorLicenseFacade.createVendorLicenseModel(VendorLicenseModelTest
259 .createVendorLicenseModel(testName + CommonMethods.nextUuId(), testName, "icon1"), USER1)
262 FeatureGroupEntity fg1 =
263 createFGForTest(vlmId, "new", Collections.emptySet(), Collections.emptySet());
264 FeatureGroupEntity fg2 =
265 createFGForTest(vlmId, "newer", Collections.emptySet(), Collections.emptySet());
266 Collection<FeatureGroupEntity> featureGroupEntities =
267 vendorLicenseManager.listFeatureGroups(vlmId, null, USER1);
268 Assert.assertEquals(featureGroupEntities.size(), 2); //precondition
270 vendorLicenseManager.deleteFeatureGroup(fg1, USER1);
271 Assert.assertEquals(vendorLicenseManager.listFeatureGroups(vlmId, null, USER1).size(), 1);