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