use of com.github.tomakehurst.wiremock.extension.Parameters in project java by kubernetes-client.
the class KubernetesInformerCreatorTest method testInformerInjection.
@Test
public void testInformerInjection() throws InterruptedException {
assertNotNull(podInformer);
assertNotNull(configMapInformer);
Semaphore getCount = new Semaphore(2);
Semaphore watchCount = new Semaphore(2);
Parameters getParams = new Parameters();
Parameters watchParams = new Parameters();
getParams.put("semaphore", getCount);
watchParams.put("semaphore", watchCount);
V1Pod foo1 = new V1Pod().kind("Pod").metadata(new V1ObjectMeta().namespace("default").name("foo1"));
V1ConfigMap bar1 = new V1ConfigMap().kind("ConfigMap").metadata(new V1ObjectMeta().namespace("default").name("bar1"));
wireMockRule.stubFor(get(urlMatching("^/api/v1/pods.*")).withPostServeAction("semaphore", getParams).withQueryParam("watch", equalTo("false")).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1PodList().metadata(new V1ListMeta().resourceVersion("0")).items(Arrays.asList(foo1))))));
wireMockRule.stubFor(get(urlMatching("^/api/v1/pods.*")).withPostServeAction("semaphore", watchParams).withQueryParam("watch", equalTo("true")).willReturn(aResponse().withStatus(200).withBody("{}")));
wireMockRule.stubFor(get(urlMatching("^/api/v1/namespaces/default/configmaps.*")).withPostServeAction("semaphore", getParams).withQueryParam("watch", equalTo("false")).willReturn(aResponse().withStatus(200).withBody(new JSON().serialize(new V1ConfigMapList().metadata(new V1ListMeta().resourceVersion("0")).items(Arrays.asList(bar1))))));
wireMockRule.stubFor(get(urlMatching("^/api/v1/namespaces/default/configmaps.*")).withPostServeAction("semaphore", watchParams).withQueryParam("watch", equalTo("true")).willReturn(aResponse().withStatus(200).withBody("{}")));
// These will be released for each web call above.
getCount.acquire(2);
watchCount.acquire(2);
informerFactory.startAllRegisteredInformers();
// Wait for the GETs to complete and the watches to start.
getCount.acquire(2);
watchCount.acquire(2);
verify(1, getRequestedFor(urlPathEqualTo("/api/v1/pods")).withQueryParam("watch", equalTo("false")));
verify(getRequestedFor(urlPathEqualTo("/api/v1/pods")).withQueryParam("watch", equalTo("true")));
verify(1, getRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/configmaps")).withQueryParam("watch", equalTo("false")));
verify(getRequestedFor(urlPathEqualTo("/api/v1/namespaces/default/configmaps")).withQueryParam("watch", equalTo("true")));
assertEquals(1, new Lister<>(podInformer.getIndexer()).list().size());
assertEquals(1, new Lister<>(configMapInformer.getIndexer()).list().size());
}
use of com.github.tomakehurst.wiremock.extension.Parameters in project box-java-sdk by box.
the class BoxDeveloperEditionAPIConnectionTest method getRequestMatcher.
private RequestMatcherExtension getRequestMatcher(final String tokenPath) {
return new RequestMatcherExtension() {
@Override
public MatchResult match(Request request, Parameters parameters) {
if (!request.getMethod().equals(RequestMethod.POST) || !request.getUrl().equals(tokenPath)) {
return MatchResult.noMatch();
}
Assert.assertNotNull("JTI should be saved from previous request", BoxDeveloperEditionAPIConnectionTest.this.jtiClaim);
try {
JwtClaims claims = BoxDeveloperEditionAPIConnectionTest.this.getClaimsFromRequest(request);
String jti = claims.getJwtId();
long expTimestamp = claims.getExpirationTime().getValue();
Assert.assertNotEquals("JWT should have a new timestamp", 1511003910L, expTimestamp);
Assert.assertNotEquals("JWT should have a new jti claim", BoxDeveloperEditionAPIConnectionTest.this.jtiClaim, jti);
} catch (Exception ex) {
Assert.fail("Could not parse JWT when request is retried: " + ex.getMessage());
}
return MatchResult.exactMatch();
}
};
}
use of com.github.tomakehurst.wiremock.extension.Parameters in project java by kubernetes-client.
the class ExecTest method testUrl.
@Test
public void testUrl() throws IOException, ApiException, InterruptedException {
Exec exec = new Exec(client);
V1Pod pod = new V1Pod().metadata(new V1ObjectMeta().name(podName).namespace(namespace));
Semaphore getCount = new Semaphore(2);
Parameters getParams = new Parameters();
getParams.put("semaphore", getCount);
wireMockRule.stubFor(get(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/exec")).withPostServeAction("semaphore", getParams).willReturn(aResponse().withStatus(404).withHeader("Content-Type", "application/json").withBody("{}")));
Process p = exec.exec(pod, cmd, "container", true, false);
p.waitFor();
exec.newExecutionBuilder(pod.getMetadata().getNamespace(), pod.getMetadata().getName(), cmd).setContainer("container").setStdin(false).setStderr(false).execute().waitFor();
// These will be released for each web call above.
// There is a race between the above waitFor() and the request actually being recorded
// by WireMock. This fixes it.
getCount.acquire(2);
wireMockRule.verify(getRequestedFor(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/exec")).withQueryParam("stdin", equalTo("true")).withQueryParam("stdout", equalTo("true")).withQueryParam("stderr", equalTo("true")).withQueryParam("container", equalTo("container")).withQueryParam("tty", equalTo("false")).withQueryParam("command", equalTo("cmd")));
wireMockRule.verify(getRequestedFor(urlPathEqualTo("/api/v1/namespaces/" + namespace + "/pods/" + podName + "/exec")).withQueryParam("stdin", equalTo("false")).withQueryParam("stdout", equalTo("true")).withQueryParam("stderr", equalTo("false")).withQueryParam("container", equalTo("container")).withQueryParam("tty", equalTo("false")).withQueryParam("command", equalTo("cmd")));
assertEquals(-1975219, p.exitValue());
}
Aggregations