Adding cloud region endpoints
[integration/csit.git] / plans / so / integration-etsi-testing / so-simulators / aai-simulator / src / test / java / org / onap / so / aaisimulator / controller / LinesOfBusinessControllerTest.java
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20 package org.onap.so.aaisimulator.controller;
21
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.TestConstants.LINE_OF_BUSINESS_NAME;
27 import static org.onap.so.aaisimulator.utils.TestConstants.RELATIONSHIP_URL;
28 import java.util.List;
29 import java.util.Optional;
30 import org.junit.After;
31 import org.junit.Test;
32 import org.onap.aai.domain.yang.LineOfBusiness;
33 import org.onap.aai.domain.yang.RelatedToProperty;
34 import org.onap.aai.domain.yang.Relationship;
35 import org.onap.aai.domain.yang.RelationshipData;
36 import org.onap.so.aaisimulator.service.providers.LinesOfBusinessCacheServiceProvider;
37 import org.onap.so.aaisimulator.utils.Constants;
38 import org.onap.so.aaisimulator.utils.TestConstants;
39 import org.onap.so.aaisimulator.utils.TestUtils;
40 import org.springframework.beans.factory.annotation.Autowired;
41 import org.springframework.http.HttpStatus;
42 import org.springframework.http.ResponseEntity;
43
44 /**
45  * @author Waqas Ikram (waqas.ikram@est.tech)
46  *
47  */
48 public class LinesOfBusinessControllerTest extends AbstractSpringBootTest {
49
50     @Autowired
51     private LinesOfBusinessCacheServiceProvider linesOfBusinessCacheServiceProvider;
52
53     @After
54     public void after() {
55         linesOfBusinessCacheServiceProvider.clearAll();
56     }
57
58     @Test
59     public void test_putLineOfBusiness_successfullyAddedToCache() throws Exception {
60
61         final String url = getUrl(Constants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME);
62         final ResponseEntity<Void> lineOfBusinessResponse =
63                 testRestTemplateService.invokeHttpPut(url, TestUtils.getLineOfBusiness(), Void.class);
64         assertEquals(HttpStatus.ACCEPTED, lineOfBusinessResponse.getStatusCode());
65
66         final ResponseEntity<LineOfBusiness> response =
67                 testRestTemplateService.invokeHttpGet(url, LineOfBusiness.class);
68         assertEquals(HttpStatus.OK, response.getStatusCode());
69
70         assertTrue(response.hasBody());
71
72         final LineOfBusiness actualLineOfBusiness = response.getBody();
73         assertEquals(LINE_OF_BUSINESS_NAME, actualLineOfBusiness.getLineOfBusinessName());
74         assertNotNull("resource version should not be null", actualLineOfBusiness.getResourceVersion());
75
76     }
77
78     @Test
79     public void test_putGenericVnfRelationShipToPlatform_successfullyAddedToCache() throws Exception {
80
81         final String url = getUrl(Constants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME);
82         final ResponseEntity<Void> response =
83                 testRestTemplateService.invokeHttpPut(url, TestUtils.getLineOfBusiness(), Void.class);
84         assertEquals(HttpStatus.ACCEPTED, response.getStatusCode());
85
86         final String relationShipUrl = getUrl(Constants.LINES_OF_BUSINESS_URL, LINE_OF_BUSINESS_NAME, RELATIONSHIP_URL);
87
88         final ResponseEntity<Relationship> responseEntity = testRestTemplateService.invokeHttpPut(relationShipUrl,
89                 TestUtils.getGenericVnfRelationShip(), Relationship.class);
90         assertEquals(HttpStatus.ACCEPTED, responseEntity.getStatusCode());
91
92         final Optional<LineOfBusiness> optional =
93                 linesOfBusinessCacheServiceProvider.getLineOfBusiness(LINE_OF_BUSINESS_NAME);
94         assertTrue(optional.isPresent());
95
96         final LineOfBusiness actual = optional.get();
97
98         assertNotNull(actual.getRelationshipList());
99         final List<Relationship> relationshipList = actual.getRelationshipList().getRelationship();
100         assertFalse("Relationship list should not be empty", relationshipList.isEmpty());
101         final Relationship relationship = relationshipList.get(0);
102
103         assertFalse("RelationshipData list should not be empty", relationship.getRelationshipData().isEmpty());
104         assertFalse("RelatedToProperty list should not be empty", relationship.getRelatedToProperty().isEmpty());
105
106         final RelationshipData relationshipData = relationship.getRelationshipData().get(0);
107         assertEquals(Constants.GENERIC_VNF_VNF_ID, relationshipData.getRelationshipKey());
108         assertEquals(TestConstants.VNF_ID, relationshipData.getRelationshipValue());
109
110         final RelatedToProperty relatedToProperty = relationship.getRelatedToProperty().get(0);
111         assertEquals(Constants.GENERIC_VNF_VNF_NAME, relatedToProperty.getPropertyKey());
112         assertEquals(TestConstants.GENERIC_VNF_NAME, relatedToProperty.getPropertyValue());
113
114     }
115
116 }