2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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.distribution.engine;
23 import fj.data.Either;
24 import mockit.Deencapsulation;
25 import org.junit.Before;
26 import org.junit.Test;
27 import org.mockito.InjectMocks;
28 import org.mockito.Mock;
29 import org.mockito.Mockito;
30 import org.mockito.MockitoAnnotations;
31 import org.openecomp.sdc.be.components.BeConfDependentTest;
32 import org.openecomp.sdc.be.model.ArtifactDefinition;
33 import org.openecomp.sdc.be.model.ComponentInstance;
34 import org.openecomp.sdc.be.model.ComponentParametersView;
35 import org.openecomp.sdc.be.model.Resource;
36 import org.openecomp.sdc.be.model.Service;
37 import org.openecomp.sdc.be.model.category.CategoryDefinition;
38 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
39 import org.openecomp.sdc.be.model.operations.impl.InterfaceLifecycleOperation;
40 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
42 import java.util.HashMap;
43 import java.util.LinkedList;
44 import java.util.List;
47 public class ServiceDistributionArtifactsBuilderTest extends BeConfDependentTest {
50 ServiceDistributionArtifactsBuilder testSubject;
53 ToscaOperationFacade toscaOperationFacade;
56 public void setUpMocks() throws Exception {
57 MockitoAnnotations.initMocks(this);
62 public void testGetInterfaceLifecycleOperation() throws Exception {
63 InterfaceLifecycleOperation result;
66 result = testSubject.getInterfaceLifecycleOperation();
70 public void testSetInterfaceLifecycleOperation() throws Exception {
71 InterfaceLifecycleOperation interfaceLifecycleOperation = null;
74 testSubject.setInterfaceLifecycleOperation(interfaceLifecycleOperation);
78 public void testResolveWorkloadContext() throws Exception {
79 String workloadContext = "";
83 result = Deencapsulation.invoke(testSubject, "resolveWorkloadContext", new Object[] { workloadContext });
87 public void testBuildResourceInstanceForDistribution() throws Exception {
88 Service service = new Service();
89 String distributionId = "";
90 String workloadContext = "";
91 INotificationData result;
94 workloadContext = "mock";
95 result = testSubject.buildResourceInstanceForDistribution(service, distributionId, workloadContext);
98 workloadContext = null;
99 result = testSubject.buildResourceInstanceForDistribution(service, distributionId, workloadContext);
103 public void testBuildServiceForDistribution() throws Exception {
104 INotificationData notificationData = Mockito.mock(INotificationData.class);
105 Service service = new Service();
106 service.setDeploymentArtifacts(new HashMap<>());
107 service.setToscaArtifacts(new HashMap<>());
108 INotificationData result;
111 result = testSubject.buildServiceForDistribution(notificationData, service);
114 @Test(expected = NullPointerException.class)
115 public void testConvertServiceArtifactsToArtifactInfo() throws Exception {
116 Service service = new Service();
117 service.setDeploymentArtifacts(new HashMap<>());
118 Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
119 ArtifactDefinition artifactDefinition = new ArtifactDefinition();
120 ArtifactDefinition artifactDefinition2 = new ArtifactDefinition();
121 artifactDefinition.setArtifactType(ArtifactTypeEnum.TOSCA_TEMPLATE.getType());
122 artifactDefinition2.setArtifactType(ArtifactTypeEnum.TOSCA_CSAR.getType());
123 toscaArtifacts.put("mock", artifactDefinition);
124 toscaArtifacts.put("mock2", artifactDefinition2);
125 service.setToscaArtifacts(new HashMap<>());
126 List<ArtifactInfoImpl> result;
129 result = Deencapsulation.invoke(testSubject, "convertServiceArtifactsToArtifactInfo", service);
130 service.setToscaArtifacts(toscaArtifacts);
131 result = Deencapsulation.invoke(testSubject, "convertServiceArtifactsToArtifactInfo", service);
135 public void testConvertRIsToJsonContanier() throws Exception {
136 Service service = new Service();
137 List<ComponentInstance> resourceInstances = new LinkedList<>();
138 List<JsonContainerResourceInstance> result;
140 Mockito.when(toscaOperationFacade.getToscaElement(Mockito.nullable(String.class), Mockito.any(ComponentParametersView.class))).thenReturn(Either.left(new Resource()));
142 result = Deencapsulation.invoke(testSubject, "convertRIsToJsonContanier", service);
144 resourceInstances.add(new ComponentInstance());
145 service.setComponentInstances(resourceInstances);
146 result = Deencapsulation.invoke(testSubject, "convertRIsToJsonContanier", service);
150 public void testFillJsonContainer() throws Exception {
151 JsonContainerResourceInstance jsonContainer = new JsonContainerResourceInstance(new ComponentInstance(),
153 Resource resource = new Resource();
156 Deencapsulation.invoke(testSubject, "fillJsonContainer", jsonContainer, resource);
160 public void testConvertToArtifactsInfoImpl() throws Exception {
161 Service service = new Service();
162 ComponentInstance resourceInstance = new ComponentInstance();
163 List<ArtifactInfoImpl> result;
166 result = Deencapsulation.invoke(testSubject, "convertToArtifactsInfoImpl", service, resourceInstance);
170 public void testSetCategories() throws Exception {
171 JsonContainerResourceInstance jsonContainer = null;
172 List<CategoryDefinition> categories = null;
176 LinkedList<CategoryDefinition> linkedList = new LinkedList<>();
177 linkedList.add(new CategoryDefinition());
178 LinkedList<ArtifactInfoImpl> artifacts = new LinkedList<>();
179 Deencapsulation.invoke(testSubject, "setCategories",
180 new JsonContainerResourceInstance(new ComponentInstance(), artifacts), linkedList);
184 public void testGetArtifactsWithPayload() throws Exception {
185 ComponentInstance resourceInstance = new ComponentInstance();
186 Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
187 resourceInstance.setDeploymentArtifacts(deploymentArtifacts);
188 List<ArtifactDefinition> result;
191 result = Deencapsulation.invoke(testSubject, "getArtifactsWithPayload", resourceInstance);
192 deploymentArtifacts.put("mock", new ArtifactDefinition());
193 result = Deencapsulation.invoke(testSubject, "getArtifactsWithPayload", resourceInstance);
197 public void testBuildResourceInstanceArtifactUrl() throws Exception {
198 Service service = new Service();
199 service.setSystemName("mock");
200 service.setVersion("mock");
201 ComponentInstance resourceInstance = new ComponentInstance();
202 resourceInstance.setNormalizedName("mock");
203 String artifactName = "mock";
207 result = ServiceDistributionArtifactsBuilder.buildResourceInstanceArtifactUrl(service, resourceInstance,
212 public void testBuildServiceArtifactUrl() throws Exception {
213 Service service = new Service();
214 String artifactName = "mock";
218 result = ServiceDistributionArtifactsBuilder.buildServiceArtifactUrl(service, artifactName);
222 public void testVerifyServiceContainsDeploymentArtifacts() throws Exception {
223 Service service = new Service();
227 result = testSubject.verifyServiceContainsDeploymentArtifacts(service);
228 Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
229 deploymentArtifacts.put("mock", new ArtifactDefinition());
230 service.setDeploymentArtifacts(deploymentArtifacts);
231 result = testSubject.verifyServiceContainsDeploymentArtifacts(service);
232 List<ComponentInstance> resourceInstances = new LinkedList<>();
233 resourceInstances.add(new ComponentInstance());
234 service.setComponentInstances(resourceInstances);
235 service.setDeploymentArtifacts(null);
236 result = testSubject.verifyServiceContainsDeploymentArtifacts(service);
240 public void testIsContainsPayload() throws Exception {
241 Map<String, ArtifactDefinition> deploymentArtifacts = null;
245 result = Deencapsulation.invoke(testSubject, "isContainsPayload", new Object[] { Map.class });