[SO] Release so 1.13.0 image
[so.git] / adapters / mso-catalog-db-adapter / src / test / java / org / onap / so / adapters / catalogdb / catalogrest / NetworkCollectionCatalogDbQueryTest.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 org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertTrue;
28 import static org.junit.Assert.fail;
29 import java.util.List;
30 import javax.transaction.Transactional;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.onap.so.adapters.catalogdb.CatalogDbAdapterBaseTest;
34 import org.onap.so.db.catalog.beans.BuildingBlockDetail;
35 import org.onap.so.db.catalog.beans.CollectionNetworkResourceCustomization;
36 import org.onap.so.db.catalog.beans.CollectionResourceCustomization;
37 import org.onap.so.db.catalog.beans.CollectionResourceInstanceGroupCustomization;
38 import org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization;
39 import org.onap.so.db.catalog.beans.CvnfcCustomization;
40 import org.onap.so.db.catalog.beans.InstanceGroup;
41 import org.onap.so.db.catalog.beans.NetworkCollectionResourceCustomization;
42 import org.onap.so.db.catalog.client.CatalogDbClientPortChanger;
43 import org.slf4j.Logger;
44 import org.slf4j.LoggerFactory;
45 import org.springframework.beans.factory.annotation.Autowired;
46 import org.springframework.boot.web.server.LocalServerPort;
47
48 public class NetworkCollectionCatalogDbQueryTest extends CatalogDbAdapterBaseTest {
49
50     private static final Logger logger = LoggerFactory.getLogger(NetworkCollectionCatalogDbQueryTest.class);
51     private static final String NETWORKCOLLECTION = "NetworkCollection";
52
53     private final String serviceUUID = "5df8b6de-2083-11e7-93ae-92361f002671";
54
55     @LocalServerPort
56     private int port;
57     boolean isInitialized;
58
59     @Autowired
60     CatalogDbClientPortChanger client;
61
62     @Before
63     public void initialize() {
64         client.wiremockPort = String.valueOf(port);
65     }
66
67     @Test
68     @Transactional
69     public void networkCollectionTest() {
70         logger.debug("TEST IS STARTING UP...");
71         String modelUUID = "4694a55f-58b3-4f17-92a5-796d6f5ffd0d";
72         boolean found = false;
73         logger.debug(Integer.toString(port));
74         InstanceGroup instanceGroup = null;
75         List<CollectionResourceInstanceGroupCustomization> collectionInstanceGroupList = null;
76         org.onap.so.db.catalog.beans.Service service = client.getServiceByID(modelUUID);
77         if (service == null) {
78             logger.debug("null");
79         } else {
80             List<CollectionResourceCustomization> customizations = service.getCollectionResourceCustomizations();
81             if (customizations.isEmpty()) {
82                 logger.debug("No Network Collection found. CollectionResourceCustomizations is empty");
83             }
84             for (CollectionResourceCustomization crc : customizations) {
85                 if (client.getNetworkCollectionResourceCustomizationByID(
86                         crc.getModelCustomizationUUID()) instanceof NetworkCollectionResourceCustomization) {
87                     if (crc.getCollectionResource() != null) {
88                         if (crc.getCollectionResource().getToscaNodeType() != null) {
89                             String toscaNodeType = crc.getCollectionResource().getToscaNodeType();
90                             if (toscaNodeType.contains(NETWORKCOLLECTION)) {
91                                 logger.debug("Found a network collection");
92                                 instanceGroup = crc.getCollectionResource().getInstanceGroup();
93                                 collectionInstanceGroupList = instanceGroup.getCollectionInstanceGroupCustomizations();
94                                 CollectionNetworkResourceCustomization collectionNetworkCust =
95                                         instanceGroup.getCollectionNetworkResourceCustomizations().get(0);
96                                 logger.debug("Found Collection Network Resource Customization: "
97                                         + collectionNetworkCust.getModelCustomizationUUID());
98                             } else {
99                                 logger.debug(
100                                         "No Network Collection found. toscaNodeType does not contain NetworkCollection");
101                             }
102                         } else {
103                             logger.debug("No Network Collection found. toscaNodeType is null");
104                         }
105                     } else {
106                         logger.debug("No Network Collection found. collectionResource is null");
107                     }
108                     found = true;
109                 } else {
110                     logger.debug("Not a Network Collection Resource Customization Instance");
111                 }
112             }
113         }
114         assertEquals("Number of CollectionResourceInstanceGroupCustomization in list", 2,
115                 collectionInstanceGroupList.size());
116         assertNotNull(instanceGroup);
117         assertTrue(found);
118     }
119
120     @Test
121     public void buildingBlockDetailTest() {
122         logger.debug("TEST IS STARTING UP...");
123         logger.debug(Integer.toString(port));
124         String buildingBlockFlowName = "CreateNetworkCollectionBB";
125         BuildingBlockDetail buildingBlockDetail = client.getBuildingBlockDetail(buildingBlockFlowName);
126         logger.debug("" + buildingBlockDetail.getResourceType());
127         assertNotNull(buildingBlockDetail);
128     }
129
130     @Test
131     public void fetchServiceTopology_Test() {
132         org.onap.so.db.catalog.beans.Service service = client.getServiceByID(serviceUUID);
133
134         if (service == null) {
135             fail("Service is null");
136         }
137         assertEquals(serviceUUID, service.getModelUUID());
138         assertEquals("MSOTADevInfra_vSAMP10a_Service", service.getModelName());
139     }
140
141     @Test
142     public void CollectionNetworkResourceCustomizationTest() {
143         String modelCustId = "1a61be4b-3378-4c9a-91c8-c919519b2d01";
144         CollectionNetworkResourceCustomization collectionNetworkCust =
145                 client.getCollectionNetworkResourceCustomizationByID(modelCustId);
146         assertNotNull(collectionNetworkCust);
147         logger.debug(collectionNetworkCust.getModelCustomizationUUID());
148     }
149
150     @Test
151     public void getCvnfcCustomization() {
152         client.getServiceByID(serviceUUID);
153         String vfId = "cb82ffd8-252a-11e7-93ae-92361f002671";
154         String vnfId = "68dc9a92-214c-11e7-93ae-92361f002671";
155
156         CvnfcConfigurationCustomization fabricConfig =
157                 client.getCvnfcCustomization(serviceUUID, vnfId, vfId, "dadc2c8c-2bab-11e9-b210-d663bd873d95");
158         assertEquals("386c9aa7-9318-48ee-a6d1-1bf0f85de385", fabricConfig.getModelCustomizationUUID());
159     }
160
161 }