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.components.impl.CommonImportManager;
41 import org.openecomp.sdc.be.components.impl.InterfaceLifecycleTypeImportManager;
42 import org.openecomp.sdc.be.impl.ComponentsUtils;
43 import org.openecomp.sdc.be.model.InterfaceDefinition;
44 import org.openecomp.sdc.be.model.operations.api.IInterfaceLifecycleOperation;
45 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
46 import org.openecomp.sdc.exception.ResponseFormat;
47 import org.slf4j.Logger;
49 import fj.data.Either;
51 public class InterfaceLifecycleTypeImportManagerTest {
54 private InterfaceLifecycleTypeImportManager importManager = new InterfaceLifecycleTypeImportManager();
55 public static final CommonImportManager commonImportManager = Mockito.mock(CommonImportManager.class);
56 public static final IInterfaceLifecycleOperation interfaceLifecycleOperation = Mockito.mock(IInterfaceLifecycleOperation.class);
57 public static final ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class);
59 static Logger log = Mockito.spy(Logger.class);
62 public static void beforeClass() throws IOException {
63 InterfaceLifecycleTypeImportManager.setLog(log);
64 when(interfaceLifecycleOperation.createInterfaceType(Mockito.any(InterfaceDefinition.class))).thenAnswer(new Answer<Either<InterfaceDefinition, StorageOperationStatus>>() {
65 public Either<InterfaceDefinition, StorageOperationStatus> answer(InvocationOnMock invocation) {
66 Object[] args = invocation.getArguments();
67 Either<InterfaceDefinition, StorageOperationStatus> ans = Either.left((InterfaceDefinition) args[0]);
72 when(commonImportManager.createElementTypesFromYml(Mockito.anyString(), Mockito.any())).thenCallRealMethod();
76 public void initMocks() {
77 MockitoAnnotations.initMocks(this);
81 public void importLiecycleTest() throws IOException {
82 String ymlContent = getYmlContent();
83 Either<List<InterfaceDefinition>, ResponseFormat> createCapabilityTypes = importManager.createLifecycleTypes(ymlContent);
84 assertTrue(createCapabilityTypes.isLeft());
88 private String getYmlContent() throws IOException {
89 Path filePath = Paths.get("src/test/resources/types/interfaceLifecycleTypes.yml");
90 byte[] fileContent = Files.readAllBytes(filePath);
91 String ymlContent = new String(fileContent);