Search in sources :

Example 1 with FreeIpaClientException

use of com.sequenceiq.freeipa.client.FreeIpaClientException in project cloudbreak by hortonworks.

the class GroupRemoveMemberOperationTest method testInvokeIfErrorOccurs.

@Test
public void testInvokeIfErrorOccurs() throws FreeIpaClientException {
    Map warnings = Maps.newHashMap();
    when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenThrow(new FreeIpaClientException("error", new JsonRpcClientException(5000, "", null)));
    GroupRemoveMemberOperation.create(GROUP_NAME, USERS, warnings::put).invoke(freeIpaClient);
    verify(freeIpaClient).invoke(eq("group_remove_member"), anyList(), any(), any());
    assertEquals(1, warnings.size());
}
Also used : JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 2 with FreeIpaClientException

use of com.sequenceiq.freeipa.client.FreeIpaClientException in project cloudbreak by hortonworks.

the class GroupRemoveOperationTest method testInvokeIfNotFoundErrorOccurs.

@Test
public void testInvokeIfNotFoundErrorOccurs() throws FreeIpaClientException {
    Map warnings = Maps.newHashMap();
    when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenThrow(new FreeIpaClientException("error", new JsonRpcClientException(4001, "", null)));
    GroupRemoveOperation.create(GROUP_NAME, warnings::put).invoke(freeIpaClient);
    verify(freeIpaClient).invoke(eq("group_del"), anyList(), any(), any());
    assertEquals(0, warnings.size());
}
Also used : JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 3 with FreeIpaClientException

use of com.sequenceiq.freeipa.client.FreeIpaClientException in project cloudbreak by hortonworks.

the class SudoRuleAddOperationTest method testInvokeWithAllHostCategory.

@Test
public void testInvokeWithAllHostCategory() throws FreeIpaClientException {
    RPCResponse<Object> rpcResponse = new RPCResponse<>();
    rpcResponse.setResult(new SudoRule());
    when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenReturn(rpcResponse);
    SudoRuleAddOperation.create(NAME, true, null).invoke(freeIpaClient);
    verify(freeIpaClient).invoke(eq("sudorule_add"), argThat(argument -> argument.contains(NAME) && argument.size() == 1), argThat(argument -> "all".equals(argument.get("hostcategory")) && argument.size() == 1), eq(SudoRule.class));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Mockito.when(org.mockito.Mockito.when) SudoRule(com.sequenceiq.freeipa.client.model.SudoRule) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse) SudoRule(com.sequenceiq.freeipa.client.model.SudoRule) Test(org.junit.jupiter.api.Test)

Example 4 with FreeIpaClientException

use of com.sequenceiq.freeipa.client.FreeIpaClientException in project cloudbreak by hortonworks.

the class SudoRuleAddOperationTest method testInvoke.

@Test
public void testInvoke() throws FreeIpaClientException {
    RPCResponse<Object> rpcResponse = new RPCResponse<>();
    rpcResponse.setResult(new SudoRule());
    when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenReturn(rpcResponse);
    SudoRuleAddOperation.create(NAME, false, null).invoke(freeIpaClient);
    verify(freeIpaClient).invoke(eq("sudorule_add"), argThat(argument -> argument.contains(NAME) && argument.size() == 1), argThat(argument -> argument.isEmpty()), eq(SudoRule.class));
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Mockito.when(org.mockito.Mockito.when) SudoRule(com.sequenceiq.freeipa.client.model.SudoRule) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse) SudoRule(com.sequenceiq.freeipa.client.model.SudoRule) Test(org.junit.jupiter.api.Test)

Example 5 with FreeIpaClientException

use of com.sequenceiq.freeipa.client.FreeIpaClientException in project cloudbreak by hortonworks.

the class SudoRuleShowOperationTest method testInvokeShouldFreeIpaClientException.

@Test
public void testInvokeShouldFreeIpaClientException() throws FreeIpaClientException {
    when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenThrow(new FreeIpaClientException(null));
    assertThrows(FreeIpaClientException.class, () -> SudoRuleShowOperation.create(NAME).invoke(freeIpaClient));
    verify(freeIpaClient).invoke(eq("sudorule_show"), argThat(argument -> argument.contains(NAME) && argument.size() == 1), argThat(argument -> argument.isEmpty()), eq(SudoRule.class));
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) RPCResponse(com.sequenceiq.cloudbreak.client.RPCResponse) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Mockito.when(org.mockito.Mockito.when) SudoRule(com.sequenceiq.freeipa.client.model.SudoRule) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) FreeIpaClient(com.sequenceiq.freeipa.client.FreeIpaClient) FreeIpaErrorCodes(com.sequenceiq.freeipa.client.FreeIpaErrorCodes) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) Optional(java.util.Optional) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) SudoRule(com.sequenceiq.freeipa.client.model.SudoRule) Test(org.junit.jupiter.api.Test)

Aggregations

FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)108 Test (org.junit.jupiter.api.Test)68 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)46 JsonRpcClientException (com.googlecode.jsonrpc4j.JsonRpcClientException)41 RetryableFreeIpaClientException (com.sequenceiq.freeipa.client.RetryableFreeIpaClientException)27 Stack (com.sequenceiq.freeipa.entity.Stack)26 Map (java.util.Map)22 Optional (java.util.Optional)16 Set (java.util.Set)15 RoleRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest)14 Host (com.sequenceiq.freeipa.client.model.Host)12 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)12 HashSet (java.util.HashSet)11 List (java.util.List)11 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)11 ArgumentMatchers.argThat (org.mockito.ArgumentMatchers.argThat)11 Mock (org.mockito.Mock)11 Mockito.when (org.mockito.Mockito.when)11 MockitoExtension (org.mockito.junit.jupiter.MockitoExtension)11 Retryable (org.springframework.retry.annotation.Retryable)11