2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.so.adapters.valet;
23 import static com.shazam.shazamcrest.MatcherAssert.assertThat;
24 import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs;
25 import static org.onap.so.bpmn.mock.StubOpenStack.mockValetConfirmPutRequest_200;
26 import static org.onap.so.bpmn.mock.StubOpenStack.mockValetCreatePostResponse_200;
27 import static org.onap.so.bpmn.mock.StubOpenStack.mockValetCreatePutResponse_200;
28 import static org.onap.so.bpmn.mock.StubOpenStack.mockValetDeleteDeleteResponse_200;
29 import static org.onap.so.bpmn.mock.StubOpenStack.mockValetRollbackPutRequest_200;
33 import org.apache.http.HttpStatus;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.onap.so.adapters.valet.beans.ValetConfirmResponse;
37 import org.onap.so.adapters.valet.beans.ValetCreateResponse;
38 import org.onap.so.adapters.valet.beans.ValetDeleteResponse;
39 import org.onap.so.adapters.valet.beans.ValetRollbackResponse;
40 import org.onap.so.adapters.valet.beans.ValetUpdateResponse;
41 import org.onap.so.adapters.vnf.BaseRestTestUtils;
42 import org.springframework.beans.factory.annotation.Autowired;
44 import com.fasterxml.jackson.databind.ObjectMapper;
46 public class ValetClientTest extends BaseRestTestUtils {
48 protected ValetClient client;
50 private ObjectMapper mapper = new ObjectMapper();
54 client.baseUrl = "http://localhost:" + wireMockPort;
58 public void testCallValetCreateRequest() throws Exception {
59 ValetCreateResponse vcr = mapper.readValue(new File("src/test/resources/__files/ValetCreateRequest.json"), ValetCreateResponse.class);
60 GenericValetResponse<ValetCreateResponse> expected = new GenericValetResponse<ValetCreateResponse>(HttpStatus.SC_OK, ValetClient.NO_STATUS_RETURNED, vcr);
62 mockValetCreatePostResponse_200("requestId", mapper.writeValueAsString(vcr));
64 GenericValetResponse<ValetCreateResponse> actual = client.callValetCreateRequest("requestId", "regionId", "tenantId", "serviceInstanceId", "vnfId", "vnfName", "vfModuleId", "vfModuleName", "keystoneUrl", null);
66 assertThat(actual, sameBeanAs(expected));
70 public void testCallValetUpdateRequest() throws Exception {
71 ValetUpdateResponse vur = mapper.readValue(new File("src/test/resources/__files/ValetCreateRequest.json"), ValetUpdateResponse.class);
72 GenericValetResponse<ValetUpdateResponse> expected = new GenericValetResponse<ValetUpdateResponse>(HttpStatus.SC_OK, ValetClient.NO_STATUS_RETURNED, vur);
74 mockValetCreatePutResponse_200("requestId", mapper.writeValueAsString(vur));
76 GenericValetResponse<ValetUpdateResponse> actual = client.callValetUpdateRequest("requestId", "regionId", "tenantId", "serviceInstanceId", "vnfId", "vnfName", "vfModuleId", "vfModuleName", "keystoneUrl", null);
78 assertThat(actual, sameBeanAs(expected));
82 public void testCallValetDeleteRequest() throws Exception {
83 ValetDeleteResponse vdr = mapper.readValue(new File("src/test/resources/__files/ValetDeleteRequest.json"), ValetDeleteResponse.class);
84 GenericValetResponse<ValetDeleteResponse> expected = new GenericValetResponse<ValetDeleteResponse>(HttpStatus.SC_OK, ValetClient.NO_STATUS_RETURNED, vdr);
86 mockValetDeleteDeleteResponse_200("requestId", mapper.writeValueAsString(vdr));
88 GenericValetResponse<ValetDeleteResponse> actual = client.callValetDeleteRequest("requestId", "regionId", "tenantId", "vfModuleId", "vfModuleName");
90 assertThat(actual, sameBeanAs(expected));
94 public void testCallValetConfirmRequest() throws Exception {
95 ValetConfirmResponse vcr = new ValetConfirmResponse();
96 GenericValetResponse<ValetConfirmResponse> expected = new GenericValetResponse<ValetConfirmResponse>(HttpStatus.SC_OK, ValetClient.NO_STATUS_RETURNED, vcr);
98 mockValetConfirmPutRequest_200("requestId", "{}");
100 GenericValetResponse<ValetConfirmResponse> actual = client.callValetConfirmRequest("requestId", "stackId");
102 assertThat(actual, sameBeanAs(expected));
106 public void testCallValetRollbackRequest() throws Exception {
107 ValetRollbackResponse vrr = new ValetRollbackResponse();
108 GenericValetResponse<ValetRollbackResponse> expected = new GenericValetResponse<ValetRollbackResponse>(HttpStatus.SC_OK, ValetClient.NO_STATUS_RETURNED, vrr);
110 mockValetRollbackPutRequest_200("requestId", "{}");
112 GenericValetResponse<ValetRollbackResponse> actual = client.callValetRollbackRequest("requestId", "stackId", true, "error");
114 assertThat(actual, sameBeanAs(expected));