1 package org.openecomp.sdc.vendorlicense.impl;
3 import static org.mockito.Matchers.any;
4 import static org.mockito.Mockito.doNothing;
5 import static org.mockito.Mockito.doReturn;
6 import static org.mockito.Mockito.verify;
8 import org.mockito.ArgumentCaptor;
9 import org.mockito.Captor;
10 import org.mockito.InjectMocks;
11 import org.mockito.Mock;
12 import org.mockito.MockitoAnnotations;
13 import org.mockito.Spy;
14 import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
15 import org.openecomp.sdc.vendorlicense.VendorLicenseConstants;
16 import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao;
17 import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao;
18 import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDao;
19 import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao;
20 import org.openecomp.sdc.vendorlicense.dao.LimitDao;
21 import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDao;
22 import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
23 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
24 import org.openecomp.sdc.versioning.VersioningManager;
25 import org.openecomp.sdc.versioning.dao.types.Version;
26 import org.testng.annotations.AfterMethod;
27 import org.testng.annotations.BeforeMethod;
28 import org.testng.annotations.Test;
32 * Created by ayalaben on 7/19/2017
34 public class VendorLicenseModelTest {
36 private static final String USER1 = "TestUser1";
37 private static final String USER2 = "TestUser2";
39 private static String vlm1_id = "vlm1_id";
40 private static String vlm2_id = "vlm2_id";
41 private static String la1_id = "la1_id";
42 private static String la2_id = "la2_id";
43 private static String fg1_id = "fg1_id";
44 private static String fg2_id = "fg2_id";
45 public static final Version VERSION01 = new Version(0, 1);
46 private static final Version VERSION10 = new Version(1, 0);
49 private VersioningManager versioningManagerMcok;
51 private VendorLicenseFacade vendorLicenseFacadeMcok;
53 private VendorLicenseModelDao vendorLicenseModelDaoMcok;
55 private LicenseAgreementDao licenseAgreementDaoMcok;
57 private FeatureGroupDao featureGroupDaoMcok;
59 private EntitlementPoolDao entitlementPoolDaoMcok;
61 private LicenseKeyGroupDao licenseKeyGroupDaoMcok;
63 private LimitDao limitDaoMcok;
67 private VendorLicenseManagerImpl vendorLicenseManager;
71 private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
75 public void setUp() throws Exception {
76 MockitoAnnotations.initMocks(this);
80 public void tearDown(){
81 vendorLicenseManager = null;
85 public void testValidate() {
87 vendorLicenseManager.validate(vlm1_id, null);
88 verify(vendorLicenseFacadeMcok).validate(vlm1_id, null);
92 public void testCreate() {
93 VendorLicenseModelEntity vlmEntity = new VendorLicenseModelEntity(vlm1_id, VERSION01);
95 vendorLicenseManager.createVendorLicenseModel(vlmEntity);
97 verify(vendorLicenseModelDaoMcok).create(vlmEntity);
101 public void testUpdate() {
103 VendorLicenseModelEntity existingVlm = new VendorLicenseModelEntity();
104 existingVlm.setVersion(VERSION01);
105 existingVlm.setId(vlm1_id);
106 existingVlm.setIconRef("icon");
107 existingVlm.setVendorName("VLM1");
108 existingVlm.setDescription("decription");
110 doReturn("VLM1").when(vendorLicenseModelDaoMcok).get(existingVlm);
112 VendorLicenseModelEntity updatedVlm = new VendorLicenseModelEntity();
113 updatedVlm.setVersion(VERSION01);
114 updatedVlm.setId(vlm1_id);
115 updatedVlm.setIconRef("icon");
116 updatedVlm.setVendorName("VLM1_updated");
117 updatedVlm.setDescription("decription");
119 doNothing().when(vendorLicenseManager)
120 .updateUniqueName(VendorLicenseConstants.UniqueValues.VENDOR_NAME,
121 existingVlm.getVendorName(), updatedVlm.getVendorName());
123 existingVlm.setWritetimeMicroSeconds(8L);
125 doReturn(existingVlm).when(vendorLicenseModelDaoMcok).get(any(VendorLicenseModelEntity.class));
127 vendorLicenseManager.updateVendorLicenseModel(updatedVlm);
129 verify(vendorLicenseModelDaoMcok).update(updatedVlm);
133 public void testGetVendorLicenseModel() {
134 vendorLicenseManager.getVendorLicenseModel(vlm1_id, VERSION01);
135 verify(vendorLicenseFacadeMcok).getVendorLicenseModel(vlm1_id, VERSION01);
138 @Test(expectedExceptions = UnsupportedOperationException.class)
139 public void testDeleteVLMUnsupportedOperation() {
140 vendorLicenseManager.deleteVendorLicenseModel(vlm1_id, null); // TODO: 8/13/2017
144 // @Test(expectedExceptions = CoreException.class)
145 // public void testGetNonExistingVersion_negative() {
146 // Version notExistversion = new Version(43, 8);
147 // doReturn(null).when(vspInfoDaoMock).get(any(VspDetails.class));
148 // vendorSoftwareProductManager.getVsp(VSP_ID, notExistversion);