Search in sources :

Example 71 with Builder

use of okhttp3.OkHttpClient.Builder in project keywhiz by square.

the class SecretResourceTest method partialUpdateSecret_notFound.

@Test
public void partialUpdateSecret_notFound() throws Exception {
    PartialUpdateSecretRequestV2 request = PartialUpdateSecretRequestV2.builder().description("a more detailed description").descriptionPresent(true).expiry(1487268151L).expiryPresent(true).build();
    RequestBody body = RequestBody.create(JSON, mapper.writeValueAsString(request));
    Request post = clientRequest("/automation/v2/secrets/non-existent/partialupdate").post(body).build();
    Response httpResponse = mutualSslClient.newCall(post).execute();
    assertThat(httpResponse.code()).isEqualTo(404);
}
Also used : Response(okhttp3.Response) PartialUpdateSecretRequestV2(keywhiz.api.automation.v2.PartialUpdateSecretRequestV2) Request(okhttp3.Request) TestClients.clientRequest(keywhiz.TestClients.clientRequest) RequestBody(okhttp3.RequestBody) Test(org.junit.Test)

Example 72 with Builder

use of okhttp3.OkHttpClient.Builder in project keywhiz by square.

the class SecretResourceTest method partialUpdateSecret_success.

//---------------------------------------------------------------------------------------
// partialUpdateSecret
//---------------------------------------------------------------------------------------
@Test
public void partialUpdateSecret_success() throws Exception {
    // Create a secret to update
    CreateOrUpdateSecretRequestV2 createRequest = CreateOrUpdateSecretRequestV2.builder().content(encoder.encodeToString("supa secret".getBytes(UTF_8))).description("desc").metadata(ImmutableMap.of("owner", "root", "mode", "0440")).type("password").build();
    Response httpResponse = createOrUpdate(createRequest, "secret3");
    assertThat(httpResponse.code()).isEqualTo(201);
    URI location = URI.create(httpResponse.header(LOCATION));
    assertThat(location.getPath()).isEqualTo("/automation/v2/secrets/secret3");
    // Update the secret's description and set its expiry
    PartialUpdateSecretRequestV2 request = PartialUpdateSecretRequestV2.builder().description("a more detailed description").descriptionPresent(true).expiry(1487268151L).expiryPresent(true).build();
    httpResponse = partialUpdate(request, "secret3");
    assertThat(httpResponse.code()).isEqualTo(201);
    location = URI.create(httpResponse.header(LOCATION));
    assertThat(location.getPath()).isEqualTo("/automation/v2/secrets/secret3");
}
Also used : Response(okhttp3.Response) PartialUpdateSecretRequestV2(keywhiz.api.automation.v2.PartialUpdateSecretRequestV2) CreateOrUpdateSecretRequestV2(keywhiz.api.automation.v2.CreateOrUpdateSecretRequestV2) URI(java.net.URI) Test(org.junit.Test)

Example 73 with Builder

use of okhttp3.OkHttpClient.Builder in project keywhiz by square.

the class SecretResourceTest method secretChangeVersion_notFound.

//---------------------------------------------------------------------------------------
// resetSecretVersion
//---------------------------------------------------------------------------------------
@Test
public void secretChangeVersion_notFound() throws Exception {
    Request post = clientRequest("/automation/v2/secrets/non-existent/setversion").post(RequestBody.create(JSON, mapper.writeValueAsString(SetSecretVersionRequestV2.builder().name("non-existent").version(0).build()))).build();
    Response httpResponse = mutualSslClient.newCall(post).execute();
    assertThat(httpResponse.code()).isEqualTo(404);
}
Also used : Response(okhttp3.Response) Request(okhttp3.Request) TestClients.clientRequest(keywhiz.TestClients.clientRequest) Test(org.junit.Test)

Example 74 with Builder

use of okhttp3.OkHttpClient.Builder in project keywhiz by square.

the class SecretResourceTest method createSecret_duplicateUnVersioned.

@Test
public void createSecret_duplicateUnVersioned() throws Exception {
    CreateSecretRequestV2 request = CreateSecretRequestV2.builder().name("secret2").content(encoder.encodeToString("supa secret2".getBytes(UTF_8))).description("desc").build();
    Response httpResponse = create(request);
    assertThat(httpResponse.code()).isEqualTo(201);
    httpResponse = create(request);
    assertThat(httpResponse.code()).isEqualTo(409);
}
Also used : Response(okhttp3.Response) CreateSecretRequestV2(keywhiz.api.automation.v2.CreateSecretRequestV2) Test(org.junit.Test)

Example 75 with Builder

use of okhttp3.OkHttpClient.Builder in project picasso by square.

the class NetworkRequestHandler method createRequest.

private static okhttp3.Request createRequest(Request request, int networkPolicy) {
    CacheControl cacheControl = null;
    if (networkPolicy != 0) {
        if (NetworkPolicy.isOfflineOnly(networkPolicy)) {
            cacheControl = CacheControl.FORCE_CACHE;
        } else {
            CacheControl.Builder builder = new CacheControl.Builder();
            if (!NetworkPolicy.shouldReadFromDiskCache(networkPolicy)) {
                builder.noCache();
            }
            if (!NetworkPolicy.shouldWriteToDiskCache(networkPolicy)) {
                builder.noStore();
            }
            cacheControl = builder.build();
        }
    }
    okhttp3.Request.Builder builder = new okhttp3.Request.Builder().url(request.uri.toString());
    if (cacheControl != null) {
        builder.cacheControl(cacheControl);
    }
    return builder.build();
}
Also used : CacheControl(okhttp3.CacheControl)

Aggregations

Request (okhttp3.Request)42 Response (okhttp3.Response)40 RequestBody (okhttp3.RequestBody)27 OkHttpClient (okhttp3.OkHttpClient)26 IOException (java.io.IOException)25 Test (org.junit.Test)17 Interceptor (okhttp3.Interceptor)9 File (java.io.File)8 URI (java.net.URI)7 X509TrustManager (javax.net.ssl.X509TrustManager)7 MultipartBody (okhttp3.MultipartBody)7 Map (java.util.Map)6 HttpUrl (okhttp3.HttpUrl)6 Provides (dagger.Provides)5 TestClients.clientRequest (keywhiz.TestClients.clientRequest)5 MediaType (okhttp3.MediaType)5 Retrofit (retrofit2.Retrofit)5 SSLContext (javax.net.ssl.SSLContext)4 TrustManager (javax.net.ssl.TrustManager)4 HttpLoggingInterceptor (okhttp3.logging.HttpLoggingInterceptor)4