Release 1.7.3 DCAEGEN2 VESCollector container
[dcaegen2/collectors/ves.git] / src / test / java / org / onap / dcae / WiremockBasedTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * org.onap.dcaegen2.collectors.ves
4  * ================================================================================
5  * Copyright (C) 2018 Nokia. All rights reserved.
6  * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.dcae;
23
24 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
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 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
29 import static io.vavr.API.Map;
30
31 import com.github.tomakehurst.wiremock.junit.WireMockRule;
32 import io.vavr.collection.Map;
33 import org.junit.Rule;
34
35 /**
36  * @author Pawel Szalapski (pawel.szalapski@nokia.com)
37  */
38 public class WiremockBasedTest {
39
40     @Rule
41     public WireMockRule wireMockRule = new WireMockRule(
42         wireMockConfig().dynamicPort().dynamicHttpsPort().keystorePath(null));
43
44     protected void stubConsulToReturnLocalAddressOfCBS() {
45         stubFor(get(urlEqualTo("/v1/catalog/service/CBSName"))
46             .willReturn(aResponse().withBody(validLocalCBSConf())));
47     }
48
49     protected void stubCBSToReturnAppConfig(String sampleConfigForVES) {
50         stubFor(get(urlEqualTo("/service_component/VESCollector"))
51             .willReturn(aResponse().withBody(sampleConfigForVES)));
52     }
53
54     protected Map<String, String> wiremockBasedEnvProps() {
55         return Map(
56             "CONSUL_HOST", "localhost",
57             "CONSUL_PORT", "" + wireMockRule.port(),
58             "HOSTNAME", "VESCollector",
59             "CONFIG_BINDING_SERVICE", "CBSName"
60         );
61     }
62
63     protected String validLocalCBSConf() {
64         return ""
65             + "[{ "
66             + "\"ServiceAddress\": \"localhost\","
67             + "\"ServicePort\":" + wireMockRule.port()
68             + "}]";
69     }
70 }