2 * ============LICENSE_START=======================================================
3 * dcaegen2-collectors-veshv
4 * ================================================================================
5 * Copyright (C) 2018 NOKIA
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
20 package org.onap.dcae.collectors.veshv.utils.http
22 import org.assertj.core.api.Assertions.assertThat
23 import org.jetbrains.spek.api.Spek
24 import org.jetbrains.spek.api.dsl.describe
25 import org.jetbrains.spek.api.dsl.given
26 import org.jetbrains.spek.api.dsl.it
27 import org.jetbrains.spek.api.dsl.on
29 import javax.json.JsonObject
32 * @author Piotr Jaszczyk <piotr.jaszczyk@nokia.com>
33 * @since September 2018
35 internal class ResponsesTest : Spek({
36 describe("response factory") {
37 describe("accepted response") {
39 val uuid = UUID.randomUUID()
41 on("calling acceptedResponse") {
42 val result = Responses.acceptedResponse(uuid)
44 it ("should have ACCEPTED status") {
45 assertThat(result.status).isEqualTo(HttpStatus.ACCEPTED)
48 it ("should have text body") {
49 assertThat(result.content.type).isEqualTo(ContentType.TEXT)
52 it ("should contain UUID text in the body") {
53 val serialized = result.content.serializer.run { result.content.value.show() }
54 assertThat(serialized).isEqualTo(uuid.toString())
59 describe("status response") {
60 given("all params are specified") {
62 val message = "good job"
63 val httpStatus = HttpStatus.OK
65 on("calling statusResponse") {
66 val result = Responses.statusResponse(status, message, httpStatus)
67 val json = result.content.value as JsonObject
69 it ("should have OK status") {
70 assertThat(result.status).isEqualTo(HttpStatus.OK)
73 it ("should have json body") {
74 assertThat(result.content.type).isEqualTo(ContentType.JSON)
77 it ("should contain status as string") {
78 assertThat(json.getString("status")).isEqualTo(status)
81 it ("should contain message") {
82 assertThat(json.getString("message")).isEqualTo(message)
87 given("default params are omitted") {
89 val message = "good job"
91 on("calling statusResponse") {
92 val result = Responses.statusResponse(status, message)
94 it ("should have OK status") {
95 assertThat(result.status).isEqualTo(HttpStatus.OK)