Skip to content

Commit

Permalink
feat(irs-api):[#344] Extract WireMockConfig to irs-testing
Browse files Browse the repository at this point in the history
  • Loading branch information
ds-jhartmann committed Jan 23, 2024
1 parent 62cc323 commit 57e09cd
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
5 changes: 5 additions & 0 deletions irs-testing/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand All @@ -53,6 +54,10 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- Update json-smart manually to avoid vulnerability CVE-2023-1370; can be removed after Spring updates their dependency -->
<dependency>
<groupId>net.minidev</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/********************************************************************************
* Copyright (c) 2021,2024 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
* SPDX-License-Identifier: Apache-2.0
********************************************************************************/
package org.eclipse.tractusx.irs.testing.wiremock;

import java.net.InetSocketAddress;
import java.net.Proxy;

import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
* Common configurations for Wiremock tests.
*/
public final class WireMockConfig {
private WireMockConfig() {
}

/**
* Configured RestTemplate which proxies all requests to the provided host / port.
*
* @param proxyServerHost the host where all requests will be proxied to
* @param httpPort the port of the host where all requests will be proxied to
* @return the configured {@link RestTemplate}
*/
public static RestTemplate restTemplateProxy(final String proxyServerHost, final int httpPort) {
final Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyServerHost, httpPort));
final SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory();
requestFactory.setProxy(proxy);
return new RestTemplate(requestFactory);
}
}

0 comments on commit 57e09cd

Please sign in to comment.