8ef9c5aec6e2ef719dad774eca437262164dcbc0
[sdc.git] /
1 package org.openecomp.sdc.vendorlicense.impl;
2
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;
7
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;
29
30
31 /**
32  * Created by ayalaben on 7/19/2017
33  */
34 public class VendorLicenseModelTest {
35
36   private static final String USER1 = "TestUser1";
37   private static final String USER2 = "TestUser2";
38
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);
47
48   @Mock
49   private VersioningManager versioningManagerMcok;
50   @Mock
51   private VendorLicenseFacade vendorLicenseFacadeMcok;
52   @Mock
53   private VendorLicenseModelDao vendorLicenseModelDaoMcok;
54   @Mock
55   private LicenseAgreementDao licenseAgreementDaoMcok;
56   @Mock
57   private FeatureGroupDao featureGroupDaoMcok;
58   @Mock
59   private EntitlementPoolDao entitlementPoolDaoMcok;
60   @Mock
61   private LicenseKeyGroupDao licenseKeyGroupDaoMcok;
62   @Mock
63   private LimitDao limitDaoMcok;
64
65   @Spy
66   @InjectMocks
67   private VendorLicenseManagerImpl vendorLicenseManager;
68
69
70   @Captor
71   private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
72
73
74   @BeforeMethod
75   public void setUp() throws Exception {
76     MockitoAnnotations.initMocks(this);
77   }
78
79   @AfterMethod
80   public void tearDown(){
81     vendorLicenseManager = null;
82   }
83
84   @Test
85   public void testValidate() {
86     // TODO: 8/13/2017
87     vendorLicenseManager.validate(vlm1_id, null);
88     verify(vendorLicenseFacadeMcok).validate(vlm1_id, null);
89   }
90
91   @Test
92   public void testCreate() {
93     VendorLicenseModelEntity vlmEntity = new VendorLicenseModelEntity(vlm1_id, VERSION01);
94
95     vendorLicenseManager.createVendorLicenseModel(vlmEntity);
96
97     verify(vendorLicenseModelDaoMcok).create(vlmEntity);
98   }
99
100   @Test
101   public void testUpdate() {
102
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");
109
110     doReturn("VLM1").when(vendorLicenseModelDaoMcok).get(existingVlm);
111
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");
118
119     doNothing().when(vendorLicenseManager)
120         .updateUniqueName(VendorLicenseConstants.UniqueValues.VENDOR_NAME,
121             existingVlm.getVendorName(), updatedVlm.getVendorName());
122
123     existingVlm.setWritetimeMicroSeconds(8L);
124
125     doReturn(existingVlm).when(vendorLicenseModelDaoMcok).get(any(VendorLicenseModelEntity.class));
126
127     vendorLicenseManager.updateVendorLicenseModel(updatedVlm);
128
129     verify(vendorLicenseModelDaoMcok).update(updatedVlm);
130   }
131
132   @Test
133   public void testGetVendorLicenseModel() {
134     vendorLicenseManager.getVendorLicenseModel(vlm1_id, VERSION01);
135     verify(vendorLicenseFacadeMcok).getVendorLicenseModel(vlm1_id, VERSION01);
136   }
137
138   @Test(expectedExceptions = UnsupportedOperationException.class)
139   public void testDeleteVLMUnsupportedOperation() {
140     vendorLicenseManager.deleteVendorLicenseModel(vlm1_id, null); // TODO: 8/13/2017
141   }
142
143
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);
149 //  }
150
151 }