2c72a82998825ba175571d424f37f6f31a4ccc66
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2022-2023 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
21 package org.onap.policy.clamp.acm.runtime.contract;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24
25 import javax.ws.rs.client.Entity;
26 import javax.ws.rs.core.Response;
27 import org.junit.jupiter.api.BeforeEach;
28 import org.junit.jupiter.api.Test;
29 import org.junit.jupiter.api.extension.ExtendWith;
30 import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController;
31 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
32 import org.springframework.boot.test.context.SpringBootTest;
33 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
34 import org.springframework.boot.test.web.server.LocalServerPort;
35 import org.springframework.test.context.ActiveProfiles;
36 import org.springframework.test.context.junit.jupiter.SpringExtension;
37
38 @ExtendWith(SpringExtension.class)
39 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
40 @ActiveProfiles({ "test", "stub" })
41 class CommissioningControllerStubTest extends CommonRestController {
42
43     private static final String COMMISSIONING_ENDPOINT = "compositions";
44     private static final String COMPOSITION_ID = "1aeed185-a98b-45b6-af22-8d5d20485ea3";
45     private static ToscaServiceTemplate serviceTemplate = new ToscaServiceTemplate();
46
47     @LocalServerPort
48     private int randomServerPort;
49
50     @BeforeEach
51     public void setUpPort() {
52         super.setHttpPrefix(randomServerPort);
53     }
54
55     @Test
56     void testQuery() {
57         var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT);
58         var respPost = invocationBuilder.get();
59         assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus());
60     }
61
62     @Test
63     void testGet() {
64         var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/" + COMPOSITION_ID);
65         var respPost = invocationBuilder.get();
66         assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus());
67     }
68
69     @Test
70     void testPut() {
71         var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/" + COMPOSITION_ID);
72         var respPost = invocationBuilder.put(Entity.json(serviceTemplate));
73         assertThat(Response.Status.ACCEPTED.getStatusCode()).isEqualTo(respPost.getStatus());
74     }
75
76     @Test
77     void testPost() {
78         var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT);
79         var respPost = invocationBuilder.post(Entity.json(serviceTemplate));
80         assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus());
81     }
82
83     @Test
84     void testDelete() {
85         var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/" + COMPOSITION_ID);
86         var respPost = invocationBuilder.delete();
87         assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus());
88     }
89 }