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.AutomationGroupResourceIntegrationTest.java

License:Apache License

@Test
public void findGroupNotFound() throws Exception {
    Request get = new Request.Builder().get().url(testUrl("/automation/groups?name=non-existent-group"))
            .build();/*from   ww w.j av  a 2s . c  o m*/

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

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

License:Apache License

@Test
public void createGroup() throws Exception {
    CreateGroupRequest request = new CreateGroupRequest("newgroup", "group-description");
    String body = mapper.writeValueAsString(request);
    Request post = new Request.Builder().post(RequestBody.create(KeywhizClient.JSON, body))
            .url(testUrl("/automation/groups")).addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
            .addHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON).build();

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

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

License:Apache License

@Test
public void createGroupRedundant() throws Exception {
    CreateGroupRequest request = new CreateGroupRequest("Web", "group-description");
    String body = mapper.writeValueAsString(request);
    Request post = new Request.Builder().post(RequestBody.create(KeywhizClient.JSON, body))
            .url(testUrl("/automation/groups")).addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
            .addHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON).build();

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

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

License:Apache License

@Test
public void deleteGroup() throws Exception {
    String body = mapper.writeValueAsString(new CreateGroupRequest("short-lived", "group-description"));
    Request post = new Request.Builder().post(RequestBody.create(KeywhizClient.JSON, body))
            .url(testUrl("/automation/groups")).addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON)
            .addHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON).build();
    Response response = mutualSslClient.newCall(post).execute();
    assertThat(response.code()).isEqualTo(200);
    long groupId = mapper.readValue(response.body().string(), Group.class).getId();

    Request delete = new Request.Builder().delete().url(testUrl("/automation/groups/" + groupId)).build();
    response = mutualSslClient.newCall(delete).execute();
    assertThat(response.code()).isEqualTo(200);

    Request lookup = new Request.Builder().get().url(testUrl("/automation/groups/" + groupId))
            .addHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON).build();
    response = mutualSslClient.newCall(lookup).execute();
    assertThat(response.code()).isEqualTo(404);
}

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

License:Apache License

@Test
public void allowAccess() throws Exception {
    //Allow "Web" to access "Hacking_Password"
    Request put = new Request.Builder().put(RequestBody.create(MediaType.parse("text/plain"), ""))
            .url(testUrl("/automation/secrets/738/groups/918")).build();

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

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

License:Apache License

@Test
public void revokeAccess() throws Exception {
    //Revoke "Database_password" from "Web"
    Request delete = new Request.Builder().delete().url(testUrl("/automation/secrets/739/groups/918")).build();

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

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

License:Apache License

@Test
public void addSecrets() throws Exception {
    CreateSecretRequest request = new CreateSecretRequest("new_secret", "desc", "superSecret", true,
            ImmutableMap.of());/*  w w w.j ava  2 s .  co 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);
}

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

License:Apache License

@Test
public void addInvalidSecrets() throws Exception {
    CreateSecretRequest request = new CreateSecretRequest("empty_secret", "desc", "", true, null);
    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(422);
}

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

License:Apache License

@Test
public void addConflictingSecrets() throws Exception {
    CreateSecretRequest request = new CreateSecretRequest("dup_secret", "desc", "content", false,
            ImmutableMap.of());//  ww w.j av a 2s .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);
    response = mutualSslClient.newCall(post).execute();
    assertThat(response.code()).isEqualTo(409);
}

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

License:Apache License

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

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