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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations