Implement 'Update Service by importing Tosca Template'-story
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / impl / ServiceImportManagerTest.java
1 /*
2  * Copyright (C) 2020 CMCC, Inc. and others. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15
16  */
17
18 package org.openecomp.sdc.be.components.impl;
19
20 import org.junit.jupiter.api.BeforeEach;
21 import org.junit.jupiter.api.Test;
22 import org.junit.jupiter.api.extension.ExtendWith;
23 import org.mockito.InjectMocks;
24 import org.mockito.Mock;
25 import org.mockito.MockitoAnnotations;
26 import org.mockito.junit.jupiter.MockitoExtension;
27 import org.openecomp.sdc.be.model.Service;
28 import org.openecomp.sdc.be.model.UploadServiceInfo;
29
30 import static org.junit.jupiter.api.Assertions.assertEquals;
31 import static org.junit.jupiter.api.Assertions.assertFalse;
32 import static org.mockito.ArgumentMatchers.anyString;
33 import static org.mockito.Mockito.when;
34
35 @ExtendWith(MockitoExtension.class)
36 class ServiceImportManagerTest {
37
38     @Mock
39     private ServiceBusinessLogic serviceBusinessLogic;
40
41     @InjectMocks
42     private ServiceImportManager serviceImportManager;
43
44     @BeforeEach
45     public void setup() {
46         MockitoAnnotations.openMocks(this);
47         serviceImportManager = new ServiceImportManager(serviceBusinessLogic, null);
48     }
49
50     @Test
51     void testPopulateServiceMetadata() {
52         UploadServiceInfo serviceMetaData = new UploadServiceInfo();
53         serviceMetaData.setDescription("Description");
54         serviceMetaData.setVendorName("VendorName");
55         serviceMetaData.setVendorRelease("VendorRelease");
56         serviceMetaData.setDerivedFromGenericVersion("derivedFromGenericVersion");
57         Service service = new Service();
58         service.setName("service");
59         serviceImportManager.populateServiceMetadata(serviceMetaData, service);
60         assertEquals("derivedFromGenericVersion", service.getDerivedFromGenericVersion());
61     }
62
63     @Test
64     void testIsServiceExist() {
65         when(serviceBusinessLogic.isServiceExist(anyString())).thenReturn(false);
66         boolean result = serviceImportManager.isServiceExist("no exist");
67         assertFalse(result);
68     }
69 }