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.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;
41 * @author waqas.ikram@ericsson.com
44 public class ProjectControllerTest extends AbstractSpringBootTest {
46 private static final String PROJECT_NAME_VALUE = "PROJECT_NAME_VALUE";
52 private TestRestTemplateService testRestTemplateService;
55 private ProjectCacheServiceProvider cacheServiceProvider;
59 cacheServiceProvider.clearAll();
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);
68 assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode());
70 final ResponseEntity<Project> actualResponse = testRestTemplateService.invokeHttpGet(url, Project.class);
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());
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());
87 final String projectRelationshipUrl = getUrl(Constants.PROJECT_URL, PROJECT_NAME_VALUE, RELATIONSHIP_URL);
89 final ResponseEntity<Void> putResponse = testRestTemplateService.invokeHttpPut(projectRelationshipUrl,
90 TestUtils.getBusinessProjectRelationship(), Void.class);
92 assertEquals(HttpStatus.ACCEPTED, putResponse.getStatusCode());
94 final ResponseEntity<Project> actualResponse = testRestTemplateService.invokeHttpGet(url, Project.class);
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));
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);
112 assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode());
114 final ResponseEntity<Results> actualResponse =
115 testRestTemplateService.invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=count", Results.class);
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));