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