2 * ============LICENSE_START=======================================================
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
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.be.components.impl;
23 import static org.junit.Assert.assertTrue;
24 import static org.mockito.Mockito.when;
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;
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 import org.slf4j.Logger;
47 import fj.data.Either;
49 public class InterfaceLifecycleTypeImportManagerTest {
52 private InterfaceLifecycleTypeImportManager importManager = new InterfaceLifecycleTypeImportManager();
53 public static final CommonImportManager commonImportManager = Mockito.mock(CommonImportManager.class);
54 public static final IInterfaceLifecycleOperation interfaceLifecycleOperation = Mockito.mock(IInterfaceLifecycleOperation.class);
55 public static final ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class);
57 static Logger log = Mockito.spy(Logger.class);
60 public static void beforeClass() throws IOException {
61 InterfaceLifecycleTypeImportManager.setLog(log);
62 when(interfaceLifecycleOperation.createInterfaceType(Mockito.any(InterfaceDefinition.class))).thenAnswer(new Answer<Either<InterfaceDefinition, StorageOperationStatus>>() {
63 public Either<InterfaceDefinition, StorageOperationStatus> answer(InvocationOnMock invocation) {
64 Object[] args = invocation.getArguments();
65 Either<InterfaceDefinition, StorageOperationStatus> ans = Either.left((InterfaceDefinition) args[0]);
70 when(commonImportManager.createElementTypesFromYml(Mockito.anyString(), Mockito.any())).thenCallRealMethod();
74 public void initMocks() {
75 MockitoAnnotations.initMocks(this);
79 public void importLiecycleTest() throws IOException {
80 String ymlContent = getYmlContent();
81 Either<List<InterfaceDefinition>, ResponseFormat> createCapabilityTypes = importManager.createLifecycleTypes(ymlContent);
82 assertTrue(createCapabilityTypes.isLeft());
86 private String getYmlContent() throws IOException {
87 Path filePath = Paths.get("src/test/resources/types/interfaceLifecycleTypes.yml");
88 byte[] fileContent = Files.readAllBytes(filePath);
89 String ymlContent = new String(fileContent);