add junit coverage for SvnfmService
[so.git] / adapters / mso-catalog-db-adapter / src / test / java / org / onap / so / adapters / catalogdb / catalogrest / ServiceMapperTest.java
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         testService.getVnfCustomizations().add(getTestVnfCustomization());
71         return testService;
72     }
73
74     private org.onap.so.db.catalog.beans.VnfResourceCustomization getTestVnfCustomization() {
75         org.onap.so.db.catalog.beans.VnfResourceCustomization test =
76                 new org.onap.so.db.catalog.beans.VnfResourceCustomization();
77         test.setId(1);
78         test.setAvailabilityZoneMaxCount(11);
79         test.setMaxInstances(3);
80         test.setMinInstances(1);
81         test.setModelCustomizationUUID("modelCustomizationUUID");
82         test.setModelInstanceName("modelInstanceName");
83         test.setMultiStageDesign("multiStageDesign");
84         test.setNfFunction("nfFunction");
85         test.setNfNamingCode("nfNamingCode");
86         test.setNfRole("nfRole");
87         test.setNfType("nfType");
88         test.setService(new org.onap.so.db.catalog.beans.Service());
89         test.setVnfResources(getTestVnfResource());
90         test.setVfModuleCustomizations(getTestVfModuleCust());
91         return test;
92     }
93
94     private List<VfModuleCustomization> getTestVfModuleCust() {
95         List<VfModuleCustomization> test = new ArrayList<>();
96         VfModuleCustomization testVfMod = new VfModuleCustomization();
97         testVfMod.setAvailabilityZoneCount(10);
98         testVfMod.setInitialCount(1);
99         testVfMod.setLabel("label");
100         testVfMod.setMaxInstances(3);
101         testVfMod.setMinInstances(1);
102         testVfMod.setModelCustomizationUUID("modelCustomizationUUID");
103         org.onap.so.db.catalog.beans.VfModule vfModule = new org.onap.so.db.catalog.beans.VfModule();
104         vfModule.setDescription("description");
105         vfModule.setIsBase(false);
106         vfModule.setModelInvariantUUID("modelInvariantUUID");
107         vfModule.setModelName("modelName");
108         vfModule.setModelUUID("modelUUID");
109         vfModule.setModelVersion("modelVersion");
110         HeatTemplate moduleHeatTemplate = new HeatTemplate();
111         moduleHeatTemplate.setArtifactChecksum("artifactChecksum");
112         moduleHeatTemplate.setArtifactUuid("artifactUuid");
113         List<HeatTemplate> childTemplates;
114         // moduleHeatTemplate.setChildTemplates(childTemplates);
115         moduleHeatTemplate.setDescription("description");
116         Set<HeatTemplateParam> parameters = new HashSet<>();
117         HeatTemplateParam heatParam = new HeatTemplateParam();
118         heatParam.setHeatTemplateArtifactUuid("heatTemplateArtifactUuid");
119         heatParam.setParamAlias("paramAlias");
120         heatParam.setParamName("paramName");
121         heatParam.setParamType("paramType");
122         heatParam.setRequired(false);
123         parameters.add(heatParam);
124         moduleHeatTemplate.setParameters(parameters);
125         moduleHeatTemplate.setTemplateBody("templateBody");
126         moduleHeatTemplate.setTemplateName("templateName");
127         moduleHeatTemplate.setTimeoutMinutes(1000);
128         moduleHeatTemplate.setVersion("version");
129         vfModule.setModuleHeatTemplate(moduleHeatTemplate);
130         testVfMod.setVfModule(vfModule);
131         test.add(testVfMod);
132         return test;
133     }
134
135     private org.onap.so.db.catalog.beans.VnfResource getTestVnfResource() {
136         org.onap.so.db.catalog.beans.VnfResource test = new org.onap.so.db.catalog.beans.VnfResource();
137         test.setCategory("category");
138         test.setDescription("description");
139         test.setModelInvariantUUID("modelInvariantUUID");
140         test.setModelName("modelName");
141         test.setModelUUID("modelUUID");
142         test.setModelVersion("modelVersion");
143         test.setAicVersionMax("cloudVersionMax");
144         test.setAicVersionMin("cloudVersionMin");
145         test.setOrchestrationMode("orchestrationMode");
146         test.setSubCategory("subCategory");
147         test.setToscaNodeType("toscaNodeType");
148         return test;
149     }
150
151     private String getJson(String filename) throws IOException {
152         return new String(Files.readAllBytes(Paths.get("src/test/resources/" + filename)));
153     }
154 }