3e1567412a9ea3a12f70eb99be206ac1910edf9d
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / onap / so / bpmn / mock / StubResponseNetworkAdapter.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 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.bpmn.mock;
22
23 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
24 import static com.github.tomakehurst.wiremock.client.WireMock.containing;
25 import static com.github.tomakehurst.wiremock.client.WireMock.delete;
26 import static com.github.tomakehurst.wiremock.client.WireMock.post;
27 import static com.github.tomakehurst.wiremock.client.WireMock.put;
28 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
29
30 import com.github.tomakehurst.wiremock.WireMockServer;
31
32 /**
33  * Please describe the StubResponseNetwork.java class
34  *
35  */
36 public class StubResponseNetworkAdapter {
37
38         private static final String EOL = "\n";
39
40         public static void setupAllMocks() {
41
42         }
43
44
45         public static void MockNetworkAdapter(WireMockServer wireMockServer) {
46                 wireMockServer.stubFor(post(urlEqualTo("/networks/NetworkAdapter"))
47                         .willReturn(aResponse()
48                         .withStatus(200)));
49         }
50
51         public static void MockNetworkAdapter(WireMockServer wireMockServer, String response) {
52                 wireMockServer.stubFor(post(urlEqualTo("/networks/NetworkAdapter"))
53                         .willReturn(aResponse()
54                         .withStatus(200)
55                         .withHeader("Content-Type", "text/xml")
56                         .withBodyFile(response)));
57         }
58
59         public static void MockNetworkAdapter_500(WireMockServer wireMockServer) {
60                 wireMockServer.stubFor(post(urlEqualTo("/networks/NetworkAdapter"))
61                         .willReturn(aResponse()
62                         .withStatus(500)));
63         }
64
65         public static void MockNetworkAdapterPost(WireMockServer wireMockServer, String responseFile, String requestContaining) {
66                 wireMockServer.stubFor(post(urlEqualTo("/networks/NetworkAdapter"))
67                         .withRequestBody(containing(requestContaining))                         
68                         .willReturn(aResponse()
69                         .withStatus(200)
70                         .withHeader("Content-Type", "text/xml")
71                         .withBodyFile(responseFile)));
72         }       
73         
74         public static void MockNetworkAdapter(WireMockServer wireMockServer, String networkId, int statusCode, String responseFile) {
75                 wireMockServer.stubFor(delete(urlEqualTo("/networks/NetworkAdapter/" + networkId))
76                                   .willReturn(aResponse()
77                                   .withStatus(statusCode)
78                                   .withHeader("Content-Type", "application/xml")
79                                   .withBodyFile(responseFile)));
80         }
81         
82         public static void MockNetworkAdapterContainingRequest(WireMockServer wireMockServer, String requestContaining, int statusCode, String responseFile) {
83                 wireMockServer.stubFor(post(urlEqualTo("/networks/NetworkAdapter"))
84                                   .withRequestBody(containing(requestContaining))
85                                   .willReturn(aResponse()
86                                   .withStatus(statusCode)
87                                   .withHeader("Content-Type", "text/xml")
88                                   .withBodyFile(responseFile)));
89         }
90         
91         public static void MockPutNetworkAdapter(WireMockServer wireMockServer, String networkId, String requestContaining, int statusCode, String responseFile) {
92                 wireMockServer.stubFor(put(urlEqualTo("/networks/NetworkAdapter/" + networkId))
93                                   .withRequestBody(containing(requestContaining))
94                                   .willReturn(aResponse()
95                                   .withStatus(statusCode)
96                                   .withHeader("Content-Type", "text/xml")
97                                   .withBodyFile(responseFile)));
98         }
99         
100         public static void MockNetworkAdapterRestRollbackDelete(WireMockServer wireMockServer, String responseFile, String networkId) {
101                 wireMockServer.stubFor(delete(urlEqualTo("/networks/NetworkAdapter/"+networkId+"/rollback"))
102                         .willReturn(aResponse()
103                         .withStatus(200)
104                         .withHeader("Content-Type", "text/xml")
105                         .withBodyFile(responseFile)));
106         }       
107
108         public static void MockNetworkAdapterRestPut(WireMockServer wireMockServer, String responseFile, String networkId) {
109                 wireMockServer.stubFor(put(urlEqualTo("/networks/NetworkAdapter/"+networkId))
110                         .willReturn(aResponse()
111                         .withStatus(200)
112                         .withHeader("Content-Type", "text/xml")
113                         .withBodyFile(responseFile)));
114         }               
115         
116 }