Adding cloud region endpoints
[integration/csit.git] / plans / so / integration-etsi-testing / so-simulators / aai-simulator / src / test / java / org / onap / so / aaisimulator / controller / ProjectControllerTest.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.RELATIONSHIP_URL;
27 import org.junit.After;
28 import org.junit.Test;
29 import org.onap.aai.domain.yang.Project;
30 import org.onap.so.aaisimulator.models.Results;
31 import org.onap.so.aaisimulator.service.providers.ProjectCacheServiceProvider;
32 import org.onap.so.aaisimulator.utils.Constants;
33 import org.onap.so.aaisimulator.utils.TestRestTemplateService;
34 import org.onap.so.aaisimulator.utils.TestUtils;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.boot.web.server.LocalServerPort;
37 import org.springframework.http.HttpStatus;
38 import org.springframework.http.ResponseEntity;
39
40 /**
41  * @author waqas.ikram@ericsson.com
42  *
43  */
44 public class ProjectControllerTest extends AbstractSpringBootTest {
45
46     private static final String PROJECT_NAME_VALUE = "PROJECT_NAME_VALUE";
47
48     @LocalServerPort
49     private int port;
50
51     @Autowired
52     private TestRestTemplateService testRestTemplateService;
53
54     @Autowired
55     private ProjectCacheServiceProvider cacheServiceProvider;
56
57     @After
58     public void after() {
59         cacheServiceProvider.clearAll();
60     }
61
62     @Test
63     public void test_putProject_successfullyAddedToCache() throws Exception {
64         final String url = getUrl(Constants.PROJECT_URL, PROJECT_NAME_VALUE);
65         final ResponseEntity<Void> actual =
66                 testRestTemplateService.invokeHttpPut(url, TestUtils.getBusinessProject(), Void.class);
67
68         assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode());
69
70         final ResponseEntity<Project> actualResponse = testRestTemplateService.invokeHttpGet(url, Project.class);
71
72         assertEquals(HttpStatus.OK, actualResponse.getStatusCode());
73         assertTrue(actualResponse.hasBody());
74         final Project actualProject = actualResponse.getBody();
75         assertEquals(PROJECT_NAME_VALUE, actualProject.getProjectName());
76         assertNotNull(actualProject.getResourceVersion());
77
78     }
79
80     @Test
81     public void test_putProjectRelationShip_successfullyAddedToCache() throws Exception {
82         final String url = getUrl(Constants.PROJECT_URL, PROJECT_NAME_VALUE);
83         final ResponseEntity<Void> actual =
84                 testRestTemplateService.invokeHttpPut(url, TestUtils.getBusinessProject(), Void.class);
85         assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode());
86
87         final String projectRelationshipUrl = getUrl(Constants.PROJECT_URL, PROJECT_NAME_VALUE, RELATIONSHIP_URL);
88
89         final ResponseEntity<Void> putResponse = testRestTemplateService.invokeHttpPut(projectRelationshipUrl,
90                 TestUtils.getBusinessProjectRelationship(), Void.class);
91
92         assertEquals(HttpStatus.ACCEPTED, putResponse.getStatusCode());
93
94         final ResponseEntity<Project> actualResponse = testRestTemplateService.invokeHttpGet(url, Project.class);
95
96         assertEquals(HttpStatus.OK, actualResponse.getStatusCode());
97         assertTrue(actualResponse.hasBody());
98         final Project actualProject = actualResponse.getBody();
99         assertEquals(PROJECT_NAME_VALUE, actualProject.getProjectName());
100         assertNotNull(actualProject.getRelationshipList());
101         assertFalse(actualProject.getRelationshipList().getRelationship().isEmpty());
102         assertNotNull(actualProject.getRelationshipList().getRelationship().get(0));
103
104     }
105
106     @Test
107     public void test_getProjectCount_correctResult() throws Exception {
108         final String url = getUrl(Constants.PROJECT_URL, PROJECT_NAME_VALUE);
109         final ResponseEntity<Void> actual =
110                 testRestTemplateService.invokeHttpPut(url, TestUtils.getBusinessProject(), Void.class);
111
112         assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode());
113
114         final ResponseEntity<Results> actualResponse =
115                 testRestTemplateService.invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=count", Results.class);
116
117         assertEquals(HttpStatus.OK, actualResponse.getStatusCode());
118         assertTrue(actualResponse.hasBody());
119         final Results result = actualResponse.getBody();
120         assertNotNull(result.getValues());
121         assertFalse(result.getValues().isEmpty());
122         assertEquals(1, result.getValues().get(0).get(Constants.PROJECT));
123     }
124
125 }