-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(irs-api):[#344] Extract WireMockConfig to irs-testing
- Loading branch information
1 parent
62cc323
commit 57e09cd
Showing
2 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
irs-testing/src/main/java/org/eclipse/tractusx/irs/testing/wiremock/WireMockConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |