e072453421d2473b620cf0206702aea97264264a
[sdc.git] /
1 package org.openecomp.sdc.vendorlicense.impl;
2
3 import org.junit.After;
4 import org.junit.Before;
5 import org.junit.Test;
6 import org.mockito.*;
7 import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
8 import org.openecomp.sdc.vendorlicense.VendorLicenseConstants;
9 import org.openecomp.sdc.vendorlicense.dao.*;
10 import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
11 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
12 import org.openecomp.sdc.versioning.VersioningManager;
13 import org.openecomp.sdc.versioning.dao.types.Version;
14
15 import static org.mockito.Matchers.any;
16 import static org.mockito.Mockito.*;
17
18
19 /**
20  * Created by ayalaben on 7/19/2017
21  */
22 public class VendorLicenseModelTest {
23
24   private static final String USER1 = "TestUser1";
25   private static final String USER2 = "TestUser2";
26
27   private static String vlm1_id = "vlm1_id";
28   private static String vlm2_id = "vlm2_id";
29   private static String la1_id = "la1_id";
30   private static String la2_id = "la2_id";
31   private static String fg1_id = "fg1_id";
32   private static String fg2_id = "fg2_id";
33   public static final Version VERSION01 = new Version(0, 1);
34   private static final Version VERSION10 = new Version(1, 0);
35
36   @Mock
37   private VersioningManager versioningManagerMcok;
38   @Mock
39   private VendorLicenseFacade vendorLicenseFacadeMcok;
40   @Mock
41   private VendorLicenseModelDao vendorLicenseModelDaoMcok;
42   @Mock
43   private LicenseAgreementDao licenseAgreementDaoMcok;
44   @Mock
45   private FeatureGroupDao featureGroupDaoMcok;
46   @Mock
47   private EntitlementPoolDao entitlementPoolDaoMcok;
48   @Mock
49   private LicenseKeyGroupDao licenseKeyGroupDaoMcok;
50   @Mock
51   private LimitDao limitDaoMcok;
52
53   @Spy
54   @InjectMocks
55   private VendorLicenseManagerImpl vendorLicenseManager;
56
57
58   @Captor
59   private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
60
61
62   @Before
63   public void setUp() throws Exception {
64     MockitoAnnotations.initMocks(this);
65   }
66
67   @After
68   public void tearDown(){
69     vendorLicenseManager = null;
70   }
71
72   @Test
73   public void testValidate() {
74     // TODO: 8/13/2017
75     vendorLicenseManager.validate(vlm1_id, null);
76     verify(vendorLicenseFacadeMcok).validate(vlm1_id, null);
77   }
78
79   @Test
80   public void testCreate() {
81     VendorLicenseModelEntity vlmEntity = new VendorLicenseModelEntity(vlm1_id, VERSION01);
82
83     vendorLicenseManager.createVendorLicenseModel(vlmEntity);
84
85     verify(vendorLicenseModelDaoMcok).create(vlmEntity);
86   }
87
88   @Test
89   public void testUpdate() {
90
91     VendorLicenseModelEntity existingVlm = new VendorLicenseModelEntity();
92     existingVlm.setVersion(VERSION01);
93     existingVlm.setId(vlm1_id);
94     existingVlm.setIconRef("icon");
95     existingVlm.setVendorName("VLM1");
96     existingVlm.setDescription("decription");
97
98     doReturn("VLM1").when(vendorLicenseModelDaoMcok).get(existingVlm);
99
100     VendorLicenseModelEntity updatedVlm = new VendorLicenseModelEntity();
101     updatedVlm.setVersion(VERSION01);
102     updatedVlm.setId(vlm1_id);
103     updatedVlm.setIconRef("icon");
104     updatedVlm.setVendorName("VLM1_updated");
105     updatedVlm.setDescription("decription");
106
107     doNothing().when(vendorLicenseManager)
108         .updateUniqueName(VendorLicenseConstants.UniqueValues.VENDOR_NAME,
109             existingVlm.getVendorName(), updatedVlm.getVendorName());
110
111     doReturn(existingVlm).when(vendorLicenseModelDaoMcok).get(any(VendorLicenseModelEntity.class));
112
113     vendorLicenseManager.updateVendorLicenseModel(updatedVlm);
114
115     verify(vendorLicenseModelDaoMcok).update(updatedVlm);
116   }
117
118   @Test
119   public void testGetVendorLicenseModel() {
120     vendorLicenseManager.getVendorLicenseModel(vlm1_id, VERSION01);
121     verify(vendorLicenseFacadeMcok).getVendorLicenseModel(vlm1_id, VERSION01);
122   }
123
124   @Test(expected = UnsupportedOperationException.class)
125   public void testDeleteVLMUnsupportedOperation() {
126     vendorLicenseManager.deleteVendorLicenseModel(vlm1_id, null); // TODO: 8/13/2017
127   }
128
129
130 //  @Test(expectedExceptions = CoreException.class)
131 //  public void testGetNonExistingVersion_negative() {
132 //    Version notExistversion = new Version(43, 8);
133 //    doReturn(null).when(vspInfoDaoMock).get(any(VspDetails.class));
134 //    vendorSoftwareProductManager.getVsp(VSP_ID, notExistversion);
135 //  }
136
137 }