1 package org.openecomp.sdc.vendorlicense.impl;
3 import org.mockito.ArgumentCaptor;
4 import org.mockito.Captor;
5 import org.mockito.InjectMocks;
6 import org.mockito.Mock;
7 import org.mockito.MockitoAnnotations;
8 import org.mockito.Spy;
9 import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
10 import org.openecomp.sdc.vendorlicense.VendorLicenseConstants;
11 import org.openecomp.sdc.vendorlicense.dao.EntitlementPoolDao;
12 import org.openecomp.sdc.vendorlicense.dao.FeatureGroupDao;
13 import org.openecomp.sdc.vendorlicense.dao.LicenseAgreementDao;
14 import org.openecomp.sdc.vendorlicense.dao.LicenseKeyGroupDao;
15 import org.openecomp.sdc.vendorlicense.dao.LimitDao;
16 import org.openecomp.sdc.vendorlicense.dao.VendorLicenseModelDao;
17 import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
18 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
19 import org.openecomp.sdc.versioning.VersioningManager;
20 import org.openecomp.sdc.versioning.dao.types.Version;
21 import org.testng.annotations.BeforeMethod;
22 import org.testng.annotations.Test;
24 import static org.mockito.Matchers.any;
25 import static org.mockito.Mockito.doNothing;
26 import static org.mockito.Mockito.doReturn;
27 import static org.mockito.Mockito.verify;
31 * Created by ayalaben on 7/19/2017
33 public class VendorLicenseModelTest {
35 private static final String USER1 = "TestUser1";
36 private static final String USER2 = "TestUser2";
38 private static String vlm1_id = "vlm1_id";
39 private static String vlm2_id = "vlm2_id";
40 private static String la1_id = "la1_id";
41 private static String la2_id = "la2_id";
42 private static String fg1_id = "fg1_id";
43 private static String fg2_id = "fg2_id";
44 public static final Version VERSION01 = new Version(0, 1);
45 private static final Version VERSION10 = new Version(1, 0);
48 private VersioningManager versioningManagerMcok;
50 private VendorLicenseFacade vendorLicenseFacadeMcok;
52 private VendorLicenseModelDao vendorLicenseModelDaoMcok;
54 private LicenseAgreementDao licenseAgreementDaoMcok;
56 private FeatureGroupDao featureGroupDaoMcok;
58 private EntitlementPoolDao entitlementPoolDaoMcok;
60 private LicenseKeyGroupDao licenseKeyGroupDaoMcok;
62 private LimitDao limitDaoMcok;
66 private VendorLicenseManagerImpl vendorLicenseManager;
70 private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
74 public void setUp() throws Exception {
75 MockitoAnnotations.initMocks(this);
79 public void testValidate() {
81 vendorLicenseManager.validate(vlm1_id, null);
82 verify(vendorLicenseFacadeMcok).validate(vlm1_id, null);
86 public void testCreate() {
87 VendorLicenseModelEntity vlmEntity = new VendorLicenseModelEntity(vlm1_id, VERSION01);
89 vendorLicenseManager.createVendorLicenseModel(vlmEntity);
91 verify(vendorLicenseModelDaoMcok).create(vlmEntity);
95 public void testUpdate() {
97 VendorLicenseModelEntity existingVlm = new VendorLicenseModelEntity();
98 existingVlm.setVersion(VERSION01);
99 existingVlm.setId(vlm1_id);
100 existingVlm.setIconRef("icon");
101 existingVlm.setVendorName("VLM1");
102 existingVlm.setDescription("decription");
104 doReturn("VLM1").when(vendorLicenseModelDaoMcok).get(existingVlm);
106 VendorLicenseModelEntity updatedVlm = new VendorLicenseModelEntity();
107 updatedVlm.setVersion(VERSION01);
108 updatedVlm.setId(vlm1_id);
109 updatedVlm.setIconRef("icon");
110 updatedVlm.setVendorName("VLM1_updated");
111 updatedVlm.setDescription("decription");
113 doNothing().when(vendorLicenseManager)
114 .updateUniqueName(VendorLicenseConstants.UniqueValues.VENDOR_NAME,
115 existingVlm.getVendorName(), updatedVlm.getVendorName());
117 existingVlm.setWritetimeMicroSeconds(8L);
119 doReturn(existingVlm).when(vendorLicenseModelDaoMcok).get(any(VendorLicenseModelEntity.class));
121 vendorLicenseManager.updateVendorLicenseModel(updatedVlm);
123 verify(vendorLicenseModelDaoMcok).update(updatedVlm);
127 public void testGetVendorLicenseModel() {
128 vendorLicenseManager.getVendorLicenseModel(vlm1_id, VERSION01);
129 verify(vendorLicenseFacadeMcok).getVendorLicenseModel(vlm1_id, VERSION01);
132 @Test(expectedExceptions = UnsupportedOperationException.class)
133 public void testDeleteVLMUnsupportedOperation() {
134 vendorLicenseManager.deleteVendorLicenseModel(vlm1_id, null); // TODO: 8/13/2017
138 // @Test(expectedExceptions = CoreException.class)
139 // public void testGetNonExistingVersion_negative() {
140 // Version notExistversion = new Version(43, 8);
141 // doReturn(null).when(vspInfoDaoMock).get(any(VspDetails.class));
142 // vendorSoftwareProductManager.getVsp(VSP_ID, notExistversion);