2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.adapters.catalogdb.catalogrest;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
26 import static org.junit.Assert.fail;
28 import java.util.List;
30 import javax.transaction.Transactional;
32 import org.junit.Before;
33 import org.junit.Test;
34 import org.junit.runner.RunWith;
35 import org.onap.so.adapters.catalogdb.CatalogDBApplication;
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.onap.so.logger.MsoLogger;
44 import org.springframework.beans.factory.annotation.Autowired;
45 import org.springframework.boot.context.embedded.LocalServerPort;
46 import org.springframework.boot.test.context.SpringBootTest;
47 import org.springframework.test.context.ActiveProfiles;
48 import org.springframework.test.context.junit4.SpringRunner;
50 @RunWith(SpringRunner.class)
51 @SpringBootTest(classes = CatalogDBApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
52 @ActiveProfiles("test")
53 public class NetworkCollectionCatalogDbQueryTest {
55 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, NetworkCollectionCatalogDbQueryTest.class);
56 private static final String NETWORKCOLLECTION = "NetworkCollection";
58 private final String serviceUUID = "5df8b6de-2083-11e7-93ae-92361f002671";
62 boolean isInitialized;
65 CatalogDbClientPortChanger client;
68 public void initialize(){
69 client.wiremockPort= String.valueOf(port);
74 public void networkCollectionTest() {
75 msoLogger.debug("TEST IS STARTING UP...");
76 String modelUUID = "4694a55f-58b3-4f17-92a5-796d6f5ffd0d";
77 boolean found = false;
78 msoLogger.debug(Integer.toString(port));
79 InstanceGroup instanceGroup = null;
80 List<CollectionResourceInstanceGroupCustomization> collectionInstanceGroupList = null;
81 org.onap.so.db.catalog.beans.Service service = client.getServiceByID(modelUUID);
82 if (service == null) {
83 msoLogger.debug("null");
85 List<CollectionResourceCustomization> customizations = service.getCollectionResourceCustomizations();
86 if (customizations.isEmpty()) {
87 msoLogger.debug("No Network Collection found. CollectionResourceCustomizations is empty");
89 for (CollectionResourceCustomization crc : customizations) {
90 if(client.getNetworkCollectionResourceCustomizationByID(crc.getModelCustomizationUUID())
91 instanceof NetworkCollectionResourceCustomization) {
92 if (crc.getCollectionResource() != null) {
93 if (crc.getCollectionResource()
94 .getToscaNodeType() != null) {
95 String toscaNodeType = crc.getCollectionResource()
97 if (toscaNodeType.contains(NETWORKCOLLECTION)) {
98 msoLogger.debug("Found a network collection");
99 instanceGroup = crc.getCollectionResource().getInstanceGroup();
100 collectionInstanceGroupList =
101 instanceGroup.getCollectionInstanceGroupCustomizations();
102 CollectionNetworkResourceCustomization collectionNetworkCust = instanceGroup.getCollectionNetworkResourceCustomizations().get(0);
103 msoLogger.debug("Found Collection Network Resource Customization: " + collectionNetworkCust.getModelCustomizationUUID());
106 "No Network Collection found. toscaNodeType does not contain NetworkCollection");
109 msoLogger.debug("No Network Collection found. toscaNodeType is null");
112 msoLogger.debug("No Network Collection found. collectionResource is null");
116 msoLogger.debug("Not a Network Collection Resource Customization Instance");
120 assertEquals("Number of CollectionResourceInstanceGroupCustomization in list", 2, collectionInstanceGroupList.size());
121 assertNotNull(instanceGroup);
126 public void buildingBlockDetailTest() {
127 msoLogger.debug("TEST IS STARTING UP...");
128 msoLogger.debug(Integer.toString(port));
129 String buildingBlockFlowName = "CreateNetworkCollectionBB";
130 BuildingBlockDetail buildingBlockDetail = client.getBuildingBlockDetail(buildingBlockFlowName);
131 msoLogger.debug("" + buildingBlockDetail.getResourceType());
132 assertNotNull(buildingBlockDetail);
136 public void fetchServiceTopology_Test() {
137 org.onap.so.db.catalog.beans.Service service = client.getServiceByID(serviceUUID);
139 if (service == null) {
140 fail("Service is null");
142 assertEquals(serviceUUID, service.getModelUUID());
143 assertEquals("MSOTADevInfra_vSAMP10a_Service",service.getModelName());
147 public void CollectionNetworkResourceCustomizationTest() {
148 String modelCustId = "1a61be4b-3378-4c9a-91c8-c919519b2d01";
149 CollectionNetworkResourceCustomization collectionNetworkCust = client.getCollectionNetworkResourceCustomizationByID(modelCustId);
150 assertNotNull(collectionNetworkCust);
151 msoLogger.debug(collectionNetworkCust.getModelCustomizationUUID());