2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 * SPDX-License-Identifier: Apache-2.0
17 * ============LICENSE_END=========================================================
19 package org.openecomp.sdc.be.components.impl;
21 import static org.hamcrest.MatcherAssert.assertThat;
22 import static org.hamcrest.Matchers.hasSize;
23 import static org.hamcrest.core.Is.is;
24 import static org.mockito.ArgumentMatchers.any;
25 import static org.mockito.Mockito.when;
27 import java.io.IOException;
28 import java.nio.file.Files;
29 import java.nio.file.Paths;
30 import java.util.Optional;
31 import org.junit.jupiter.api.BeforeEach;
32 import org.junit.jupiter.api.Test;
33 import org.mockito.InjectMocks;
34 import org.mockito.Mock;
35 import org.mockito.Mockito;
36 import org.mockito.MockitoAnnotations;
37 import org.openecomp.sdc.be.model.Model;
38 import org.openecomp.sdc.be.model.operations.impl.ArtifactTypeOperation;
39 import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
41 public class ArtifactTypeImportManagerTest {
44 private ArtifactTypeImportManager artifactTypeImportManager;
46 private CommonImportManager commonImportManager;
48 private ModelOperation modelOperation;
50 private ArtifactTypeOperation artifactTypeOperation;
54 MockitoAnnotations.openMocks(this);
58 void createArtifactTypeFromYmlTest() throws IOException {
59 when(commonImportManager.createElementTypesFromYml(Mockito.anyString(), any())).thenCallRealMethod();
60 when(commonImportManager.createElementTypesFromToscaJsonMap(any(), any())).thenCallRealMethod();
61 when(artifactTypeOperation.createArtifactType(any())).thenCallRealMethod();
62 when(modelOperation.findModelByName("test")).thenReturn(Optional.of(new Model("test")));
63 final var result = artifactTypeImportManager
64 .createArtifactTypes(getArtifactsYml(), "test", false);
65 assertThat("The createElementTypesFromYml should be left", result.isLeft(), is(true));
66 final var artifactTypes = result.left().value();
67 assertThat("The artifact types list should have size", artifactTypes, hasSize(1));
70 private String getArtifactsYml() throws IOException {
71 return new String(Files.readAllBytes(Paths.get("src/test/resources/types/artifactTypes.yml")));