2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2024 Deutsche Telekom AG 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
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.aai.modelloader;
22 import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
23 import static com.github.tomakehurst.wiremock.client.WireMock.equalTo;
24 import static com.github.tomakehurst.wiremock.client.WireMock.get;
25 import static com.github.tomakehurst.wiremock.client.WireMock.matching;
26 import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
27 import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
29 import java.io.IOException;
30 import java.io.InputStream;
31 import java.nio.file.Files;
32 import java.nio.file.Paths;
33 import java.util.Properties;
35 import org.springframework.beans.factory.annotation.Value;
36 import org.springframework.boot.context.event.ApplicationStartedEvent;
37 import org.springframework.boot.test.context.TestConfiguration;
38 import org.springframework.context.annotation.Bean;
39 import org.springframework.context.annotation.Primary;
40 import org.springframework.context.event.EventListener;
43 public class DistributionClientTestConfiguration {
45 @Value("${CONFIG_HOME}")
46 private String configDir;
48 @Value("${wiremock.server.port}")
49 private int wiremockPort;
52 @Bean(name = "testProperties")
53 public Properties configProperties() throws IOException {
54 // Load model loader system configuration
55 InputStream configInputStream = Files.newInputStream(Paths.get(configDir, "model-loader.properties"));
56 Properties configProperties = new Properties();
57 configProperties.load(configInputStream);
59 setOverrides(configProperties);
61 return configProperties;
64 private void setOverrides(Properties configProperties) {
65 configProperties.setProperty("ml.distribution.ASDC_ADDRESS", "localhost:" + wiremockPort);
66 configProperties.setProperty("ml.babel.BASE_URL", "http://localhost:" + wiremockPort);
69 @EventListener(ApplicationStartedEvent.class)
70 public void mockSdcInit() {
71 stubFor(get(urlEqualTo("/sdc/v1/artifactTypes"))
72 .withHeader("X-ECOMP-RequestID", matching(".+"))
73 .withHeader("X-ECOMP-InstanceID", equalTo("aai-ml-id-test"))
74 .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("artifactTypes.json")));
76 stubFor(get(urlEqualTo("/sdc/v1/distributionKafkaData"))
77 .withHeader("X-ECOMP-RequestID", matching(".+"))
78 .withHeader("X-ECOMP-InstanceID", equalTo("aai-ml-id-test"))
79 .willReturn(aResponse().withHeader("Content-Type", "application/json").withBodyFile("kafkaBootstrap.json")));