Search in sources :

Example 1 with CreateGroupRequest

use of keywhiz.api.CreateGroupRequest in project keywhiz by square.

the class AutomationGroupResourceTest method createNewGroup.

@Test
public void createNewGroup() {
    Group group = new Group(50, "testGroup", "testing group", now, "automation client", now, "automation client", ImmutableMap.of("app", "keywhiz"));
    CreateGroupRequest request = new CreateGroupRequest("testGroup", null, null);
    when(groupDAO.getGroup("testGroup")).thenReturn(Optional.empty());
    when(groupDAO.createGroup(group.getName(), automation.getName(), "", ImmutableMap.of())).thenReturn(500L);
    when(groupDAO.getGroupById(500L)).thenReturn(Optional.of(group));
    Group responseGroup = resource.createGroup(automation, request);
    assertThat(responseGroup).isEqualTo(group);
}
Also used : Group(keywhiz.api.model.Group) CreateGroupRequest(keywhiz.api.CreateGroupRequest) Test(org.junit.Test)

Example 2 with CreateGroupRequest

use of keywhiz.api.CreateGroupRequest in project keywhiz by square.

the class AutomationGroupResourceIntegrationTest method deleteGroup.

@Test
public void deleteGroup() throws Exception {
    String body = mapper.writeValueAsString(new CreateGroupRequest("short-lived", "group-description", ImmutableMap.of("app", "short")));
    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);
}
Also used : Response(okhttp3.Response) GroupDetailResponse(keywhiz.api.GroupDetailResponse) Group(keywhiz.api.model.Group) CreateGroupRequest(keywhiz.api.CreateGroupRequest) Request(okhttp3.Request) CreateGroupRequest(keywhiz.api.CreateGroupRequest) Test(org.junit.Test)

Example 3 with CreateGroupRequest

use of keywhiz.api.CreateGroupRequest in project keywhiz by square.

the class KeywhizClient method createGroup.

public GroupDetailResponse createGroup(String name, String description, ImmutableMap<String, String> metadata) throws IOException {
    checkArgument(!name.isEmpty());
    String response = httpPost(baseUrl.resolve("/admin/groups"), new CreateGroupRequest(name, description, metadata));
    return mapper.readValue(response, GroupDetailResponse.class);
}
Also used : CreateGroupRequest(keywhiz.api.CreateGroupRequest)

Example 4 with CreateGroupRequest

use of keywhiz.api.CreateGroupRequest in project keywhiz by square.

the class AutomationGroupResourceIntegrationTest method createGroup.

@Test
public void createGroup() throws Exception {
    CreateGroupRequest request = new CreateGroupRequest("newgroup", "group-description", ImmutableMap.of("app", "new"));
    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);
}
Also used : Response(okhttp3.Response) GroupDetailResponse(keywhiz.api.GroupDetailResponse) CreateGroupRequest(keywhiz.api.CreateGroupRequest) Request(okhttp3.Request) CreateGroupRequest(keywhiz.api.CreateGroupRequest) Test(org.junit.Test)

Example 5 with CreateGroupRequest

use of keywhiz.api.CreateGroupRequest in project keywhiz by square.

the class AutomationGroupResourceIntegrationTest method createGroupRedundant.

@Test
public void createGroupRedundant() throws Exception {
    CreateGroupRequest request = new CreateGroupRequest("Web", "group-description", ImmutableMap.of("app", "Web"));
    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);
}
Also used : Response(okhttp3.Response) GroupDetailResponse(keywhiz.api.GroupDetailResponse) CreateGroupRequest(keywhiz.api.CreateGroupRequest) Request(okhttp3.Request) CreateGroupRequest(keywhiz.api.CreateGroupRequest) Test(org.junit.Test)

Aggregations

CreateGroupRequest (keywhiz.api.CreateGroupRequest)6 Request (okhttp3.Request)4 Test (org.junit.Test)4 GroupDetailResponse (keywhiz.api.GroupDetailResponse)3 Response (okhttp3.Response)3 Group (keywhiz.api.model.Group)2 CreateSecretRequest (keywhiz.api.CreateSecretRequest)1