2 * ============LICENSE_START=======================================================
3 * org.onap.dcaegen2.collectors.ves
4 * ================================================================================
5 * Copyright (C) 2020 Nokia. 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
20 package org.onap.dcae.configuration.cbs;
22 import com.github.tomakehurst.wiremock.junit.WireMockRule;
23 import org.json.JSONObject;
24 import org.junit.Rule;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.mockito.junit.MockitoJUnitRunner;
28 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.CbsClientConfiguration;
29 import org.onap.dcaegen2.services.sdk.rest.services.cbs.client.model.ImmutableCbsClientConfiguration;
31 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
32 import static com.github.tomakehurst.wiremock.client.WireMock.get;
33 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
34 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
35 import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig;
36 import static org.assertj.core.api.Assertions.assertThat;
38 @RunWith(MockitoJUnitRunner.Silent.class)
39 public class CbsConfigResolverTest {
41 private static final String VES_CONFIG = "{\"collector.port\": 8081}";
42 private static final String HOSTNAME = "localhost";
43 private static final String PROTOCOL = "http";
44 private static final String APP_NAME = "VESCollector";
47 public final WireMockRule wireMockRule = new WireMockRule(
48 wireMockConfig().dynamicPort().dynamicPort());
51 public void shouldFetchConfigurationFromCBS() {
53 final int PORT = wireMockRule.port();
54 stubCBSToReturnAppConfig();
57 CbsClientConfiguration cbsClientConfiguration = ImmutableCbsClientConfiguration.builder()
63 JSONObject appConfig = new CbsConfigResolver(cbsClientConfiguration).getAppConfig().get();
66 assertThat(appConfig).isNotNull();
67 assertThat(appConfig.toString()).isEqualTo(new JSONObject(VES_CONFIG).toString());
70 private void stubCBSToReturnAppConfig() {
71 stubFor(get(urlEqualTo("/service_component/VESCollector"))
72 .willReturn(aResponse().withBody(CbsConfigResolverTest.VES_CONFIG)));