Example usage for com.squareup.okhttp Response code

List of usage examples for com.squareup.okhttp Response code

Introduction

In this page you can find the example usage for com.squareup.okhttp Response code.

Prototype

int code

To view the source code for com.squareup.okhttp Response code.

Click Source Link

Usage

From source file:keywhiz.service.resources.AutomationSecretResourceIntegrationTest.java

License:Apache License

@Test
public void readValidSecret() throws Exception {
    CreateSecretRequest request = new CreateSecretRequest("readable", "desc", "c3VwZXJTZWNyZXQK", false,
            ImmutableMap.of());/*from  w ww  . j  av  a 2 s .  c om*/
    String body = mapper.writeValueAsString(request);
    Request post = new Request.Builder().post(RequestBody.create(KeywhizClient.JSON, body))
            .url(testUrl("/automation/secrets")).addHeader("Content-Type", MediaType.APPLICATION_JSON).build();

    Response response = mutualSslClient.newCall(post).execute();
    assertThat(response.code()).isEqualTo(200);

    Request get = new Request.Builder().get().url(testUrl("/automation/secrets?name=readable")).build();
    response = mutualSslClient.newCall(get).execute();
    assertThat(response.code()).isEqualTo(200);
}

From source file:keywhiz.service.resources.AutomationSecretResourceIntegrationTest.java

License:Apache License

@Test
public void readInvalidSecret() throws Exception {
    Request get = new Request.Builder().get().url(testUrl("/automation/secrets?name=invalid")).build();
    Response response = mutualSslClient.newCall(get).execute();
    assertThat(response.code()).isEqualTo(404);
}

From source file:keywhiz.service.resources.AutomationSecretResourceIntegrationTest.java

License:Apache License

@Test
public void deleteSecrets() throws Exception {
    CreateSecretRequest request = new CreateSecretRequest("deletable", "desc", "c3VwZXJTZWNyZXQK", true,
            ImmutableMap.of());// w  w  w  . j ava  2  s.c  o  m
    String body = mapper.writeValueAsString(request);
    Request post = new Request.Builder().post(RequestBody.create(KeywhizClient.JSON, body))
            .url(testUrl("/automation/secrets")).addHeader("Content-Type", MediaType.APPLICATION_JSON).build();

    Response response = mutualSslClient.newCall(post).execute();
    assertThat(response.code()).isEqualTo(200);

    Request delete = new Request.Builder().delete().url(testUrl("/automation/secrets/deletable")).build();

    response = mutualSslClient.newCall(delete).execute();
    assertThat(response.code()).isEqualTo(200);
}

From source file:keywhiz.service.resources.SecretDeliveryResourceIntegrationTest.java

License:Apache License

@Test
public void returnsSecretWhenAllowed() throws Exception {
    Request get = new Request.Builder().get().url(testUrl("/secret/General_Password")).build();

    Response response = client.newCall(get).execute();
    assertThat(response.code()).isEqualTo(200);
    assertThat(response.body().string())
            .isEqualTo(mapper.writeValueAsString(SecretDeliveryResponse.fromSecret(generalPassword)));
}

From source file:keywhiz.service.resources.SecretDeliveryResourceIntegrationTest.java

License:Apache License

@Test
public void returnsNotFoundWhenSecretUnspecified() throws Exception {
    Request get = new Request.Builder().get().url(testUrl("/secret/")).build();

    Response response = client.newCall(get).execute();
    assertThat(response.code()).isEqualTo(404);
}

From source file:keywhiz.service.resources.SecretDeliveryResourceIntegrationTest.java

License:Apache License

@Test
public void returnsNotFoundWhenSecretDoesNotExist() throws Exception {
    Request get = new Request.Builder().get().url(testUrl("/secret/nonexistent")).build();

    Response response = client.newCall(get).execute();
    assertThat(response.code()).isEqualTo(404);
}

From source file:keywhiz.service.resources.SecretDeliveryResourceIntegrationTest.java

License:Apache License

@Test
public void returnsUnauthorizedWhenDenied() throws Exception {
    Request get = new Request.Builder().get().url(testUrl("/secret/Hacking_Password")).build();

    Response response = client.newCall(get).execute();
    assertThat(response.code()).isEqualTo(403);
}

From source file:keywhiz.service.resources.SecretsDeliveryResourceIntegrationTest.java

License:Apache License

@Test
public void returnsJsonArrayWhenUserHasMultipleSecrets() throws Exception {
    Request get = new Request.Builder().get().url(testUrl("/secrets")).build();

    Response response = client.newCall(get).execute();
    assertThat(response.code()).isEqualTo(200);

    String responseString = response.body().string();
    assertThat(responseString).contains(generalPassword.getName()).contains(databasePassword.getName())
            .contains(nobodyPgPassPassword.getName()).contains(nonExistentOwnerPass.getName());
}

From source file:keywhiz.service.resources.SecretsDeliveryResourceIntegrationTest.java

License:Apache License

@Test
public void returnsJsonArray() throws Exception {
    Request get = new Request.Builder().get().url(testUrl("/secrets")).build();

    Response response = client.newCall(get).execute();
    assertThat(response.code()).isEqualTo(200);
    assertThat(response.body().string()).startsWith("[").endsWith("]");
}

From source file:keywhiz.service.resources.SecretsDeliveryResourceIntegrationTest.java

License:Apache License

@Test
public void returnsUnauthorizedWhenUnauthenticated() throws Exception {
    Request get = new Request.Builder().get().url(testUrl("/secrets")).build();

    Response response = clientNoClientCert.newCall(get).execute();
    assertThat(response.code()).isEqualTo(401);
}