-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
114 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
50 changes: 50 additions & 0 deletions
50
...arthomej.binding.http/src/test/org/smarthomej/binding/http/RateLimitedHttpClientTest.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,50 @@ | ||
/** | ||
* Copyright (c) 2021 Contributors to the SmartHome/J project | ||
* | ||
* See the NOTICE file(s) distributed with this work for additional | ||
* information. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License 2.0 which is available at | ||
* http://www.eclipse.org/legal/epl-2.0 | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
*/ | ||
package org.smarthomej.binding.http; | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer; | ||
import org.eclipse.jdt.annotation.NonNullByDefault; | ||
import org.eclipse.jetty.client.HttpClient; | ||
import org.eclipse.jetty.client.api.ContentResponse; | ||
import org.eclipse.jetty.http.HttpMethod; | ||
import org.junit.jupiter.api.Test; | ||
import org.openhab.core.test.TestPortUtil; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.configureFor; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.get; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
@NonNullByDefault | ||
public class RateLimitedHttpClientTest { | ||
|
||
@Test | ||
public void simpleHttpTest() throws Exception { | ||
int port = TestPortUtil.findFreePort(); | ||
|
||
WireMockServer wireMockServer = new WireMockServer(port); | ||
wireMockServer.start(); | ||
|
||
configureFor("localhost", 8080); | ||
stubFor(get(urlEqualTo("/baeldung")).willReturn(aResponse().withBody("Welcome to Baeldung!"))); | ||
|
||
HttpClient httpClient = new HttpClient(); | ||
httpClient.start(); | ||
|
||
ContentResponse cr = httpClient.newRequest("http://localhost:"+port+"/baeldung").method(HttpMethod.GET).send(); | ||
|
||
assertEquals("x", cr.getContentAsString()); | ||
} | ||
} |