52dbcf8ac7401be287f7cd91acf34504f1ba07e0
[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 jakarta.ws.rs.client.Entity;
26 import jakarta.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.clamp.models.acm.concepts.AutomationComposition;
32 import org.onap.policy.clamp.models.acm.messages.rest.instantiation.AcInstanceStateUpdate;
33 import org.springframework.boot.test.context.SpringBootTest;
34 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
35 import org.springframework.boot.test.web.server.LocalServerPort;
36 import org.springframework.test.context.ActiveProfiles;
37 import org.springframework.test.context.junit.jupiter.SpringExtension;
38
39 @ExtendWith(SpringExtension.class)
40 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
41 @ActiveProfiles({ "test", "stub" })
42 class InstantiationControllerStubTest extends CommonRestController {
43
44     private static final String COMMISSIONING_ENDPOINT = "compositions";
45     private static final String INSTANTIATION_ENDPOINT = "instances";
46     private static final String COMPOSITION_ID = "1aeed185-a98b-45b6-af22-8d5d20485ea3";
47     private static final String INSTANCE_ID = "709c62b3-8918-41b9-a747-d21eb79c6c23";
48
49     @LocalServerPort
50     private int randomServerPort;
51
52     @BeforeEach
53     public void setUpPort() {
54         super.setHttpPrefix(randomServerPort);
55     }
56
57     @Test
58     void testQuery() {
59         var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT
60                 + "/" + COMPOSITION_ID
61                 + "/" + INSTANTIATION_ENDPOINT);
62         var respPost = invocationBuilder.get();
63         assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus());
64     }
65
66     @Test
67     void testGet() {
68         var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT
69                 + "/" + COMPOSITION_ID
70                 + "/" + INSTANTIATION_ENDPOINT
71                 + "/" + INSTANCE_ID);
72         var respPost = invocationBuilder.get();
73         assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus());
74     }
75
76     @Test
77     void testPut() {
78         var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT
79                 + "/" + COMPOSITION_ID
80                 + "/" + INSTANTIATION_ENDPOINT
81                 + "/" + INSTANCE_ID);
82         var respPost = invocationBuilder.put(Entity.json(new AcInstanceStateUpdate()));
83         assertThat(Response.Status.ACCEPTED.getStatusCode()).isEqualTo(respPost.getStatus());
84     }
85
86     @Test
87     void testPost() {
88         var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT
89                 + "/" + COMPOSITION_ID
90                 + "/" + INSTANTIATION_ENDPOINT);
91         var respPost = invocationBuilder.post(Entity.json(new AutomationComposition()));
92         assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus());
93     }
94
95     @Test
96     void testDelete() {
97         var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT
98                 + "/" + COMPOSITION_ID
99                 + "/" + INSTANTIATION_ENDPOINT
100                 + "/" + INSTANCE_ID);
101         var respPost = invocationBuilder.delete();
102         assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus());
103     }
104 }