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 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.dao.api.ActionStatus;
33 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
34 import org.openecomp.sdc.be.impl.ComponentsUtils;
35 import org.openecomp.sdc.be.model.category.CategoryDefinition;
36 import org.openecomp.sdc.be.model.category.SubCategoryDefinition;
37 import org.openecomp.sdc.be.model.operations.api.IElementOperation;
38 import org.openecomp.sdc.exception.ResponseFormat;
40 import java.io.IOException;
41 import java.nio.file.Files;
42 import java.nio.file.Path;
43 import java.nio.file.Paths;
44 import java.util.List;
47 import static org.junit.Assert.assertTrue;
48 import static org.mockito.Mockito.when;
50 public class CategoriesImportManagerTest {
52 static CategoriesImportManager importManager = new CategoriesImportManager();
53 public static final IElementOperation elementOperation = Mockito.mock(IElementOperation.class);
54 public static final ComponentsUtils componentsUtils = Mockito.mock(ComponentsUtils.class);
55 private static SubCategoryDefinition subcategory;
58 public static void beforeClass() throws IOException {
59 subcategory = new SubCategoryDefinition();
60 subcategory.setUniqueId("123");
62 when(elementOperation.createCategory(Mockito.any(CategoryDefinition.class), Mockito.any(NodeTypeEnum.class))).thenAnswer((Answer<Either<CategoryDefinition, ActionStatus>>) invocation -> {
63 Object[] args = invocation.getArguments();
64 CategoryDefinition category = (CategoryDefinition) args[0];
65 category.setUniqueId("123");
66 Either<CategoryDefinition, ActionStatus> ans = Either.left(category);
69 when(elementOperation.createSubCategory(Mockito.any(String.class), Mockito.any(SubCategoryDefinition.class), Mockito.any(NodeTypeEnum.class))).thenAnswer(new Answer<Either<SubCategoryDefinition, ActionStatus>>() {
70 public Either<SubCategoryDefinition, ActionStatus> answer(InvocationOnMock invocation) {
71 Object[] args = invocation.getArguments();
72 // subcategory.setName(((SubCategoryDefinition)args[0]).getName());
73 Either<SubCategoryDefinition, ActionStatus> ans = Either.left(subcategory);
79 // when(Mockito.any(SubCategoryDefinition.class).getUniqueId()).thenReturn("123");
83 public void initMocks() {
84 MockitoAnnotations.initMocks(this);
88 public void importCategoriesTest() throws IOException {
89 String ymlContent = getYmlContent();
90 Either<Map<String, List<CategoryDefinition>>, ResponseFormat> createCapabilityTypes = importManager.createCategories(ymlContent);
91 assertTrue(createCapabilityTypes.isLeft());
95 private String getYmlContent() throws IOException {
96 Path filePath = Paths.get("src/test/resources/types/categoryTypes.yml");
97 byte[] fileContent = Files.readAllBytes(filePath);
98 String ymlContent = new String(fileContent);