Search in sources :

Example 1 with Parameters

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());
}
Also used : V1PodList(io.kubernetes.client.openapi.models.V1PodList) Parameters(com.github.tomakehurst.wiremock.extension.Parameters) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Pod(io.kubernetes.client.openapi.models.V1Pod) JSON(io.kubernetes.client.openapi.JSON) Semaphore(java.util.concurrent.Semaphore) V1ConfigMapList(io.kubernetes.client.openapi.models.V1ConfigMapList) V1ConfigMap(io.kubernetes.client.openapi.models.V1ConfigMap) V1ListMeta(io.kubernetes.client.openapi.models.V1ListMeta) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with Parameters

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();
        }
    };
}
Also used : Parameters(com.github.tomakehurst.wiremock.extension.Parameters) JwtClaims(org.jose4j.jwt.JwtClaims) Request(com.github.tomakehurst.wiremock.http.Request) RequestMatcherExtension(com.github.tomakehurst.wiremock.matching.RequestMatcherExtension)

Example 3 with Parameters

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());
}
Also used : Parameters(com.github.tomakehurst.wiremock.extension.Parameters) V1ObjectMeta(io.kubernetes.client.openapi.models.V1ObjectMeta) V1Pod(io.kubernetes.client.openapi.models.V1Pod) ExecProcess(io.kubernetes.client.Exec.ExecProcess) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test)

Aggregations

Parameters (com.github.tomakehurst.wiremock.extension.Parameters)3 V1ObjectMeta (io.kubernetes.client.openapi.models.V1ObjectMeta)2 V1Pod (io.kubernetes.client.openapi.models.V1Pod)2 Semaphore (java.util.concurrent.Semaphore)2 Test (org.junit.Test)2 Request (com.github.tomakehurst.wiremock.http.Request)1 RequestMatcherExtension (com.github.tomakehurst.wiremock.matching.RequestMatcherExtension)1 ExecProcess (io.kubernetes.client.Exec.ExecProcess)1 JSON (io.kubernetes.client.openapi.JSON)1 V1ConfigMap (io.kubernetes.client.openapi.models.V1ConfigMap)1 V1ConfigMapList (io.kubernetes.client.openapi.models.V1ConfigMapList)1 V1ListMeta (io.kubernetes.client.openapi.models.V1ListMeta)1 V1PodList (io.kubernetes.client.openapi.models.V1PodList)1 JwtClaims (org.jose4j.jwt.JwtClaims)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1