Search in sources :

Example 1 with JsonRpcClientException

use of com.googlecode.jsonrpc4j.JsonRpcClientException 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 JsonRpcClientException

use of com.googlecode.jsonrpc4j.JsonRpcClientException 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 JsonRpcClientException

use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.

the class SudoRuleShowOperationTest method testInvokeShouldReturnEmptyInCaseOfNotFoundException.

@Test
public void testInvokeShouldReturnEmptyInCaseOfNotFoundException() throws FreeIpaClientException {
    when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenThrow(new FreeIpaClientException("", new JsonRpcClientException(FreeIpaErrorCodes.NOT_FOUND.getValue(), null, null)));
    Optional<SudoRule> result = SudoRuleShowOperation.create(NAME).invoke(freeIpaClient);
    assertEquals(Optional.empty(), result);
    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) JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) SudoRule(com.sequenceiq.freeipa.client.model.SudoRule) Test(org.junit.jupiter.api.Test)

Example 4 with JsonRpcClientException

use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.

the class UserModOperationTest method testInvokeIfOtherErrorOccurs.

@Test
public void testInvokeIfOtherErrorOccurs() throws FreeIpaClientException {
    when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenThrow(new FreeIpaClientException("error", new JsonRpcClientException(5000, "", null)));
    assertThrows(FreeIpaClientException.class, () -> UserModOperation.create("key", new Object(), USER_NAME).invoke(freeIpaClient));
    verify(freeIpaClient).invoke(eq("user_mod"), anyList(), any(), any());
}
Also used : JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Test(org.junit.jupiter.api.Test)

Example 5 with JsonRpcClientException

use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.

the class FreeIpaClientExceptionUtilV1Test method testIsNotFoundException.

@Test
public void testIsNotFoundException() throws Exception {
    Assertions.assertFalse(FreeIpaClientExceptionUtil.isNotFoundException(new FreeIpaClientException(MESSAGE)));
    Assertions.assertFalse(FreeIpaClientExceptionUtil.isNotFoundException(new FreeIpaClientException(MESSAGE, new JsonRpcClientException(DUPLICATE_ENTRY, MESSAGE, null))));
    assertTrue(FreeIpaClientExceptionUtil.isNotFoundException(new FreeIpaClientException(MESSAGE, new JsonRpcClientException(NOT_FOUND, MESSAGE, null))));
}
Also used : JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) Test(org.junit.jupiter.api.Test)

Aggregations

JsonRpcClientException (com.googlecode.jsonrpc4j.JsonRpcClientException)43 Test (org.junit.jupiter.api.Test)40 FreeIpaClientException (com.sequenceiq.freeipa.client.FreeIpaClientException)38 Map (java.util.Map)13 RoleRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest)10 FreeIpaClient (com.sequenceiq.freeipa.client.FreeIpaClient)8 Stack (com.sequenceiq.freeipa.entity.Stack)7 Host (com.sequenceiq.freeipa.client.model.Host)6 FreeIpa (com.sequenceiq.freeipa.entity.FreeIpa)6 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 HashSet (java.util.HashSet)5 Optional (java.util.Optional)5 Role (com.sequenceiq.freeipa.client.model.Role)4 Service (com.sequenceiq.freeipa.client.model.Service)4 AddDnsARecordRequest (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsARecordRequest)3 ServiceKeytabRequest (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.ServiceKeytabRequest)3 ServiceKeytabResponse (com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.ServiceKeytabResponse)3 Privilege (com.sequenceiq.freeipa.client.model.Privilege)3 Set (java.util.Set)3 AddDnsCnameRecordRequest (com.sequenceiq.freeipa.api.v1.dns.model.AddDnsCnameRecordRequest)2