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