2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.vendorlicense.impl;
23 import org.junit.After;
24 import org.junit.Before;
25 import org.junit.Test;
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;
35 import static org.mockito.Matchers.any;
36 import static org.mockito.Mockito.*;
40 * Created by ayalaben on 7/19/2017
42 public class VendorLicenseModelTest {
44 private static final String USER1 = "TestUser1";
45 private static final String USER2 = "TestUser2";
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);
57 private VersioningManager versioningManagerMcok;
59 private VendorLicenseFacade vendorLicenseFacadeMcok;
61 private VendorLicenseModelDao vendorLicenseModelDaoMcok;
63 private LicenseAgreementDao licenseAgreementDaoMcok;
65 private FeatureGroupDao featureGroupDaoMcok;
67 private EntitlementPoolDao entitlementPoolDaoMcok;
69 private LicenseKeyGroupDao licenseKeyGroupDaoMcok;
71 private LimitDao limitDaoMcok;
75 private VendorLicenseManagerImpl vendorLicenseManager;
79 private ArgumentCaptor<ActivityLogEntity> activityLogEntityArg;
83 public void setUp() throws Exception {
84 MockitoAnnotations.openMocks(this);
88 public void tearDown(){
89 vendorLicenseManager = null;
93 public void testValidate() {
95 vendorLicenseManager.validate(vlm1_id, null);
96 verify(vendorLicenseFacadeMcok).validate(vlm1_id, null);
100 public void testCreate() {
101 VendorLicenseModelEntity vlmEntity = new VendorLicenseModelEntity(vlm1_id, VERSION01);
103 vendorLicenseManager.createVendorLicenseModel(vlmEntity);
105 verify(vendorLicenseModelDaoMcok).create(vlmEntity);
109 public void testUpdate() {
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");
118 doReturn("VLM1").when(vendorLicenseModelDaoMcok).get(existingVlm);
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");
127 doNothing().when(vendorLicenseManager)
128 .updateUniqueName(VendorLicenseConstants.UniqueValues.VENDOR_NAME,
129 existingVlm.getVendorName(), updatedVlm.getVendorName());
131 doReturn(existingVlm).when(vendorLicenseModelDaoMcok).get(any(VendorLicenseModelEntity.class));
133 vendorLicenseManager.updateVendorLicenseModel(updatedVlm);
135 verify(vendorLicenseModelDaoMcok).update(updatedVlm);
139 public void testGetVendorLicenseModel() {
140 vendorLicenseManager.getVendorLicenseModel(vlm1_id, VERSION01);
141 verify(vendorLicenseFacadeMcok).getVendorLicenseModel(vlm1_id, VERSION01);
144 @Test(expected = UnsupportedOperationException.class)
145 public void testDeleteVLMUnsupportedOperation() {
146 vendorLicenseManager.deleteVendorLicenseModel(vlm1_id, null); // TODO: 8/13/2017
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);