d46fd9c7ba5f345b36e37252214b0042b275cd63
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 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
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.onap.so.adapters.catalogdb.catalogrest;
22
23 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
24 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
25 import java.io.IOException;
26 import java.nio.file.Files;
27 import java.nio.file.Paths;
28 import java.util.ArrayList;
29 import java.util.HashSet;
30 import java.util.List;
31 import java.util.Set;
32 import org.junit.Test;
33 import org.onap.so.adapters.catalogdb.rest.ServiceMapper;
34 import org.onap.so.db.catalog.beans.HeatTemplate;
35 import org.onap.so.db.catalog.beans.HeatTemplateParam;
36 import org.onap.so.db.catalog.beans.VfModuleCustomization;
37 import org.onap.so.rest.catalog.beans.Service;
38 import wiremock.com.fasterxml.jackson.core.JsonParseException;
39 import wiremock.com.fasterxml.jackson.databind.JsonMappingException;
40 import wiremock.com.fasterxml.jackson.databind.ObjectMapper;
41
42 public class ServiceMapperTest {
43
44     private ServiceMapper serviceMapper = new ServiceMapper();
45
46     @Test
47     public void service_map_test() throws JsonParseException, JsonMappingException, IOException {
48         Service actual = serviceMapper.mapService(getTestService(), 2);
49         assertThat(actual, sameBeanAs(getExpectedService()));
50     }
51
52     private Service getExpectedService() throws JsonParseException, JsonMappingException, IOException {
53         ObjectMapper mapper = new ObjectMapper();
54         return mapper.readValue(getJson("ExpectedService.json"), Service.class);
55     }
56
57
58     private org.onap.so.db.catalog.beans.Service getTestService() {
59         org.onap.so.db.catalog.beans.Service testService = new org.onap.so.db.catalog.beans.Service();
60         testService.setCategory("category");
61         testService.setDescription("description");
62         testService.setDistrobutionStatus("distrobutionStatus");
63         testService.setEnvironmentContext("environmentContext");
64         testService.setModelInvariantUUID("modelInvariantUUID");
65         testService.setModelName("modelName");
66         testService.setModelUUID("modelUUID");
67         testService.setModelVersion("modelVersion");
68         testService.setServiceType("serviceType");
69         testService.setServiceRole("serviceRole");
70
71         testService.getVnfCustomizations().add(getTestVnfCustomization());
72         return testService;
73     }
74
75     private org.onap.so.db.catalog.beans.VnfResourceCustomization getTestVnfCustomization() {
76         org.onap.so.db.catalog.beans.VnfResourceCustomization test =
77                 new org.onap.so.db.catalog.beans.VnfResourceCustomization();
78         test.setId(1);
79         test.setAvailabilityZoneMaxCount(11);
80         test.setMaxInstances(3);
81         test.setMinInstances(1);
82         test.setModelCustomizationUUID("modelCustomizationUUID");
83         test.setModelInstanceName("modelInstanceName");
84         test.setMultiStageDesign("multiStageDesign");
85         test.setNfFunction("nfFunction");
86         test.setNfNamingCode("nfNamingCode");
87         test.setNfRole("nfRole");
88         test.setNfType("nfType");
89         test.setService(new org.onap.so.db.catalog.beans.Service());
90         test.setVnfResources(getTestVnfResource());
91         test.setVfModuleCustomizations(getTestVfModuleCust());
92         return test;
93     }
94
95     private List<VfModuleCustomization> getTestVfModuleCust() {
96         List<VfModuleCustomization> test = new ArrayList<>();
97         VfModuleCustomization testVfMod = new VfModuleCustomization();
98         testVfMod.setAvailabilityZoneCount(10);
99         testVfMod.setInitialCount(1);
100         testVfMod.setLabel("label");
101         testVfMod.setMaxInstances(3);
102         testVfMod.setMinInstances(1);
103         testVfMod.setModelCustomizationUUID("modelCustomizationUUID");
104         org.onap.so.db.catalog.beans.VfModule vfModule = new org.onap.so.db.catalog.beans.VfModule();
105         vfModule.setDescription("description");
106         vfModule.setIsBase(false);
107         vfModule.setModelInvariantUUID("modelInvariantUUID");
108         vfModule.setModelName("modelName");
109         vfModule.setModelUUID("modelUUID");
110         vfModule.setModelVersion("modelVersion");
111         HeatTemplate moduleHeatTemplate = new HeatTemplate();
112         moduleHeatTemplate.setArtifactChecksum("artifactChecksum");
113         moduleHeatTemplate.setArtifactUuid("artifactUuid");
114         List<HeatTemplate> childTemplates;
115         // moduleHeatTemplate.setChildTemplates(childTemplates);
116         moduleHeatTemplate.setDescription("description");
117         Set<HeatTemplateParam> parameters = new HashSet<>();
118         HeatTemplateParam heatParam = new HeatTemplateParam();
119         heatParam.setHeatTemplateArtifactUuid("heatTemplateArtifactUuid");
120         heatParam.setParamAlias("paramAlias");
121         heatParam.setParamName("paramName");
122         heatParam.setParamType("paramType");
123         heatParam.setRequired(false);
124         parameters.add(heatParam);
125         moduleHeatTemplate.setParameters(parameters);
126         moduleHeatTemplate.setTemplateBody("templateBody");
127         moduleHeatTemplate.setTemplateName("templateName");
128         moduleHeatTemplate.setTimeoutMinutes(1000);
129         moduleHeatTemplate.setVersion("version");
130         vfModule.setModuleHeatTemplate(moduleHeatTemplate);
131         testVfMod.setVfModule(vfModule);
132         test.add(testVfMod);
133         return test;
134     }
135
136     private org.onap.so.db.catalog.beans.VnfResource getTestVnfResource() {
137         org.onap.so.db.catalog.beans.VnfResource test = new org.onap.so.db.catalog.beans.VnfResource();
138         test.setCategory("category");
139         test.setDescription("description");
140         test.setModelInvariantUUID("modelInvariantUUID");
141         test.setModelName("modelName");
142         test.setModelUUID("modelUUID");
143         test.setModelVersion("modelVersion");
144         test.setAicVersionMax("cloudVersionMax");
145         test.setAicVersionMin("cloudVersionMin");
146         test.setOrchestrationMode("orchestrationMode");
147         test.setSubCategory("subCategory");
148         test.setToscaNodeType("toscaNodeType");
149         return test;
150     }
151
152     private String getJson(String filename) throws IOException {
153         return new String(Files.readAllBytes(Paths.get("src/test/resources/" + filename)));
154     }
155 }