2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.onap.so.aaisimulator.controller;
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
26 import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL;
27 import static org.onap.so.aaisimulator.utils.TestConstants.GENERIC_VNF_URL;
28 import static org.onap.so.aaisimulator.utils.TestConstants.PLATFORM_NAME;
29 import static org.onap.so.aaisimulator.utils.TestConstants.VNF_ID;
30 import java.util.List;
31 import java.util.Optional;
32 import org.junit.After;
33 import org.junit.Test;
34 import org.onap.aai.domain.yang.Platform;
35 import org.onap.aai.domain.yang.RelatedToProperty;
36 import org.onap.aai.domain.yang.Relationship;
37 import org.onap.aai.domain.yang.RelationshipData;
38 import org.onap.so.aaisimulator.models.Format;
39 import org.onap.so.aaisimulator.models.Results;
40 import org.onap.so.aaisimulator.service.providers.PlatformCacheServiceProvider;
41 import org.onap.so.aaisimulator.utils.Constants;
42 import org.onap.so.aaisimulator.utils.TestConstants;
43 import org.onap.so.aaisimulator.utils.TestUtils;
44 import org.springframework.beans.factory.annotation.Autowired;
45 import org.springframework.http.HttpStatus;
46 import org.springframework.http.ResponseEntity;
49 * @author Waqas Ikram (waqas.ikram@est.tech)
52 public class PlatformControllerTest extends AbstractSpringBootTest {
55 private PlatformCacheServiceProvider platformCacheServiceProvider;
59 platformCacheServiceProvider.clearAll();
63 public void test_putPlatform_successfullyAddedToCache() throws Exception {
65 final String platformUrl = getUrl(TestConstants.PLATFORMS_URL, PLATFORM_NAME);
66 final ResponseEntity<Void> platformResponse =
67 testRestTemplateService.invokeHttpPut(platformUrl, TestUtils.getPlatform(), Void.class);
68 assertEquals(HttpStatus.ACCEPTED, platformResponse.getStatusCode());
70 final ResponseEntity<Platform> response = testRestTemplateService.invokeHttpGet(platformUrl, Platform.class);
71 assertEquals(HttpStatus.OK, response.getStatusCode());
73 assertTrue(response.hasBody());
75 final Platform actualPlatform = response.getBody();
76 assertEquals(PLATFORM_NAME, actualPlatform.getPlatformName());
77 assertNotNull("resource version should not be null", actualPlatform.getResourceVersion());
82 public void test_getPlatformWithFormatCount() throws Exception {
84 final String platformUrl = getUrl(TestConstants.PLATFORMS_URL, PLATFORM_NAME);
86 final ResponseEntity<Void> platformResponse =
87 testRestTemplateService.invokeHttpPut(platformUrl, TestUtils.getPlatform(), Void.class);
88 assertEquals(HttpStatus.ACCEPTED, platformResponse.getStatusCode());
90 final ResponseEntity<Results> response = testRestTemplateService.invokeHttpGet(
91 platformUrl + "?resultIndex=0&resultSize=1&format=" + Format.COUNT.getValue(), Results.class);
92 assertEquals(HttpStatus.OK, response.getStatusCode());
94 assertTrue(response.hasBody());
96 final Results result = response.getBody();
97 assertNotNull(result.getValues());
98 assertFalse(result.getValues().isEmpty());
99 assertEquals(1, result.getValues().get(0).get(Constants.PLATFORM));
104 public void test_putGenericVnfRelationShipToPlatform_successfullyAddedToCache() throws Exception {
106 final String platformUrl = getUrl(TestConstants.PLATFORMS_URL, PLATFORM_NAME);
107 final ResponseEntity<Void> platformResponse =
108 testRestTemplateService.invokeHttpPut(platformUrl, TestUtils.getPlatform(), Void.class);
109 assertEquals(HttpStatus.ACCEPTED, platformResponse.getStatusCode());
111 final String platformRelationShipUrl =
112 getUrl(TestConstants.PLATFORMS_URL, PLATFORM_NAME, BI_DIRECTIONAL_RELATIONSHIP_LIST_URL);
114 final ResponseEntity<Relationship> responseEntity = testRestTemplateService
115 .invokeHttpPut(platformRelationShipUrl, TestUtils.getGenericVnfRelationShip(), Relationship.class);
116 assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode());
118 final Optional<Platform> optional = platformCacheServiceProvider.getPlatform(PLATFORM_NAME);
119 assertTrue(optional.isPresent());
121 final Platform actual = optional.get();
123 assertNotNull(actual.getRelationshipList());
124 final List<Relationship> relationshipList = actual.getRelationshipList().getRelationship();
125 assertFalse("Relationship list should not be empty", relationshipList.isEmpty());
126 final Relationship relationship = relationshipList.get(0);
128 assertEquals(GENERIC_VNF_URL + VNF_ID, relationship.getRelatedLink());
129 assertFalse("RelationshipData list should not be empty", relationship.getRelationshipData().isEmpty());
130 assertFalse("RelatedToProperty list should not be empty", relationship.getRelatedToProperty().isEmpty());
132 final RelationshipData relationshipData = relationship.getRelationshipData().get(0);
133 assertEquals(Constants.GENERIC_VNF_VNF_ID, relationshipData.getRelationshipKey());
134 assertEquals(TestConstants.VNF_ID, relationshipData.getRelationshipValue());
136 final RelatedToProperty relatedToProperty = relationship.getRelatedToProperty().get(0);
137 assertEquals(Constants.GENERIC_VNF_VNF_NAME, relatedToProperty.getPropertyKey());
138 assertEquals(TestConstants.GENERIC_VNF_NAME, relatedToProperty.getPropertyValue());