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