added generic fabric support to SO
[so.git] / mso-catalog-db / src / test / java / org / onap / so / db / catalog / data / repository / CvnfcCustomizationRepositoryTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2018 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.db.catalog.data.repository;
22
23 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
24 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
25
26 import java.util.ArrayList;
27 import java.util.List;
28
29 import org.junit.Assert;
30 import org.junit.Test;
31 import org.onap.so.db.catalog.BaseTest;
32 import org.onap.so.db.catalog.beans.CvnfcCustomization;
33 import org.onap.so.db.catalog.beans.VfModule;
34 import org.onap.so.db.catalog.beans.VfModuleCustomization;
35 import org.onap.so.db.catalog.beans.VnfResource;
36 import org.onap.so.db.catalog.beans.VnfResourceCustomization;
37 import org.onap.so.db.catalog.beans.VnfcCustomization;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.transaction.annotation.Transactional;
40 import org.springframework.util.CollectionUtils;
41
42 public class CvnfcCustomizationRepositoryTest extends BaseTest {
43     @Autowired
44     private CvnfcCustomizationRepository cvnfcCustomizationRepository;
45     
46     @Test
47     public void findAllTest() throws Exception {
48         List<CvnfcCustomization> cvnfcCustomizationList = cvnfcCustomizationRepository.findAll();
49         Assert.assertFalse(CollectionUtils.isEmpty(cvnfcCustomizationList));
50     }
51     
52     @Test
53     @Transactional
54     public void createAndGetTest() throws Exception {
55                         
56         CvnfcCustomization cvnfcCustomization = setUpCvnfcCustomization();
57         cvnfcCustomization.setModelCustomizationUUID("cf9f6efc-9f14-11e8-98d0-529269fb1459");
58
59         VfModuleCustomization vfModuleCustomization = new VfModuleCustomization();
60         vfModuleCustomization.setModelCustomizationUUID("cf9f6efc-9f14-11e8-98d0-529269fb1459");
61         
62         VfModule vFModule = setUpVfModule();
63         VnfResource vnfResource = setUpVnfResource();
64
65         vFModule.setVnfResources(vnfResource);
66         vfModuleCustomization.setVfModule(vFModule);
67         cvnfcCustomization.setVfModuleCustomization(vfModuleCustomization);
68         
69         VnfResourceCustomization vnfResourceCustomization = new VnfResourceCustomization();
70         vnfResourceCustomization.setModelCustomizationUUID("cf9f6efc-9f14-11e8-98d0-529269fb1459"); 
71         vnfResourceCustomization.setModelInstanceName("testModelInstanceName");
72         
73         List<VnfResourceCustomization> vnfResourceCustomizations = new ArrayList();
74         vnfResourceCustomizations.add(vnfResourceCustomization);
75         vnfResource.setVnfResourceCustomizations(vnfResourceCustomizations);
76         vnfResourceCustomization.setVnfResources(vnfResource);
77         
78         cvnfcCustomization.setVnfResourceCustomization(vnfResourceCustomization);
79         
80         VnfcCustomization vnfcCustomization = setUpVnfcCustomization();
81         vnfcCustomization.setModelCustomizationUUID("d95d704a-9ff2-11e8-98d0-529269fb1459");
82         cvnfcCustomization.setVnfcCustomization(vnfcCustomization);
83         
84         cvnfcCustomizationRepository.save(cvnfcCustomization);
85         
86         List<CvnfcCustomization> cvnfcCustomizationList = cvnfcCustomizationRepository.findAll();
87         boolean matchFound = false;
88         for (CvnfcCustomization foundCvnfcCustomization : cvnfcCustomizationList) {
89                 if (foundCvnfcCustomization.getDescription().equalsIgnoreCase(cvnfcCustomization.getDescription())) {
90                 
91                 assertThat(cvnfcCustomization, sameBeanAs(foundCvnfcCustomization)
92                                 .ignoring("id")
93                                 .ignoring("created")
94                                 .ignoring("vnfVfmoduleCvnfcConfigurationCustomization")
95                                 .ignoring("vnfResourceCusteModelCustomizationUUID"));
96                 
97                 matchFound = true;
98                 break;
99                 }
100         }
101         Assert.assertTrue(matchFound);
102     }
103 }