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.distribution;
23 import org.junit.Test;
24 import org.mockito.InjectMocks;
25 import org.mockito.Mockito;
26 import org.openecomp.sdc.be.components.BeConfDependentTest;
27 import org.openecomp.sdc.be.components.distribution.engine.ArtifactInfoImpl;
28 import org.openecomp.sdc.be.components.distribution.engine.ServiceDistributionArtifactsBuilder;
29 import org.openecomp.sdc.be.model.ArtifactDefinition;
30 import org.openecomp.sdc.be.model.Service;
31 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
32 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
33 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
35 import java.lang.reflect.Method;
36 import java.util.HashMap;
37 import java.util.List;
39 import java.util.stream.Collectors;
41 import static org.junit.Assert.assertEquals;
42 import static org.junit.Assert.assertNotNull;
43 import static org.junit.Assert.assertTrue;
45 public class ServiceDistributionArtifactsBuilderTest extends BeConfDependentTest {
47 private final ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
50 ServiceDistributionArtifactsBuilder serviceDistributionArtifactsBuilder = new ServiceDistributionArtifactsBuilder(toscaOperationFacade);
52 @SuppressWarnings({ "unchecked", "rawtypes" })
54 public void testConvertServiceArtifactsToArtifactInfo() {
56 Service service = new Service();
57 String serviceName = "myService";
58 String serviceVersion = "1.0";
59 String serviceId = "serviceId";
60 service.setName(serviceName);
61 service.setVersion(serviceVersion);
62 service.setUniqueId(serviceId);
65 String artifactName = "service-Myservice-template.yml";
66 String artifactLabel = "assettoscatemplate";
67 String esArtifactId = "123123dfgdfgd0";
68 byte[] payload = "some payload".getBytes();
70 ArtifactDefinition toscaTemplateArtifact = new ArtifactDefinition();
71 toscaTemplateArtifact.setArtifactName(artifactName);
72 toscaTemplateArtifact.setArtifactType(ArtifactTypeEnum.TOSCA_TEMPLATE.getType());
73 toscaTemplateArtifact.setArtifactLabel(artifactLabel);
74 toscaTemplateArtifact.setEsId(esArtifactId);
75 toscaTemplateArtifact.setUniqueId(esArtifactId);
76 toscaTemplateArtifact.setPayload(payload);
78 Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
79 toscaArtifacts.put(artifactLabel, toscaTemplateArtifact);
80 service.setToscaArtifacts(toscaArtifacts);
82 ArtifactDefinition deploymentArtifact = new ArtifactDefinition();
83 deploymentArtifact.setArtifactName("deployment.yaml");
84 deploymentArtifact.setArtifactGroupType(ArtifactGroupTypeEnum.DEPLOYMENT);
85 deploymentArtifact.setArtifactType(ArtifactTypeEnum.OTHER.getType());
86 deploymentArtifact.setArtifactLabel("deployment");
87 deploymentArtifact.setEsId("deployment007");
88 deploymentArtifact.setUniqueId("deployment007");
89 deploymentArtifact.setPayload(payload);
90 Map<String, ArtifactDefinition> deploymentArtifacts = new HashMap<>();
91 deploymentArtifacts.put("deployment", deploymentArtifact);
92 service.setDeploymentArtifacts(deploymentArtifacts);
94 Class<ServiceDistributionArtifactsBuilder> targetClass = ServiceDistributionArtifactsBuilder.class;
95 String methodName = "convertServiceArtifactsToArtifactInfo";
96 Object[] argObjects = {service};
97 Class[] argClasses = {Service.class};
99 Method method = targetClass.getDeclaredMethod(methodName, argClasses);
100 method.setAccessible(true);
101 List<ArtifactInfoImpl> convertServiceArtifactsToArtifactInfoRes =
102 (List<ArtifactInfoImpl>) method.invoke(serviceDistributionArtifactsBuilder, argObjects);
103 assertNotNull(convertServiceArtifactsToArtifactInfoRes);
104 assertEquals(2, convertServiceArtifactsToArtifactInfoRes.size());
105 List<String> artifactsNames = convertServiceArtifactsToArtifactInfoRes.stream().map(ArtifactInfoImpl::getArtifactName).collect(Collectors.toList());
106 assertTrue(artifactsNames.contains(artifactName) && artifactsNames.contains("deployment.yaml"));
108 catch (Exception e) {