3 * Copyright (c) 2022. Deutsche Telekom AG
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
22 package org.onap.portalng.preferences.preferences;
24 import static org.assertj.core.api.Assertions.assertThat;
26 import org.junit.jupiter.api.Test;
27 import org.onap.portalng.preferences.BaseIntegrationTest;
28 import org.onap.portalng.preferences.openapi.model.PreferencesApiDto;
29 import org.onap.portalng.preferences.services.PreferencesService;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.http.HttpStatus;
32 import org.springframework.http.MediaType;
34 import io.restassured.http.ContentType;
36 class PreferencesControllerIntegrationTest extends BaseIntegrationTest {
39 PreferencesService preferencesService;
42 void thatUserPreferencesCanBeRetrieved() {
43 // First save a user preference before a GET can run
44 PreferencesApiDto expectedResponse = new PreferencesApiDto()
45 .properties("{\"properties\": {\"dashboard\": {\"key1:\": \"value2\"}, \"appStarter\": \"value1\"}}");
47 .savePreferences("test-user", expectedResponse)
50 PreferencesApiDto actualResponse = requestSpecification("test-user")
52 .accept(MediaType.APPLICATION_JSON_VALUE)
54 .get("/v1/preferences")
56 .statusCode(HttpStatus.OK.value())
59 .as(PreferencesApiDto.class);
61 assertThat(actualResponse).isNotNull();
62 assertThat(actualResponse.getProperties()).isEqualTo(expectedResponse.getProperties());
66 void thatUserPreferencesCanNotBeRetrieved() {
67 unauthenticatedRequestSpecification()
69 .accept(MediaType.APPLICATION_JSON_VALUE)
70 .contentType(ContentType.JSON)
72 .get("/v1/preferences")
74 .statusCode(HttpStatus.UNAUTHORIZED.value());
78 void thatUserPreferencesCanBeSaved() {
79 PreferencesApiDto expectedResponse = new PreferencesApiDto()
82 "properties": { "appStarter": "value1",
83 "dashboard": {"key1:" : "value2"}
87 PreferencesApiDto actualResponse = requestSpecification()
89 .accept(MediaType.APPLICATION_JSON_VALUE)
90 .contentType(ContentType.JSON)
91 .body(expectedResponse)
93 .post("/v1/preferences")
95 .statusCode(HttpStatus.OK.value())
98 .as(PreferencesApiDto.class);
100 assertThat(actualResponse).isNotNull();
101 assertThat(actualResponse.getProperties()).isEqualTo(expectedResponse.getProperties());
105 void thatUserPreferencesCanBeUpdated() {
106 // First save a user preference before a GET can run
107 PreferencesApiDto initialPreferences = new PreferencesApiDto()
110 "properties": { "appStarter": "value1",
111 "dashboard": {"key1:" : "value2"}
116 .savePreferences("test-user", initialPreferences)
119 PreferencesApiDto expectedResponse = new PreferencesApiDto()
122 "properties": { "appStarter": "value3",
123 "dashboard": {"key2:" : "value4"}
127 PreferencesApiDto actualResponse = requestSpecification("test-user")
129 .accept(MediaType.APPLICATION_JSON_VALUE)
130 .contentType(ContentType.JSON)
131 .body(expectedResponse)
133 .put("/v1/preferences")
135 .statusCode(HttpStatus.OK.value())
138 .as(PreferencesApiDto.class);
140 assertThat(actualResponse).isNotNull();
141 assertThat(actualResponse.getProperties()).isEqualTo(expectedResponse.getProperties());
145 void thatUserPreferencesCanNotBeFound() {
147 PreferencesApiDto actualResponse = requestSpecification("test-canNotBeFound")
149 .accept(MediaType.APPLICATION_JSON_VALUE)
151 .get("/v1/preferences")
153 .statusCode(HttpStatus.OK.value())
156 .as(PreferencesApiDto.class);
158 assertThat(actualResponse).isNotNull();
159 assertThat(actualResponse.getProperties()).isNull();