use of okhttp3.FormBody.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);
}
use of okhttp3.FormBody.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");
}
use of okhttp3.FormBody.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);
}
use of okhttp3.FormBody.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);
}
use of okhttp3.FormBody.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();
}
Aggregations