1 package org.openecomp.sdc.vendorlicense;
3 import org.openecomp.sdc.common.errors.CoreException;
4 import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDaoFactory;
5 import org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm;
6 import org.openecomp.sdc.vendorlicense.impl.VendorLicenseManagerImpl;
7 import org.openecomp.sdc.versioning.dao.types.Version;
8 import org.openecomp.core.util.UniqueValueUtil;
9 import org.openecomp.core.utilities.CommonMethods;
10 import org.testng.Assert;
11 import org.testng.annotations.BeforeClass;
12 import org.testng.annotations.Test;
14 import java.util.Collection;
15 import java.util.HashSet;
18 public class LicenseAgreementTest {
19 private static final Version VERSION01 = new Version(0, 1);
20 private static final String USER1 = "user1";
21 private static final String LA1_NAME = "LA1 Name";
23 private static VendorLicenseManager vendorLicenseManager = new VendorLicenseManagerImpl();
24 private static org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao featureGroupDao;
25 private static org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDao licenseAgreementDao;
27 private static String vlm1Id;
28 private static String vlm2Id;
29 private static String la1Id;
30 private static String la2Id;
32 public static org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity createLicenseAgreement(String vlmId, Version version,
33 String id, String name, String desc,
34 String requirementsAndConstrains,
35 org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther<LicenseTerm> term,
37 org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity
38 la = new org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity();
39 la.setVendorLicenseModelId(vlmId);
40 la.setVersion(version);
43 la.setDescription(desc);
44 la.setLicenseTerm(term);
45 la.setRequirementsAndConstrains(requirementsAndConstrains);
46 for (String fgId : fgIds) {
47 la.getFeatureGroupIds().add(fgId);
52 public static org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity createFeatureGroup(String vendorId, Version version, String id,
53 String name, String description,
54 Set<String> entitlementPoolIds,
55 Set<String> licenseKeyGroupIds) {
56 org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity
57 featureGroup = new org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity();
58 featureGroup.setVendorLicenseModelId(vendorId);
59 featureGroup.setVersion(version);
60 featureGroup.setId(id);
61 featureGroup.setName(name);
62 featureGroup.setDescription(description);
63 featureGroup.setEntitlementPoolIds(entitlementPoolIds);
64 featureGroup.setLicenseKeyGroupIds(licenseKeyGroupIds);
70 licenseAgreementDao = org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDaoFactory.getInstance().createInterface();
71 featureGroupDao = FeatureGroupDaoFactory.getInstance().createInterface();
72 vlm1Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
73 .createVendorLicenseModel("vendor1 name " + CommonMethods.nextUuId(), "vlm1 dec", "icon1"),
75 vlm2Id = vendorLicenseManager.createVendorLicenseModel(VendorLicenseModelTest
76 .createVendorLicenseModel("vendor2 name " + CommonMethods.nextUuId(), "vlm2 dec", "icon2"),
81 public void createLicenseAgreementTest() {
82 la1Id = testCreate(vlm1Id, LA1_NAME);
85 private String testCreate(String vlmId, String name) {
86 org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity fg1 =
87 createFeatureGroup(vlmId, VERSION01, "fg11", "FG1", "FG1 desc", null, null);
88 featureGroupDao.create(fg1);
90 org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity
91 la1 = createLicenseAgreement(vlmId, VERSION01, null, name, "LA1 desc",
92 "RequirementsAndConstrains1", new org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther<>(
93 org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm.Unlimited, null), "fg11");
94 la1 = vendorLicenseManager.createLicenseAgreement(la1, USER1);
95 String la1Id = la1.getId();
97 org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity loadedLa1 = licenseAgreementDao.get(la1);
98 Assert.assertTrue(loadedLa1.equals(la1));
102 @Test(dependsOnMethods = {"createLicenseAgreementTest"})
103 public void testCreateWithExistingName_negative() {
105 org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity la1 =
106 createLicenseAgreement(vlm1Id, VERSION01, null, LA1_NAME, "LA1 desc",
107 "RequirementsAndConstrains1", new org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther<>(
108 org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm.Unlimited, null),
110 vendorLicenseManager.createLicenseAgreement(la1, USER1);
112 } catch (CoreException e) {
113 Assert.assertEquals(e.code().id(), UniqueValueUtil.UNIQUE_VALUE_VIOLATION);
117 @Test(dependsOnMethods = {"createLicenseAgreementTest"})
118 public void testCreateWithExistingNameUnderOtherVlm() {
119 testCreate(vlm2Id, LA1_NAME);
122 @Test(dependsOnMethods = {"testCreateWithExistingName_negative"})
123 public void updateLicenseAgreementTest() {
124 org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity fg2 =
125 createFeatureGroup(vlm1Id, VERSION01, "fg2", "FG2", "FG2 desc", null, null);
126 featureGroupDao.create(fg2);
128 org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity fg3 =
129 createFeatureGroup(vlm1Id, VERSION01, "fg3", "FG3", "FG3 desc", null, null);
130 featureGroupDao.create(fg3);
132 org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity la1 =
133 licenseAgreementDao.get(new org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity(vlm1Id, VERSION01, la1Id));
134 la1.setDescription("LA1 desc updated");
135 la1.setLicenseTerm(new org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther<>(
136 org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm.Other, "bla bla term"));
137 la1.getFeatureGroupIds().add("fg2");
138 la1.getFeatureGroupIds().add("fg3");
139 la1.getFeatureGroupIds().remove("fg11");
141 Set<String> addedFeatureGroupIds = new HashSet<>();
142 addedFeatureGroupIds.add("fg2");
143 addedFeatureGroupIds.add("fg3");
145 Set<String> removedFeatureGroupIds = new HashSet<>();
146 removedFeatureGroupIds.add("fg11");
149 .updateLicenseAgreement(la1, addedFeatureGroupIds, removedFeatureGroupIds, USER1);
151 org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity loadedLa1 =
152 licenseAgreementDao.get(new org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity(vlm1Id, VERSION01, la1Id));
153 Assert.assertTrue(loadedLa1.equals(la1));
157 @Test(dependsOnMethods = {"updateLicenseAgreementTest"})
158 public void listLicenseAgreementsTest() {
159 org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity
160 la2 = createLicenseAgreement(vlm1Id, VERSION01, null, "LA2", "LA2 desc",
161 "RequirementsAndConstrains2", new org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther<>(
162 org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm.Unlimited, null), "fg2");
163 la2 = vendorLicenseManager.createLicenseAgreement(la2, USER1);
166 Collection<org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity> loadedLas =
167 vendorLicenseManager.listLicenseAgreements(vlm1Id, null, USER1);
168 Assert.assertEquals(loadedLas.size(), 2);
169 boolean la2Exists = false;
170 for (org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity loadedLa : loadedLas) {
171 if (la2Id.equals(loadedLa.getId())) {
172 Assert.assertTrue(loadedLa.equals(la2));
177 Assert.assertTrue(la2Exists);
180 @Test(dependsOnMethods = {"listLicenseAgreementsTest"})
181 public void featureGroupDeletedLicenseAgreementUpdated() {
182 org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity licenseAgreement =
183 createLicenseAgreement(vlm1Id, VERSION01, "laId", "LA2", "LA2 desc",
184 "RequirementsAndConstrains2", new org.openecomp.sdc.vendorlicense.dao.types.ChoiceOrOther<>(
185 org.openecomp.sdc.vendorlicense.dao.types.LicenseTerm.Unlimited, null), "fg2");
186 licenseAgreementDao.create(licenseAgreement);
187 String featureGroupId = "FeatureGroupId";
188 org.openecomp.sdc.vendorlicense.dao.types.FeatureGroupEntity created =
189 createFeatureGroup(vlm1Id, VERSION01, "fg11", "FG1", "FG1 desc", null, null);
190 featureGroupDao.create(created);
191 featureGroupDao.addReferencingLicenseAgreement(created, licenseAgreement.getId());
193 vendorLicenseManager.deleteFeatureGroup(created, USER1);
194 org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity afterDeletingFG = licenseAgreementDao.get(licenseAgreement);
195 Assert.assertEquals(afterDeletingFG.getFeatureGroupIds().size(), 1);
196 Assert.assertTrue(afterDeletingFG.getFeatureGroupIds().contains("fg2"));
199 @Test(dependsOnMethods = {"listLicenseAgreementsTest"})
200 public void deleteLicenseAgreementsTest() {
201 vendorLicenseManager.deleteLicenseAgreement(vlm1Id, la1Id, USER1);
203 org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity loadedLa1 =
204 licenseAgreementDao.get(new org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity(vlm1Id, VERSION01, la1Id));
205 Assert.assertEquals(loadedLa1, null);
207 Collection<org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity> loadedLas =
208 licenseAgreementDao.list(new org.openecomp.sdc.vendorlicense.dao.types.LicenseAgreementEntity(vlm1Id, VERSION01, null));
209 Assert.assertEquals(loadedLas.size(), 1);
210 Assert.assertEquals(loadedLas.iterator().next().getId(), la2Id);
213 @Test(dependsOnMethods = "deleteLicenseAgreementsTest")
214 public void testCreateWithRemovedName() {
215 testCreate(vlm1Id, LA1_NAME);