Sync Integ to Master
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / impl / InterfaceLifecycleTypeImportManagerTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 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.be.components.impl;
22
23 import fj.data.Either;
24 import org.junit.Before;
25 import org.junit.BeforeClass;
26 import org.junit.Test;
27 import org.mockito.InjectMocks;
28 import org.mockito.Mockito;
29 import org.mockito.MockitoAnnotations;
30 import org.mockito.invocation.InvocationOnMock;
31 import org.mockito.stubbing.Answer;
32 import org.openecomp.sdc.be.impl.ComponentsUtils;
33 import org.openecomp.sdc.be.model.InterfaceDefinition;
34 import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
35 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
36 import org.openecomp.sdc.exception.ResponseFormat;
37
38 import java.io.IOException;
39 import java.nio.file.Files;
40 import java.nio.file.Path;
41 import java.nio.file.Paths;
42 import java.util.List;
43
44 import static org.junit.Assert.assertTrue;
45 import static org.mockito.Mockito.when;
46
47 public class InterfaceLifecycleTypeImportManagerTest {
48
49     @InjectMocks
50     private InterfaceLifecycleTypeImportManager importManager = new InterfaceLifecycleTypeImportManager();
51     public static final CommonImportManager commonImportManager = Mockito.mock(CommonImportManager.class);
52     public static final IInterfaceLifecycleOperation interfaceLifecycleOperation = Mockito.mock(IInterfaceLifecycleOperation.class);
53     public static final ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class);
54
55     @BeforeClass
56     public static void beforeClass() throws IOException {
57         when(interfaceLifecycleOperation.createInterfaceType(Mockito.any(InterfaceDefinition.class))).thenAnswer(new Answer<Either<InterfaceDefinition, StorageOperationStatus>>() {
58             public Either<InterfaceDefinition, StorageOperationStatus> answer(InvocationOnMock invocation) {
59                 Object[] args = invocation.getArguments();
60                 Either<InterfaceDefinition, StorageOperationStatus> ans = Either.left((InterfaceDefinition) args[0]);
61                 return ans;
62             }
63
64         });
65         when(commonImportManager.createElementTypesFromYml(Mockito.anyString(), Mockito.any())).thenCallRealMethod();
66     }
67
68     @Before
69     public void initMocks() {
70         MockitoAnnotations.initMocks(this);
71     }
72
73     @Test
74     public void importLiecycleTest() throws IOException {
75         String ymlContent = getYmlContent();
76         Either<List<InterfaceDefinition>, ResponseFormat> createCapabilityTypes = importManager.createLifecycleTypes(ymlContent);
77         assertTrue(createCapabilityTypes.isLeft());
78
79     }
80
81     private String getYmlContent() throws IOException {
82         Path filePath = Paths.get("src/test/resources/types/interfaceLifecycleTypes.yml");
83         byte[] fileContent = Files.readAllBytes(filePath);
84         String ymlContent = new String(fileContent);
85         return ymlContent;
86     }
87 }