2 * ============LICENSE_START=======================================================
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
13 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
23 package org.onap.so.adapters.catalogdb.catalogrest;
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;
30 import java.util.HashSet;
31 import java.util.List;
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;
57 import org.springframework.beans.BeanUtils;
59 @RunWith(SpringRunner.class)
60 @SpringBootTest(classes = CatalogDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
61 @ActiveProfiles("test")
62 public class CvnfcCatalogDbQueryTest {
65 private CvnfcCustomizationRepository cvnfcCustomizationRepository;
67 private static final Logger logger = LoggerFactory.getLogger(CvnfcCatalogDbQueryTest.class);
71 boolean isInitialized;
74 CatalogDbClientPortChanger client;
77 public void initialize(){
78 client.wiremockPort= String.valueOf(port);
82 public void cVnfcTest() {
84 CvnfcCustomization cvnfcCustomization = setUpCvnfcCustomization("dadc2c8c-2bab-11e9-b210-d663bd873d93");
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);
91 CvnfcCustomization templateCvnfcCustomization = new CvnfcCustomization();
92 BeanUtils.copyProperties(found, templateCvnfcCustomization, "vnfVfmoduleCvnfcConfigurationCustomization", "vfModuleCustomization", "vnfcCustomization", "vnfResourceCustomization");
94 assertThat(cvnfcCustomization, sameBeanAs(templateCvnfcCustomization)
97 .ignoring("vnfVfmoduleCvnfcConfigurationCustomization")
98 .ignoring("vnfResourceCusteModelCustomizationUUID"));
102 public void cVnfcByCustomizationUUID_Test() {
104 CvnfcCustomization cvnfcCustomization = setUpCvnfcCustomization("dadc2c8c-2bab-11e9-b210-d663bd873d93");
106 CvnfcCustomization found = client.getCvnfcCustomizationByCustomizationUUID("dadc2c8c-2bab-11e9-b210-d663bd873d93");
107 assertNotNull(found);
109 CvnfcCustomization templateCvnfcCustomization = new CvnfcCustomization();
110 BeanUtils.copyProperties(found, templateCvnfcCustomization, "vnfVfmoduleCvnfcConfigurationCustomization", "vfModuleCustomization", "vnfcCustomization", "vnfResourceCustomization");
112 assertThat(cvnfcCustomization, sameBeanAs(templateCvnfcCustomization)
115 .ignoring("vnfVfmoduleCvnfcConfigurationCustomization")
116 .ignoring("vnfResourceCusteModelCustomizationUUID"));
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;
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;