Refactor babel-related code to not update parameter values
[aai/model-loader.git] / src / test / java / org / onap / aai / modelloader / DistributionClientTestConfiguration.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
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
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 package org.onap.aai.modelloader;
21
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;
28
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;
34
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;
41
42 @TestConfiguration
43 public class DistributionClientTestConfiguration {
44
45   @Value("${CONFIG_HOME}")
46   private String configDir;
47
48   @Value("${wiremock.server.port}")
49   private int wiremockPort;
50
51   @Primary
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);
58
59     setOverrides(configProperties);
60
61     return configProperties;
62   }
63
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);
67   }
68
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")));
75
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")));
80   }
81 }