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 static org.junit.Assert.assertTrue;
25 import java.lang.reflect.Method;
26 import java.util.HashMap;
27 import java.util.List;
29 import org.junit.Test;
30 import org.mockito.InjectMocks;
31 import org.openecomp.sdc.be.components.BaseConfDependentTest;
32 import org.openecomp.sdc.be.components.distribution.engine.ArtifactInfoImpl;
33 import org.openecomp.sdc.be.components.distribution.engine.ServiceDistributionArtifactsBuilder;
34 import org.openecomp.sdc.be.model.ArtifactDefinition;
35 import org.openecomp.sdc.be.model.Service;
36 import org.openecomp.sdc.common.api.ArtifactTypeEnum;
38 public class ServiceDistributionArtifactsBuilderTest extends BaseConfDependentTest {
41 ServiceDistributionArtifactsBuilder serviceDistributionArtifactsBuilder = new ServiceDistributionArtifactsBuilder();
43 @SuppressWarnings({ "unchecked", "rawtypes" })
45 public void testConvertServiceArtifactsToArtifactInfo() {
47 Service service = new Service();
48 String serviceName = "myService";
49 String serviceVersion = "1.0";
50 String serviceId = "serviceId";
51 service.setName(serviceName);
52 service.setVersion(serviceVersion);
53 service.setUniqueId(serviceId);
56 String artifactName = "service-Myservice-template.yml";
57 String artifactLabel = "assettoscatemplate";
58 String esArtifactId = "123123dfgdfgd0";
59 byte[] payload = "some payload".getBytes();
61 ArtifactDefinition toscaTemplateArtifact = new ArtifactDefinition();
62 toscaTemplateArtifact.setArtifactName(artifactName);
63 toscaTemplateArtifact.setArtifactType(ArtifactTypeEnum.TOSCA_TEMPLATE.getType());
64 toscaTemplateArtifact.setArtifactLabel(artifactLabel);
65 toscaTemplateArtifact.setEsId(esArtifactId);
66 toscaTemplateArtifact.setPayload(payload);
68 Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
69 toscaArtifacts.put(artifactLabel, toscaTemplateArtifact);
70 service.setToscaArtifacts(toscaArtifacts);
72 Class<ServiceDistributionArtifactsBuilder> targetClass = ServiceDistributionArtifactsBuilder.class;
73 String methodName = "convertServiceArtifactsToArtifactInfo";
74 Object[] argObjects = {service};
75 Class[] argClasses = {Service.class};
77 Method method = targetClass.getDeclaredMethod(methodName, argClasses);
78 method.setAccessible(true);
79 List<ArtifactInfoImpl> convertServiceArtifactsToArtifactInfoRes =
80 (List<ArtifactInfoImpl>) method.invoke(serviceDistributionArtifactsBuilder, argObjects);
81 assertTrue(convertServiceArtifactsToArtifactInfoRes != null);
82 assertTrue(convertServiceArtifactsToArtifactInfoRes.size() == 1);
83 assertTrue(convertServiceArtifactsToArtifactInfoRes.get(0).getArtifactName().equals(artifactName));