Corrected hibernate for cfvc customization table
[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.db.catalog.beans.ConfigurationResource;
40 import org.onap.so.db.catalog.beans.CvnfcCustomization;
41 import org.onap.so.db.catalog.beans.VfModule;
42 import org.onap.so.db.catalog.beans.VfModuleCustomization;
43 import org.onap.so.db.catalog.beans.VnfResource;
44 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
45 import org.onap.so.db.catalog.beans.VnfVfmoduleCvnfcConfigurationCustomization;
46 import org.onap.so.db.catalog.beans.VnfcCustomization;
47 import org.onap.so.db.catalog.client.CatalogDbClientPortChanger;
48 import org.onap.so.db.catalog.data.repository.CvnfcCustomizationRepository;
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
51 import org.springframework.beans.factory.annotation.Autowired;
52 import org.springframework.boot.web.server.LocalServerPort;
53 import org.springframework.boot.test.context.SpringBootTest;
54 import org.springframework.test.context.ActiveProfiles;
55 import org.springframework.test.context.junit4.SpringRunner;
56
57 import org.springframework.beans.BeanUtils;
58
59 @RunWith(SpringRunner.class)
60 @SpringBootTest(classes = CatalogDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
61 @ActiveProfiles("test")
62 public class CvnfcCatalogDbQueryTest {
63
64     @Autowired
65     private CvnfcCustomizationRepository cvnfcCustomizationRepository;
66     
67         private static final Logger logger = LoggerFactory.getLogger(CvnfcCatalogDbQueryTest.class);
68
69         @LocalServerPort
70         private int port;
71         boolean isInitialized;
72
73         @Autowired
74         CatalogDbClientPortChanger client;
75
76         @Before
77         public void initialize(){
78                 client.wiremockPort= String.valueOf(port);
79         }
80         
81         @Test
82         public void cVnfcTest() {
83                 
84         CvnfcCustomization cvnfcCustomization = setUpCvnfcCustomization("dadc2c8c-2bab-11e9-b210-d663bd873d93");
85         
86                 List<CvnfcCustomization> foundCvnfcCustomization = client.getCvnfcCustomizationByVnfCustomizationUUIDAndVfModuleCustomizationUUID("68dc9a92-214c-11e7-93ae-92361f002671","cb82ffd8-252a-11e7-93ae-92361f002671");
87                 assertNotNull(foundCvnfcCustomization);
88                 assertTrue(foundCvnfcCustomization.size() > 0);
89                 CvnfcCustomization found = foundCvnfcCustomization.get(0);
90                 
91                 CvnfcCustomization templateCvnfcCustomization = new CvnfcCustomization();
92                 BeanUtils.copyProperties(found, templateCvnfcCustomization, "vnfVfmoduleCvnfcConfigurationCustomization", "vfModuleCustomization", "vnfcCustomization", "vnfResourceCustomization");
93                 
94         assertThat(cvnfcCustomization, sameBeanAs(templateCvnfcCustomization)
95                         .ignoring("id")
96                         .ignoring("created")
97                         .ignoring("vnfVfmoduleCvnfcConfigurationCustomization")
98                         .ignoring("vnfResourceCusteModelCustomizationUUID"));
99         }
100         
101         @Test
102         public void cVnfcByCustomizationUUID_Test() {
103                 
104         CvnfcCustomization cvnfcCustomization = setUpCvnfcCustomization("dadc2c8c-2bab-11e9-b210-d663bd873d93");
105         
106                 CvnfcCustomization found = client.getCvnfcCustomizationByCustomizationUUID("dadc2c8c-2bab-11e9-b210-d663bd873d93");
107                 assertNotNull(found);
108                 
109                 CvnfcCustomization templateCvnfcCustomization = new CvnfcCustomization();
110                 BeanUtils.copyProperties(found, templateCvnfcCustomization, "vnfVfmoduleCvnfcConfigurationCustomization", "vfModuleCustomization", "vnfcCustomization", "vnfResourceCustomization");
111                 
112         assertThat(cvnfcCustomization, sameBeanAs(templateCvnfcCustomization)
113                         .ignoring("id")
114                         .ignoring("created")
115                         .ignoring("vnfVfmoduleCvnfcConfigurationCustomization")
116                         .ignoring("vnfResourceCusteModelCustomizationUUID"));
117         }
118
119         
120     protected CvnfcCustomization setUpCvnfcCustomization(String id){
121         CvnfcCustomization cvnfcCustomization = new CvnfcCustomization();
122         cvnfcCustomization.setModelCustomizationUUID(id);
123         cvnfcCustomization.setModelInstanceName("testModelInstanceName");
124         cvnfcCustomization.setModelUUID("b25735fe-9b37-11e8-98d0-529269fb1459");
125         cvnfcCustomization.setModelInvariantUUID("ba7e6ef0-9b37-11e8-98d0-529269fb1459");
126         cvnfcCustomization.setModelVersion("testModelVersion");
127         cvnfcCustomization.setModelName("testModelName");
128         cvnfcCustomization.setToscaNodeType("testToscaNodeType");
129         cvnfcCustomization.setDescription("testCvnfcCustomzationDescription");
130         cvnfcCustomization.setNfcFunction("testNfcFunction");
131         cvnfcCustomization.setNfcNamingCode("testNfcNamingCode");
132         return cvnfcCustomization;
133     }
134     
135     protected VnfcCustomization setUpVnfcCustomization(){
136         VnfcCustomization vnfcCustomization = new VnfcCustomization();
137         vnfcCustomization.setModelInstanceName("testVnfcCustomizationModelInstanceName");
138         vnfcCustomization.setModelUUID("321228a4-9f15-11e8-98d0-529269fb1459");
139         vnfcCustomization.setModelInvariantUUID("c0659136-9f15-11e8-98d0-529269fb1459");
140         vnfcCustomization.setModelVersion("testModelVersion");
141         vnfcCustomization.setModelName("testModelName");
142         vnfcCustomization.setToscaNodeType("testToscaModelType");
143         vnfcCustomization.setDescription("testVnfcCustomizationDescription");
144         return vnfcCustomization;
145     }
146 }