Merge "Construct multicloud infra_workload endpoint"
[so.git] / adapters / mso-catalog-db-adapter / src / test / java / org / onap / so / adapters / catalogdb / catalogrest / CvnfcCatalogDbQueryTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.adapters.catalogdb.catalogrest;
24
25 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
26 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
29
30 import java.util.HashSet;
31 import java.util.List;
32 import java.util.Set;
33
34 import org.junit.Assert;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.junit.runner.RunWith;
38 import org.onap.so.adapters.catalogdb.CatalogDBApplication;
39 import org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest;
40 import org.onap.so.db.catalog.beans.ConfigurationResource;
41 import org.onap.so.db.catalog.beans.CvnfcCustomization;
42 import org.onap.so.db.catalog.beans.VfModule;
43 import org.onap.so.db.catalog.beans.VfModuleCustomization;
44 import org.onap.so.db.catalog.beans.VnfResource;
45 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
46 import org.onap.so.db.catalog.beans.VnfVfmoduleCvnfcConfigurationCustomization;
47 import org.onap.so.db.catalog.beans.VnfcCustomization;
48 import org.onap.so.db.catalog.client.CatalogDbClientPortChanger;
49 import org.onap.so.db.catalog.data.repository.CvnfcCustomizationRepository;
50 import org.slf4j.Logger;
51 import org.slf4j.LoggerFactory;
52 import org.springframework.beans.factory.annotation.Autowired;
53 import org.springframework.boot.web.server.LocalServerPort;
54 import org.springframework.boot.test.context.SpringBootTest;
55 import org.springframework.test.context.ActiveProfiles;
56 import org.springframework.test.context.junit4.SpringRunner;
57
58 import org.springframework.beans.BeanUtils;
59
60 public class CvnfcCatalogDbQueryTest extends CatalogDbAdapterBaseTest {
61
62     @Autowired
63     private CvnfcCustomizationRepository cvnfcCustomizationRepository;
64     
65         private static final Logger logger = LoggerFactory.getLogger(CvnfcCatalogDbQueryTest.class);
66
67         @LocalServerPort
68         private int port;
69         boolean isInitialized;
70
71         @Autowired
72         CatalogDbClientPortChanger client;
73
74         @Before
75         public void initialize(){
76                 client.wiremockPort= String.valueOf(port);
77         }
78         
79         @Test
80         public void cVnfcTest() {
81                 
82         CvnfcCustomization cvnfcCustomization = setUpCvnfcCustomization("dadc2c8c-2bab-11e9-b210-d663bd873d93");
83         
84                 List<CvnfcCustomization> foundCvnfcCustomization = client.getCvnfcCustomizationByVnfCustomizationUUIDAndVfModuleCustomizationUUID("68dc9a92-214c-11e7-93ae-92361f002671","cb82ffd8-252a-11e7-93ae-92361f002671");
85                 assertNotNull(foundCvnfcCustomization);
86                 assertTrue(foundCvnfcCustomization.size() > 0);
87                 CvnfcCustomization found = foundCvnfcCustomization.get(0);
88                 
89                 CvnfcCustomization templateCvnfcCustomization = new CvnfcCustomization();
90                 BeanUtils.copyProperties(found, templateCvnfcCustomization, "vnfVfmoduleCvnfcConfigurationCustomization", "vfModuleCustomization", "vnfcCustomization", "vnfResourceCustomization");
91                 
92         assertThat(cvnfcCustomization, sameBeanAs(templateCvnfcCustomization)
93                         .ignoring("id")
94                         .ignoring("created")
95                         .ignoring("vnfVfmoduleCvnfcConfigurationCustomization")
96                         .ignoring("vnfResourceCusteModelCustomizationUUID"));
97         }
98         
99         @Test
100         public void cVnfcByCustomizationUUID_Test() {
101                 
102         CvnfcCustomization cvnfcCustomization = setUpCvnfcCustomization("dadc2c8c-2bab-11e9-b210-d663bd873d93");
103         
104                 CvnfcCustomization found = client.getCvnfcCustomizationByCustomizationUUID("dadc2c8c-2bab-11e9-b210-d663bd873d93");
105                 assertNotNull(found);
106                 
107                 CvnfcCustomization templateCvnfcCustomization = new CvnfcCustomization();
108                 BeanUtils.copyProperties(found, templateCvnfcCustomization, "vnfVfmoduleCvnfcConfigurationCustomization", "vfModuleCustomization", "vnfcCustomization", "vnfResourceCustomization");
109                 
110         assertThat(cvnfcCustomization, sameBeanAs(templateCvnfcCustomization)
111                         .ignoring("id")
112                         .ignoring("created")
113                         .ignoring("vnfVfmoduleCvnfcConfigurationCustomization")
114                         .ignoring("vnfResourceCusteModelCustomizationUUID"));
115         }
116
117         
118     protected CvnfcCustomization setUpCvnfcCustomization(String id){
119         CvnfcCustomization cvnfcCustomization = new CvnfcCustomization();
120         cvnfcCustomization.setModelCustomizationUUID(id);
121         cvnfcCustomization.setModelInstanceName("testModelInstanceName");
122         cvnfcCustomization.setModelUUID("b25735fe-9b37-11e8-98d0-529269fb1459");
123         cvnfcCustomization.setModelInvariantUUID("ba7e6ef0-9b37-11e8-98d0-529269fb1459");
124         cvnfcCustomization.setModelVersion("testModelVersion");
125         cvnfcCustomization.setModelName("testModelName");
126         cvnfcCustomization.setToscaNodeType("testToscaNodeType");
127         cvnfcCustomization.setDescription("testCvnfcCustomzationDescription");
128         cvnfcCustomization.setNfcFunction("testNfcFunction");
129         cvnfcCustomization.setNfcNamingCode("testNfcNamingCode");
130         return cvnfcCustomization;
131     }
132     
133     protected VnfcCustomization setUpVnfcCustomization(){
134         VnfcCustomization vnfcCustomization = new VnfcCustomization();
135         vnfcCustomization.setModelInstanceName("testVnfcCustomizationModelInstanceName");
136         vnfcCustomization.setModelUUID("321228a4-9f15-11e8-98d0-529269fb1459");
137         vnfcCustomization.setModelInvariantUUID("c0659136-9f15-11e8-98d0-529269fb1459");
138         vnfcCustomization.setModelVersion("testModelVersion");
139         vnfcCustomization.setModelName("testModelName");
140         vnfcCustomization.setToscaNodeType("testToscaModelType");
141         vnfcCustomization.setDescription("testVnfcCustomizationDescription");
142         return vnfcCustomization;
143     }
144 }