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.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.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL;
27 import static org.onap.aaisimulator.utils.TestConstants.GENERIC_VNF_URL;
28 import static org.onap.aaisimulator.utils.TestConstants.LINE_OF_BUSINESS_NAME;
29 import static org.onap.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.LineOfBusiness;
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.aaisimulator.models.Format;
39 import org.onap.aaisimulator.models.Results;
40 import org.onap.aaisimulator.service.providers.LinesOfBusinessCacheServiceProvider;
41 import org.onap.aaisimulator.utils.Constants;
42 import org.onap.aaisimulator.utils.TestConstants;
43 import org.onap.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 LinesOfBusinessControllerTest extends AbstractSpringBootTest {
55 private LinesOfBusinessCacheServiceProvider linesOfBusinessCacheServiceProvider;
59 linesOfBusinessCacheServiceProvider.clearAll();
63 public void test_putLineOfBusiness_successfullyAddedToCache() throws Exception {
65 final String url = getUrl(TestConstants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME);
66 final ResponseEntity<Void> lineOfBusinessResponse =
67 testRestTemplateService.invokeHttpPut(url, TestUtils.getLineOfBusiness(), Void.class);
68 assertEquals(HttpStatus.ACCEPTED, lineOfBusinessResponse.getStatusCode());
70 final ResponseEntity<LineOfBusiness> response =
71 testRestTemplateService.invokeHttpGet(url, LineOfBusiness.class);
72 assertEquals(HttpStatus.OK, response.getStatusCode());
74 assertTrue(response.hasBody());
76 final LineOfBusiness actualLineOfBusiness = response.getBody();
77 assertEquals(LINE_OF_BUSINESS_NAME, actualLineOfBusiness.getLineOfBusinessName());
78 assertNotNull("resource version should not be null", actualLineOfBusiness.getResourceVersion());
83 public void test_getLineOfBusinessWithFormatCount() throws Exception {
85 final String url = getUrl(TestConstants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME);
86 final ResponseEntity<Void> lineOfBusinessResponse =
87 testRestTemplateService.invokeHttpPut(url, TestUtils.getLineOfBusiness(), Void.class);
88 assertEquals(HttpStatus.ACCEPTED, lineOfBusinessResponse.getStatusCode());
90 final ResponseEntity<Results> response = testRestTemplateService
91 .invokeHttpGet(url + "?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.LINE_OF_BUSINESS));
104 public void test_putGenericVnfRelationShipToPlatform_successfullyAddedToCache() throws Exception {
106 final String url = getUrl(TestConstants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME);
107 final ResponseEntity<Void> response =
108 testRestTemplateService.invokeHttpPut(url, TestUtils.getLineOfBusiness(), Void.class);
109 assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
111 final String relationShipUrl = getUrl(TestConstants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME,
112 BI_DIRECTIONAL_RELATIONSHIP_LIST_URL);
114 final ResponseEntity<Relationship> responseEntity = testRestTemplateService.invokeHttpPut(relationShipUrl,
115 TestUtils.getGenericVnfRelationShip(), Relationship.class);
116 assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode());
118 final Optional<LineOfBusiness> optional =
119 linesOfBusinessCacheServiceProvider.getLineOfBusiness(LINE_OF_BUSINESS_NAME);
120 assertTrue(optional.isPresent());
122 final LineOfBusiness actual = optional.get();
124 assertNotNull(actual.getRelationshipList());
125 final List<Relationship> relationshipList = actual.getRelationshipList().getRelationship();
126 assertFalse("Relationship list should not be empty", relationshipList.isEmpty());
127 final Relationship relationship = relationshipList.get(0);
129 assertEquals(GENERIC_VNF_URL + VNF_ID, relationship.getRelatedLink());
130 assertFalse("RelationshipData list should not be empty", relationship.getRelationshipData().isEmpty());
131 assertFalse("RelatedToProperty list should not be empty", relationship.getRelatedToProperty().isEmpty());
133 final RelationshipData relationshipData = relationship.getRelationshipData().get(0);
134 assertEquals(Constants.GENERIC_VNF_VNF_ID, relationshipData.getRelationshipKey());
135 assertEquals(TestConstants.VNF_ID, relationshipData.getRelationshipValue());
137 final RelatedToProperty relatedToProperty = relationship.getRelatedToProperty().get(0);
138 assertEquals(Constants.GENERIC_VNF_VNF_NAME, relatedToProperty.getPropertyKey());
139 assertEquals(TestConstants.GENERIC_VNF_NAME, relatedToProperty.getPropertyValue());