本文整理了Java中com.github.tomakehurst.wiremock.client.WireMock.urlMatching()
方法的一些代码示例,展示了WireMock.urlMatching()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WireMock.urlMatching()
方法的具体详情如下:
包路径:com.github.tomakehurst.wiremock.client.WireMock
类名称:WireMock
方法名:urlMatching
暂无
代码示例来源:origin: palantir/atlasdb
private void verifyUsingTimeLockByGettingAFreshTimestamp() {
when(config.namespace()).thenReturn(Optional.of(CLIENT));
getLockAndTimestampServices().timelock().getFreshTimestamp();
availableServer.verify(1, postRequestedFor(urlMatching(TIMELOCK_TIMESTAMP_PATH)));
}
代码示例来源:origin: palantir/atlasdb
@Test
public void directProxyIsConfigurableOnClientRequests() {
Optional<ProxySelector> directProxySelector = Optional.of(
ServiceCreator.createProxySelector(ProxyConfiguration.DIRECT));
TestResource clientWithDirectCall = AtlasDbHttpClients.createProxyWithFailover(
new MetricRegistry(), NO_SSL,
directProxySelector, ImmutableSet.of(getUriForPort(availablePort)), TestResource.class);
clientWithDirectCall.getTestNumber();
String defaultUserAgent = UserAgents.fromStrings(UserAgents.DEFAULT_VALUE, UserAgents.DEFAULT_VALUE);
availableServer.verify(getRequestedFor(urlMatching(TEST_ENDPOINT))
.withHeader(FeignOkHttpClients.USER_AGENT_HEADER, WireMock.equalTo(defaultUserAgent)));
}
代码示例来源:origin: palantir/atlasdb
@Test
public void ifOneServerResponds503WithNoRetryHeaderTheRequestIsRerouted() {
unavailableServer.stubFor(ENDPOINT_MAPPING.willReturn(aResponse().withStatus(503)));
TestResource client = AtlasDbHttpClients.createProxyWithFailover(new MetricRegistry(),
NO_SSL,
Optional.empty(), bothUris, TestResource.class);
int response = client.getTestNumber();
assertThat(response, equalTo(TEST_NUMBER));
unavailableServer.verify(getRequestedFor(urlMatching(TEST_ENDPOINT)));
}
代码示例来源:origin: palantir/atlasdb
@Test
public void httpProxyIsConfigurableOnClientRequests() {
Optional<ProxySelector> httpProxySelector = Optional.of(
ServiceCreator.createProxySelector(ProxyConfiguration.of(getHostAndPort(proxyPort))));
TestResource clientWithHttpProxy = AtlasDbHttpClients.createProxyWithFailover(
new MetricRegistry(),
NO_SSL,
httpProxySelector, ImmutableSet.of(getUriForPort(availablePort)), TestResource.class);
clientWithHttpProxy.getTestNumber();
String defaultUserAgent = UserAgents.fromStrings(UserAgents.DEFAULT_VALUE, UserAgents.DEFAULT_VALUE);
proxyServer.verify(getRequestedFor(urlMatching(TEST_ENDPOINT))
.withHeader(FeignOkHttpClients.USER_AGENT_HEADER, WireMock.equalTo(defaultUserAgent)));
availableServer.verify(0, getRequestedFor(urlMatching(TEST_ENDPOINT)));
}
代码示例来源:origin: palantir/atlasdb
@Test
public void canLiveReloadServersList() {
unavailableServer.stubFor(ENDPOINT_MAPPING.willReturn(aResponse().withStatus(503)));
List<String> servers = Lists.newArrayList(getUriForPort(unavailablePort));
TestResource client = AtlasDbHttpClients.createLiveReloadingProxyWithQuickFailoverForTesting(
new MetricRegistry(),
() -> ImmutableServerListConfig.builder()
.servers(servers)
.build(),
SslSocketFactories::createTrustContext,
unused -> ProxySelector.getDefault(),
TestResource.class,
"user (123)");
// actually a Feign RetryableException but that's not on our classpath
assertThatThrownBy(client::getTestNumber).isInstanceOf(RuntimeException.class);
servers.add(getUriForPort(availablePort));
Uninterruptibles.sleepUninterruptibly(
PollingRefreshable.DEFAULT_REFRESH_INTERVAL.getSeconds() + 1, TimeUnit.SECONDS);
int response = client.getTestNumber();
assertThat(response, equalTo(TEST_NUMBER));
unavailableServer.verify(getRequestedFor(urlMatching(TEST_ENDPOINT)));
}
代码示例来源:origin: palantir/atlasdb
@Test
public void userAgentIsPresentOnClientRequests() {
TestResource client =
AtlasDbHttpClients.createProxy(
new MetricRegistry(), NO_SSL, getUriForPort(availablePort), TestResource.class);
client.getTestNumber();
String defaultUserAgent = UserAgents.fromStrings(UserAgents.DEFAULT_VALUE, UserAgents.DEFAULT_VALUE);
availableServer.verify(getRequestedFor(urlMatching(TEST_ENDPOINT))
.withHeader(FeignOkHttpClients.USER_AGENT_HEADER, WireMock.equalTo(defaultUserAgent)));
}
代码示例来源:origin: palantir/atlasdb
@Test
public void remoteCallsElidedIfTalkingToLocalServer() throws IOException, InterruptedException {
setUpForLocalServices();
setUpLeaderBlockInConfig();
TransactionManagers.LockAndTimestampServices lockAndTimestamp = getLockAndTimestampServices();
availableServer.verify(getRequestedFor(urlMatching(LEADER_UUID_PATH)));
lockAndTimestamp.timelock().getFreshTimestamp();
lockAndTimestamp.lock().currentTimeMillis();
availableServer.verify(0, postRequestedFor(urlMatching(TIMESTAMP_PATH))
.withHeader(USER_AGENT_HEADER, WireMock.equalTo(USER_AGENT)));
availableServer.verify(0, postRequestedFor(urlMatching(LOCK_PATH))
.withHeader(USER_AGENT_HEADER, WireMock.equalTo(USER_AGENT)));
}
代码示例来源:origin: palantir/atlasdb
@Test
public void remoteCallsStillMadeIfPingableLeader404s() throws IOException, InterruptedException {
setUpForRemoteServices();
setUpLeaderBlockInConfig();
TransactionManagers.LockAndTimestampServices lockAndTimestamp = getLockAndTimestampServices();
availableServer.verify(getRequestedFor(urlMatching(LEADER_UUID_PATH)));
lockAndTimestamp.timelock().getFreshTimestamp();
lockAndTimestamp.lock().currentTimeMillis();
availableServer.verify(postRequestedFor(urlMatching(TIMESTAMP_PATH))
.withHeader(USER_AGENT_HEADER, WireMock.equalTo(USER_AGENT)));
availableServer.verify(postRequestedFor(urlMatching(LOCK_PATH))
.withHeader(USER_AGENT_HEADER, WireMock.equalTo(USER_AGENT)));
}
代码示例来源:origin: palantir/atlasdb
private void verifyUserAgentOnTimestampAndLockRequests(String timestampPath, String lockPath) {
InMemoryTimestampService ts = new InMemoryTimestampService();
TransactionManagers.LockAndTimestampServices lockAndTimestamp =
TransactionManagers.createLockAndTimestampServices(
metricsManager,
config,
() -> runtimeConfig,
environment,
LockServiceImpl::create,
() -> ts,
() -> ts,
invalidator,
USER_AGENT);
lockAndTimestamp.timelock().getFreshTimestamp();
lockAndTimestamp.timelock().currentTimeMillis();
availableServer.verify(postRequestedFor(urlMatching(timestampPath))
.withHeader(USER_AGENT_HEADER, WireMock.equalTo(USER_AGENT)));
availableServer.verify(postRequestedFor(urlMatching(lockPath))
.withHeader(USER_AGENT_HEADER, WireMock.equalTo(USER_AGENT)));
}
代码示例来源:origin: palantir/atlasdb
@Test
public void userAgentsPresentOnRequestsToTimelockServer() {
setUpTimeLockBlockInInstallConfig();
availableServer.stubFor(post(urlMatching("/")).willReturn(aResponse().withStatus(200).withBody("3")));
availableServer.stubFor(TIMELOCK_LOCK_MAPPING.willReturn(aResponse().withStatus(200).withBody("4")));
verifyUserAgentOnTimelockTimestampAndLockRequests();
}
代码示例来源:origin: aws/aws-sdk-java-v2
/**
* @return All LoggedRequests that wire mock captured.
*/
public static List<LoggedRequest> findAllLoggedRequests() {
List<LoggedRequest> requests = findAll(
new RequestPatternBuilder(RequestMethod.ANY, urlMatching(".*")));
return requests;
}
代码示例来源:origin: software.amazon.awssdk/protocol-tests-core
/**
* @return All LoggedRequests that wire mock captured.
*/
public static List<LoggedRequest> findAllLoggedRequests() {
List<LoggedRequest> requests = findAll(
new RequestPatternBuilder(RequestMethod.ANY, urlMatching(".*")));
return requests;
}
}
代码示例来源:origin: aws/aws-sdk-java-v2
/**
* Reset wire mock and re-configure stubbing.
*/
private void resetWireMock(GivenResponse givenResponse) {
WireMock.reset();
// Stub to return given response in test definition.
stubFor(any(urlMatching(".*")).willReturn(toResponseBuilder(givenResponse)));
}
代码示例来源:origin: software.amazon.awssdk/protocol-tests-core
/**
* Reset wire mock and re-configure stubbing.
*/
private void resetWireMock(GivenResponse givenResponse) {
WireMock.reset();
// Stub to return given response in test definition.
stubFor(any(urlMatching(".*")).willReturn(toResponseBuilder(givenResponse)));
}
代码示例来源:origin: mozilla/zest
private void verifyUrlAccessed(String filePath) {
server.verify(getRequestedFor(urlMatching(filePath)));
}
代码示例来源:origin: aws/aws-sdk-java-v2
/**
* Reset wire mock and re-configure stubbing.
*/
private void resetWireMock() {
WireMock.reset();
// Stub to return 200 for all requests
ResponseDefinitionBuilder responseDefBuilder = aResponse().withStatus(200);
// XML Unmarshallers expect at least one level in the XML document.
if (model.getMetadata().isXmlProtocol()) {
responseDefBuilder.withBody("<foo></foo>");
}
stubFor(any(urlMatching(".*")).willReturn(responseDefBuilder));
}
代码示例来源:origin: software.amazon.awssdk/protocol-tests-core
/**
* Reset wire mock and re-configure stubbing.
*/
private void resetWireMock() {
WireMock.reset();
// Stub to return 200 for all requests
final ResponseDefinitionBuilder responseDefBuilder = aResponse().withStatus(200);
// XML Unmarshallers expect at least one level in the XML document.
if (model.getMetadata().isXmlProtocol()) {
responseDefBuilder.withBody("<foo></foo>");
}
stubFor(any(urlMatching(".*")).willReturn(responseDefBuilder));
}
代码示例来源:origin: kamax-matrix/mxisd
@Test
public void forNameNotFound() {
stubFor(post(urlEqualTo(displayNameEndpoint))
.willReturn(aResponse()
.withStatus(404)
)
);
Optional<String> v = p.getDisplayName(userId);
verify(postRequestedFor(urlMatching(displayNameEndpoint))
.withHeader("Content-Type", containing(ContentType.APPLICATION_JSON.getMimeType()))
.withRequestBody(equalTo(GsonUtil.get().toJson(new JsonProfileRequest(userId))))
);
assertFalse(v.isPresent());
}
代码示例来源:origin: kamax-matrix/mxisd
@Test
public void forNameEmptyBody() {
stubFor(post(urlEqualTo(displayNameEndpoint))
.willReturn(aResponse()
.withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
)
);
Optional<String> v = p.getDisplayName(userId);
verify(postRequestedFor(urlMatching(displayNameEndpoint))
.withHeader("Content-Type", containing(ContentType.APPLICATION_JSON.getMimeType()))
.withRequestBody(equalTo(GsonUtil.get().toJson(new JsonProfileRequest(userId))))
);
assertFalse(v.isPresent());
}
代码示例来源:origin: kamax-matrix/mxisd
@Test
public void lookupSingleNotFound() {
stubFor(post(urlEqualTo(lookupSinglePath))
.willReturn(aResponse()
.withHeader("Content-Type", ContentType.APPLICATION_JSON.getMimeType())
.withBody(lookupSingleNotFoundBody)
)
);
Optional<SingleLookupReply> rep = p.find(lookupSingleRequest);
assertTrue(!rep.isPresent());
verify(postRequestedFor(urlMatching("/lookup/single"))
.withHeader("Content-Type", containing(ContentType.APPLICATION_JSON.getMimeType()))
.withRequestBody(equalTo(lookupSingleRequestBody))
);
}
内容来源于网络,如有侵权,请联系作者删除!