8fd745d76598b23843d5f31d721326b710abdccd
[so.git] / bpmn / MSOCommonBPMN / src / test / java / org / onap / so / bpmn / mock / StubResponseDatabase.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.get;
25 import static com.github.tomakehurst.wiremock.client.WireMock.post;
26 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
27
28 import com.github.tomakehurst.wiremock.WireMockServer;
29
30 /**
31  * Stub response class for Database stubs
32  * including database adapter, catalog db,
33  * and other databases.
34  */
35 public class StubResponseDatabase {
36
37         public static void setupAllMocks() {
38
39         }
40
41         public static void MockUpdateRequestDB(WireMockServer wireMockServer, String fileName){
42                 wireMockServer.stubFor(post(urlEqualTo("/services/RequestsDbAdapter"))
43                                 .willReturn(aResponse()
44                                 .withStatus(200)
45                             .withHeader("Content-Type", "text/xml")
46                                 .withBodyFile(fileName)));
47         }       
48         
49         public static void mockUpdateRequestDB(WireMockServer wireMockServer, int statusCode, String reponseFile) {
50                 wireMockServer.stubFor(post(urlEqualTo("/services/RequestsDbAdapter"))
51                                 .willReturn(aResponse()
52                                 .withStatus(statusCode)
53                             .withHeader("Content-Type", "text/xml")
54                                 .withBodyFile(reponseFile)));
55         }
56
57         public static void MockGetAllottedResourcesByModelInvariantId(WireMockServer wireMockServer, String modelInvariantId, String responseFile){
58                 wireMockServer.stubFor(get(urlEqualTo("/v1/serviceAllottedResources?serviceModelInvariantUuid=" + modelInvariantId))
59                                 .willReturn(aResponse()
60                                 .withStatus(200)
61                             .withHeader("Content-Type", "application/json")
62                                 .withBodyFile(responseFile)));
63         }
64
65         public static void MockGetAllottedResourcesByModelInvariantId_500(WireMockServer wireMockServer, String modelInvariantId, String responseFile){
66                 wireMockServer.stubFor(get(urlEqualTo("/v1/serviceAllottedResources?serviceModelInvariantUuid=" + modelInvariantId))
67                                 .willReturn(aResponse()
68                                 .withStatus(500)));
69         }
70         
71         public static void MockGetVnfCatalogDataCustomizationUuid(WireMockServer wireMockServer, String vnfModelCustomizationUuid,  String responseFile){
72                 wireMockServer.stubFor(get(urlEqualTo("/v2/serviceVnfs?vnfModelCustomizationUuid=" + vnfModelCustomizationUuid))
73                                   .willReturn(aResponse()
74                                   .withStatus(200)
75                                   .withHeader("Content-Type", "application/json")
76                                   .withBodyFile(responseFile)));
77         }
78
79         public static void MockGetVfModuleByModelNameCatalogData(WireMockServer wireMockServer, String vfModuleModelName, String responseFile){
80                 wireMockServer.stubFor(get(urlEqualTo("/v2/vfModules?vfModuleModelName=" + vfModuleModelName))
81                                   .willReturn(aResponse()
82                                   .withStatus(200)
83                                   .withHeader("Content-Type", "application/json")
84                                   .withBodyFile(responseFile)));
85         }
86         
87         public static void MockGetServiceResourcesCatalogData(WireMockServer wireMockServer, String serviceModelInvariantUuid, String serviceModelVersion, String responseFile){
88                 wireMockServer.stubFor(get(urlEqualTo("/ecomp/mso/catalog/v2/serviceResources?serviceModelInvariantUuid=" +
89                                 serviceModelInvariantUuid + 
90                                 "&serviceModelVersion=" + serviceModelVersion))
91                                   .willReturn(aResponse()
92                                   .withStatus(200)
93                                   .withHeader("Content-Type", "application/json")
94                                   .withBodyFile(responseFile)));
95         }
96         
97         public static void MockGetServiceResourcesCatalogData(WireMockServer wireMockServer, String serviceModelInvariantUuid, String responseFile){
98                 wireMockServer.stubFor(get(urlEqualTo("/ecomp/mso/catalog/v2/serviceResources?serviceModelInvariantUuid=" + serviceModelInvariantUuid))
99                                   .willReturn(aResponse()
100                                   .withStatus(200)
101                                   .withHeader("Content-Type", "application/json")
102                                   .withBodyFile(responseFile)));
103         }       
104         
105     public static void MockGetServiceResourcesCatalogDataByModelUuid(WireMockServer wireMockServer, String serviceModelUuid, String responseFile){
106         wireMockServer.stubFor(get(urlEqualTo("/v2/serviceResources?serviceModelUuid=" + serviceModelUuid))
107                   .willReturn(aResponse()
108                   .withStatus(200)
109                   .withHeader("Content-Type", "application/json")
110                   .withBodyFile(responseFile)));
111     }   
112         
113         public static void MockPostRequestDB(WireMockServer wireMockServer){
114                 wireMockServer.stubFor(post(urlEqualTo("/dbadapters/RequestsDbAdapter"))
115                                 .willReturn(aResponse()
116                                 .withStatus(200)
117                             .withHeader("Content-Type", "text/xml")));
118         }       
119 }