Search in sources :

Example 1 with SimpleResponse

use of org.jose4j.http.SimpleResponse in project kafka by apache.

the class RefreshingHttpsJwksTest method spyHttpsJwks.

/**
 * We *spy* (not *mock*) the {@link HttpsJwks} instance because we want to have it
 * _partially mocked_ to determine if it's calling its internal refresh method. We want to
 * make sure it *doesn't* do that when we call our getJsonWebKeys() method on
 * {@link RefreshingHttpsJwks}.
 */
private HttpsJwks spyHttpsJwks() {
    HttpsJwks httpsJwks = new HttpsJwks("https://www.example.com");
    SimpleResponse simpleResponse = new SimpleResponse() {

        @Override
        public int getStatusCode() {
            return 200;
        }

        @Override
        public String getStatusMessage() {
            return "OK";
        }

        @Override
        public Collection<String> getHeaderNames() {
            return Collections.emptyList();
        }

        @Override
        public List<String> getHeaderValues(String name) {
            return Collections.emptyList();
        }

        @Override
        public String getBody() {
            return "{\"keys\": []}";
        }
    };
    httpsJwks.setSimpleHttpGet(l -> simpleResponse);
    return Mockito.spy(httpsJwks);
}
Also used : HttpsJwks(org.jose4j.jwk.HttpsJwks) SimpleResponse(org.jose4j.http.SimpleResponse)

Aggregations

SimpleResponse (org.jose4j.http.SimpleResponse)1 HttpsJwks (org.jose4j.jwk.HttpsJwks)1