f0cd359c6a3276908a5e6e7e0d37a8b4b2860131
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 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.MediaType;
27 import javax.ws.rs.core.Response;
28 import org.junit.jupiter.api.BeforeEach;
29 import org.junit.jupiter.api.Test;
30 import org.junit.jupiter.api.extension.ExtendWith;
31 import org.onap.policy.clamp.acm.runtime.util.rest.CommonRestController;
32 import org.springframework.boot.test.context.SpringBootTest;
33 import org.springframework.boot.test.web.server.LocalServerPort;
34 import org.springframework.test.context.ActiveProfiles;
35 import org.springframework.test.context.junit.jupiter.SpringExtension;
36
37 @ExtendWith(SpringExtension.class)
38 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
39 @ActiveProfiles({ "test", "stub" })
40 public class ParticipantControllerStubTest extends CommonRestController {
41     private static final String PARTICIPANT_ENDPOINT = "participants";
42     private static final String PARTICIPANT_ID = "101c62b3-8918-41b9-a747-d21eb79c6c03";
43
44     @LocalServerPort
45     private int randomServerPort;
46
47     @BeforeEach
48     public void setUpPort() {
49         super.setHttpPrefix(randomServerPort);
50     }
51
52     @Test
53     void testGet() {
54         var invocationBuilder = super.sendRequest(PARTICIPANT_ENDPOINT + "/" + PARTICIPANT_ID);
55         var respPost = invocationBuilder.get();
56         assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus());
57     }
58
59     @Test
60     void testQuery() {
61         var invocationBuilder = super.sendRequest(PARTICIPANT_ENDPOINT);
62         var respPost = invocationBuilder.get();
63         assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus());
64     }
65
66     @Test
67     void testOrderReport() {
68         var invocationBuilder = super.sendRequest(PARTICIPANT_ENDPOINT + "/" + PARTICIPANT_ID);
69
70         var respPost = invocationBuilder.header("Content-Length", 0).put(Entity.entity(""
71             + "", MediaType.APPLICATION_JSON));
72         assertThat(Response.Status.ACCEPTED.getStatusCode()).isEqualTo(respPost.getStatus());
73     }
74
75     @Test
76     void testOrderAllReport() {
77         var invocationBuilder = super.sendRequest(PARTICIPANT_ENDPOINT);
78
79         var respPost = invocationBuilder.header("Content-Length", 0).put(Entity.entity(""
80             + "", MediaType.APPLICATION_JSON));
81         assertThat(Response.Status.ACCEPTED.getStatusCode()).isEqualTo(respPost.getStatus());
82     }
83 }