Improve testing stability
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-license-manager / src / test / java / org / openecomp / sdc / vendorlicense / impl / VendorLicenseModelTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.vendorlicense.impl;
22
23 import org.junit.After;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.mockito.*;
27 import org.openecomp.sdc.activitylog.dao.type.ActivityLogEntity;
28 import org.openecomp.sdc.vendorlicense.VendorLicenseConstants;
29 import org.openecomp.sdc.vendorlicense.dao.*;
30 import org.openecomp.sdc.vendorlicense.dao.types.VendorLicenseModelEntity;
31 import org.openecomp.sdc.vendorlicense.facade.VendorLicenseFacade;
32 import org.openecomp.sdc.versioning.VersioningManager;
33 import org.openecomp.sdc.versioning.dao.types.Version;
34
35 import static org.mockito.Matchers.any;
36 import static org.mockito.Mockito.*;
37
38
39 /**
40  * Created by ayalaben on 7/19/2017
41  */
42 public class VendorLicenseModelTest {
43
44   private static final String USER1 = "TestUser1";
45   private static final String USER2 = "TestUser2";
46
47   private static String vlm1_id = "vlm1_id";
48   private static String vlm2_id = "vlm2_id";
49   private static String la1_id = "la1_id";
50   private static String la2_id = "la2_id";
51   private static String fg1_id = "fg1_id";
52   private static String fg2_id = "fg2_id";
53   public static final Version VERSION01 = new Version(0, 1);
54   private static final Version VERSION10 = new Version(1, 0);
55
56   @Mock
57   private VersioningManager versioningManagerMcok;
58   @Mock
59   private VendorLicenseFacade vendorLicenseFacadeMcok;
60   @Mock
61   private VendorLicenseModelDao vendorLicenseModelDaoMcok;
62   @Mock
63   private LicenseAgreementDao licenseAgreementDaoMcok;
64   @Mock
65   private FeatureGroupDao featureGroupDaoMcok;
66   @Mock
67   private EntitlementPoolDao entitlementPoolDaoMcok;
68   @Mock
69   private LicenseKeyGroupDao licenseKeyGroupDaoMcok;
70   @Mock
71   private LimitDao limitDaoMcok;
72
73   @Spy
74   @InjectMocks
75   private VendorLicenseManagerImpl vendorLicenseManager;
76
77
78   @Captor
79   private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
80
81
82   @Before
83   public void setUp() throws Exception {
84     MockitoAnnotations.openMocks(this);
85   }
86
87   @After
88   public void tearDown(){
89     vendorLicenseManager = null;
90   }
91
92   @Test
93   public void testValidate() {
94     // TODO: 8/13/2017
95     vendorLicenseManager.validate(vlm1_id, null);
96     verify(vendorLicenseFacadeMcok).validate(vlm1_id, null);
97   }
98
99   @Test
100   public void testCreate() {
101     VendorLicenseModelEntity vlmEntity = new VendorLicenseModelEntity(vlm1_id, VERSION01);
102
103     vendorLicenseManager.createVendorLicenseModel(vlmEntity);
104
105     verify(vendorLicenseModelDaoMcok).create(vlmEntity);
106   }
107
108   @Test
109   public void testUpdate() {
110
111     VendorLicenseModelEntity existingVlm = new VendorLicenseModelEntity();
112     existingVlm.setVersion(VERSION01);
113     existingVlm.setId(vlm1_id);
114     existingVlm.setIconRef("icon");
115     existingVlm.setVendorName("VLM1");
116     existingVlm.setDescription("decription");
117
118     doReturn("VLM1").when(vendorLicenseModelDaoMcok).get(existingVlm);
119
120     VendorLicenseModelEntity updatedVlm = new VendorLicenseModelEntity();
121     updatedVlm.setVersion(VERSION01);
122     updatedVlm.setId(vlm1_id);
123     updatedVlm.setIconRef("icon");
124     updatedVlm.setVendorName("VLM1_updated");
125     updatedVlm.setDescription("decription");
126
127     doNothing().when(vendorLicenseManager)
128         .updateUniqueName(VendorLicenseConstants.UniqueValues.VENDOR_NAME,
129             existingVlm.getVendorName(), updatedVlm.getVendorName());
130
131     doReturn(existingVlm).when(vendorLicenseModelDaoMcok).get(any(VendorLicenseModelEntity.class));
132
133     vendorLicenseManager.updateVendorLicenseModel(updatedVlm);
134
135     verify(vendorLicenseModelDaoMcok).update(updatedVlm);
136   }
137
138   @Test
139   public void testGetVendorLicenseModel() {
140     vendorLicenseManager.getVendorLicenseModel(vlm1_id, VERSION01);
141     verify(vendorLicenseFacadeMcok).getVendorLicenseModel(vlm1_id, VERSION01);
142   }
143
144   @Test(expected = UnsupportedOperationException.class)
145   public void testDeleteVLMUnsupportedOperation() {
146     vendorLicenseManager.deleteVendorLicenseModel(vlm1_id, null); // TODO: 8/13/2017
147   }
148
149
150 //  @Test(expectedExceptions = CoreException.class)
151 //  public void testGetNonExistingVersion_negative() {
152 //    Version notExistversion = new Version(43, 8);
153 //    doReturn(null).when(vspInfoDaoMock).get(any(VspDetails.class));
154 //    vendorSoftwareProductManager.getVsp(VSP_ID, notExistversion);
155 //  }
156
157 }