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
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
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.clamp.acm.runtime.contract;
23 import static org.assertj.core.api.Assertions.assertThat;
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.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;
38 @ExtendWith(SpringExtension.class)
39 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
40 @ActiveProfiles({ "test", "stub" })
41 class CommissioningControllerStubTest extends CommonRestController {
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();
48 private int randomServerPort;
51 public void setUpPort() {
52 super.setHttpPrefix(randomServerPort);
57 var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT);
58 var respPost = invocationBuilder.get();
59 assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus());
64 var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/" + COMPOSITION_ID);
65 var respPost = invocationBuilder.get();
66 assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus());
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());
78 var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT);
79 var respPost = invocationBuilder.post(Entity.json(serviceTemplate));
80 assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus());
85 var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT + "/" + COMPOSITION_ID);
86 var respPost = invocationBuilder.delete();
87 assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus());