Search in sources :

Example 21 with NotFoundException

use of keywhiz.client.KeywhizClient.NotFoundException in project keywhiz by square.

the class AddActionTest method addCallsAddForGroup.

@Test
public void addCallsAddForGroup() throws Exception {
    addActionConfig.addType = Arrays.asList("group");
    addActionConfig.name = group.getName();
    when(keywhizClient.getGroupByName(group.getName())).thenThrow(new NotFoundException());
    addAction.run();
    verify(keywhizClient).createGroup(addActionConfig.name, "", ImmutableMap.of());
}
Also used : NotFoundException(keywhiz.client.KeywhizClient.NotFoundException) Test(org.junit.Test)

Example 22 with NotFoundException

use of keywhiz.client.KeywhizClient.NotFoundException in project keywhiz by square.

the class AssignActionTest method assignClientAddsClientsThatDoNotExist.

@Test
public void assignClientAddsClientsThatDoNotExist() throws Exception {
    assignActionConfig.assignType = Arrays.asList("client");
    assignActionConfig.name = "non-existent-client-name";
    assignActionConfig.group = group.getName();
    Client client = new Client(543, assignActionConfig.name, null, null, null, null, null, null, false, false);
    // Group exists
    when(keywhizClient.getGroupByName(group.getName())).thenReturn(group);
    // Client does not exist, but 2nd call returns the created client.
    when(keywhizClient.getClientByName(client.getName())).thenThrow(new NotFoundException()).thenReturn(client);
    // Client not assigned to group
    when(keywhizClient.groupDetailsForId(group.getId())).thenReturn(groupDetailResponse);
    assignAction.run();
    verify(keywhizClient).createClient(assignActionConfig.name);
    verify(keywhizClient).enrollClientInGroupByIds(client.getId(), group.getId());
}
Also used : NotFoundException(keywhiz.client.KeywhizClient.NotFoundException) Client(keywhiz.api.model.Client) KeywhizClient(keywhiz.client.KeywhizClient) Test(org.junit.Test)

Example 23 with NotFoundException

use of keywhiz.client.KeywhizClient.NotFoundException in project keywhiz by square.

the class DeleteActionTest method deleteThrowsIfDeleteClientFails.

@Test(expected = AssertionError.class)
public void deleteThrowsIfDeleteClientFails() throws Exception {
    deleteActionConfig.deleteType = Arrays.asList("client");
    deleteActionConfig.name = "nonexistent-client-name";
    when(keywhizClient.getClientByName(deleteActionConfig.name)).thenThrow(new NotFoundException());
    deleteAction.run();
}
Also used : NotFoundException(keywhiz.client.KeywhizClient.NotFoundException) Test(org.junit.Test)

Aggregations

NotFoundException (keywhiz.client.KeywhizClient.NotFoundException)23 Test (org.junit.Test)18 ByteArrayInputStream (java.io.ByteArrayInputStream)8 IOException (java.io.IOException)5 SanitizedSecret (keywhiz.api.model.SanitizedSecret)5 Client (keywhiz.api.model.Client)4 KeywhizClient (keywhiz.client.KeywhizClient)4 Group (keywhiz.api.model.Group)3 BufferedReader (java.io.BufferedReader)2 InputStreamReader (java.io.InputStreamReader)2