replace all fixed wiremock ports
[so.git] / adapters / mso-openstack-adapters / src / test / java / org / onap / so / adapters / valet / ValetClientTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.onap.so.adapters.valet;
22
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;
30
31 import java.io.File;
32
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;
43
44 import com.fasterxml.jackson.databind.ObjectMapper;
45
46 public class ValetClientTest extends BaseRestTestUtils {
47         @Autowired
48         protected ValetClient client;
49         
50         private ObjectMapper mapper = new ObjectMapper();
51
52         @Before
53         public void init() {
54                 client.baseUrl = "http://localhost:" + wireMockPort;
55         }
56         
57         @Test
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);
61                 
62                 mockValetCreatePostResponse_200(wireMockServer, "requestId", mapper.writeValueAsString(vcr));
63                 
64                 GenericValetResponse<ValetCreateResponse> actual = client.callValetCreateRequest("requestId", "regionId", "ownerId", "tenantId", "serviceInstanceId", "vnfId", "vnfName", "vfModuleId", "vfModuleName", "keystoneUrl", null);
65
66                 assertThat(actual, sameBeanAs(expected));
67         }
68         
69         @Test
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);
73                 
74                 mockValetCreatePutResponse_200(wireMockServer, "requestId", mapper.writeValueAsString(vur));
75                 
76                 GenericValetResponse<ValetUpdateResponse> actual = client.callValetUpdateRequest("requestId", "regionId", "ownerId", "tenantId", "serviceInstanceId", "vnfId", "vnfName", "vfModuleId", "vfModuleName", "keystoneUrl", null);
77
78                 assertThat(actual, sameBeanAs(expected));
79         }
80         
81         @Test
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);
85                 
86                 mockValetDeleteDeleteResponse_200(wireMockServer, "requestId", mapper.writeValueAsString(vdr));
87                 
88                 GenericValetResponse<ValetDeleteResponse> actual = client.callValetDeleteRequest("requestId", "regionId", "ownerId", "tenantId", "vfModuleId", "vfModuleName");
89
90                 assertThat(actual, sameBeanAs(expected));
91         }
92         
93         @Test
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);
97                 
98                 mockValetConfirmPutRequest_200(wireMockServer, "requestId", "{}");
99                 
100                 GenericValetResponse<ValetConfirmResponse> actual = client.callValetConfirmRequest("requestId", "stackId");
101
102                 assertThat(actual, sameBeanAs(expected));
103         }
104         
105         @Test
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);
109                 
110                 mockValetRollbackPutRequest_200(wireMockServer, "requestId", "{}");
111                 
112                 GenericValetResponse<ValetRollbackResponse> actual = client.callValetRollbackRequest("requestId", "stackId", true, "error");
113
114                 assertThat(actual, sameBeanAs(expected));
115         }
116 }