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