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;
23 import fj.data.Either;
24 import org.junit.BeforeClass;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.mockito.InjectMocks;
28 import org.mockito.Mock;
29 import org.mockito.runners.MockitoJUnitRunner;
30 import org.openecomp.sdc.be.DummyConfigurationManager;
31 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
32 import org.openecomp.sdc.be.components.impl.ComponentBusinessLogic;
33 import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
34 import org.openecomp.sdc.be.components.utils.ResourceBuilder;
35 import org.openecomp.sdc.be.config.ConfigurationManager;
36 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
37 import org.openecomp.sdc.be.model.ArtifactDefinition;
38 import org.openecomp.sdc.be.model.ComponentInstance;
39 import org.openecomp.sdc.be.model.Resource;
40 import org.openecomp.sdc.be.model.User;
41 import org.openecomp.sdc.be.ui.model.UiComponentDataTransfer;
42 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
43 import org.openecomp.sdc.exception.ResponseFormat;
45 import java.util.HashMap;
46 import java.util.List;
49 import static org.assertj.core.api.Assertions.assertThat;
50 import static org.mockito.Mockito.when;
52 @RunWith(MockitoJUnitRunner.class)
53 public class ComponentBusinessLogicTest {
55 private static final User USER = new User();
56 private static final String ARTIFACT_LABEL = "toscaArtifact1";
57 private static final String ARTIFACT_LABEL2 = "toscaArtifact2";
60 private ComponentBusinessLogic testInstance = new ComponentBusinessLogic() {
62 public Either<List<String>, ResponseFormat> deleteMarkedComponents() {
67 public ComponentInstanceBusinessLogic getComponentInstanceBL() {
72 public Either<List<ComponentInstance>, ResponseFormat> getComponentInstancesFilteredByPropertiesAndInputs(String componentId, ComponentTypeEnum componentTypeEnum, String userId, String searchText) {
77 public Either<UiComponentDataTransfer, ResponseFormat> getUiComponentDataTransferByComponentId(String componentId, List<String> dataParamsToReturn) {
83 private ArtifactsBusinessLogic artifactsBusinessLogic;
86 public static void setUp() throws Exception {
87 new DummyConfigurationManager();
90 @SuppressWarnings("unchecked")
92 public void setToscaArtifactsPlaceHolders_normalizeArtifactName() throws Exception {
93 Resource resource = new ResourceBuilder().setUniqueId("uid")
94 .setComponentType(ComponentTypeEnum.RESOURCE)
95 .setSystemName("myResource")
97 Map<String, Object> artifactsFromConfig = new HashMap<>();
98 artifactsFromConfig.put(ARTIFACT_LABEL, buildArtifactMap("artifact:not normalized.yml"));
99 artifactsFromConfig.put(ARTIFACT_LABEL2, buildArtifactMap("alreadyNormalized.csar"));
100 when(ConfigurationManager.getConfigurationManager().getConfiguration().getToscaArtifacts()).thenReturn(artifactsFromConfig);
101 when(artifactsBusinessLogic.createArtifactPlaceHolderInfo(resource.getUniqueId(), ARTIFACT_LABEL, (Map<String, Object>) artifactsFromConfig.get(ARTIFACT_LABEL), USER, ArtifactGroupTypeEnum.TOSCA))
102 .thenReturn(buildArtifactDef(ARTIFACT_LABEL));
103 when(artifactsBusinessLogic.createArtifactPlaceHolderInfo(resource.getUniqueId(), ARTIFACT_LABEL2, (Map<String, Object>) artifactsFromConfig.get(ARTIFACT_LABEL2), USER, ArtifactGroupTypeEnum.TOSCA))
104 .thenReturn(buildArtifactDef(ARTIFACT_LABEL2));
105 testInstance.setToscaArtifactsPlaceHolders(resource, USER);
107 Map<String, ArtifactDefinition> toscaArtifacts = resource.getToscaArtifacts();
108 assertThat(toscaArtifacts).hasSize(2);
109 ArtifactDefinition artifactDefinition = toscaArtifacts.get(ARTIFACT_LABEL);
110 assertThat(artifactDefinition.getArtifactName()).isEqualTo("resource-myResourceartifactnot-normalized.yml");
111 ArtifactDefinition artifactDefinition2 = toscaArtifacts.get(ARTIFACT_LABEL2);
112 assertThat(artifactDefinition2.getArtifactName()).isEqualTo("resource-myResourcealreadyNormalized.csar");
115 private Map<String, Object> buildArtifactMap(String artifactName) {
116 Map<String, Object> artifact = new HashMap<>();
117 artifact.put("artifactName", artifactName);
121 private ArtifactDefinition buildArtifactDef(String artifactLabel) {
122 ArtifactDefinition artifactDefinition = new ArtifactDefinition();
123 artifactDefinition.setArtifactLabel(artifactLabel);
124 return artifactDefinition;