1c84cf6ca67adfbe28f7715f4b6e653541ec5b9d
[sdc.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.distribution;
22
23 import static org.junit.Assert.assertTrue;
24
25 import java.lang.reflect.Method;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
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;
37
38 public class ServiceDistributionArtifactsBuilderTest extends BaseConfDependentTest {
39
40         @InjectMocks
41         ServiceDistributionArtifactsBuilder serviceDistributionArtifactsBuilder = new ServiceDistributionArtifactsBuilder();
42         
43         @SuppressWarnings({ "unchecked", "rawtypes" })
44         @Test
45         public void testConvertServiceArtifactsToArtifactInfo() {
46
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);
54                 
55                 
56                 String artifactName = "service-Myservice-template.yml";
57                 String artifactLabel = "assettoscatemplate";
58                 String esArtifactId = "123123dfgdfgd0";
59                 byte[] payload = "some payload".getBytes();
60                 
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);
67                 
68                 Map<String, ArtifactDefinition> toscaArtifacts = new HashMap<>();
69                 toscaArtifacts.put(artifactLabel, toscaTemplateArtifact);
70                 service.setToscaArtifacts(toscaArtifacts);
71                 
72                 Class<ServiceDistributionArtifactsBuilder> targetClass = ServiceDistributionArtifactsBuilder.class;
73                 String methodName = "convertServiceArtifactsToArtifactInfo";
74                 Object[] argObjects = {service};
75                 Class[] argClasses = {Service.class};
76             try {
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));
84             }
85             catch (Exception e) {
86                 e.printStackTrace();
87             }
88         }
89 }