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.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;
39 @ExtendWith(SpringExtension.class)
40 @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
41 @ActiveProfiles({ "test", "stub" })
42 class InstantiationControllerStubTest extends CommonRestController {
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 private static final String ROLLBACK = "rollback";
51 private int randomServerPort;
54 public void setUpPort() {
55 super.setHttpPrefix(randomServerPort);
60 var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT
61 + "/" + COMPOSITION_ID
62 + "/" + INSTANTIATION_ENDPOINT);
63 var respPost = invocationBuilder.get();
64 assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus());
69 var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT
70 + "/" + COMPOSITION_ID
71 + "/" + INSTANTIATION_ENDPOINT
73 var respPost = invocationBuilder.get();
74 assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus());
79 var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT
80 + "/" + COMPOSITION_ID
81 + "/" + INSTANTIATION_ENDPOINT
83 var respPost = invocationBuilder.put(Entity.json(new AcInstanceStateUpdate()));
84 assertThat(Response.Status.ACCEPTED.getStatusCode()).isEqualTo(respPost.getStatus());
89 var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT
90 + "/" + COMPOSITION_ID
91 + "/" + INSTANTIATION_ENDPOINT);
92 var respPost = invocationBuilder.post(Entity.json(new AutomationComposition()));
93 assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus());
98 var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT
99 + "/" + COMPOSITION_ID
100 + "/" + INSTANTIATION_ENDPOINT
101 + "/" + INSTANCE_ID);
102 var respPost = invocationBuilder.delete();
103 assertThat(Response.Status.OK.getStatusCode()).isEqualTo(respPost.getStatus());
107 void testRollback() {
108 var invocationBuilder = super.sendRequest(COMMISSIONING_ENDPOINT
109 + "/" + COMPOSITION_ID
110 + "/" + INSTANTIATION_ENDPOINT
113 var respPost = invocationBuilder.post(Entity.json(new AcInstanceStateUpdate()));
114 assertThat(Response.Status.ACCEPTED.getStatusCode()).isEqualTo(respPost.getStatus());