Search in sources :

Example 21 with JsonRpcClientException

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

the class FreeIpaClientExceptionUtilV1Test method testIgnoreNotFoundWithValueWithNotFound.

@Test
public void testIgnoreNotFoundWithValueWithNotFound() throws FreeIpaClientException {
    Optional<Object> result = FreeIpaClientExceptionUtil.ignoreNotFoundExceptionWithValue(() -> {
        throw new FreeIpaClientException("Not found", new JsonRpcClientException(FreeIpaErrorCodes.NOT_FOUND.getValue(), "Not found", null));
    }, null);
    assertTrue(result.isEmpty());
}
Also used : JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) Test(org.junit.jupiter.api.Test)

Example 22 with JsonRpcClientException

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

the class GroupAddMemberOperationTest 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)));
    GroupAddMemberOperation.create(GROUP_NAME, USERS, warnings::put).invoke(freeIpaClient);
    verify(freeIpaClient).invoke(eq("group_add_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 23 with JsonRpcClientException

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

the class GroupAddOperationTest method testInvokeIfOtherErrorOccurs.

@Test
public void testInvokeIfOtherErrorOccurs() throws FreeIpaClientException {
    Map warnings = Maps.newHashMap();
    when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenThrow(new FreeIpaClientException("error", new JsonRpcClientException(5000, "", null)));
    GroupAddOperation.create(GROUP_NAME, POSIX, warnings::put).invoke(freeIpaClient);
    verify(freeIpaClient).invoke(eq("group_add"), 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 24 with JsonRpcClientException

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

the class GroupRemoveOperationTest method testInvokeIfOtherErrorOccurs.

@Test
public void testInvokeIfOtherErrorOccurs() throws FreeIpaClientException {
    Map warnings = Maps.newHashMap();
    when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenThrow(new FreeIpaClientException("error", new JsonRpcClientException(5000, "", null)));
    GroupRemoveOperation.create(GROUP_NAME, warnings::put).invoke(freeIpaClient);
    verify(freeIpaClient).invoke(eq("group_del"), 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 25 with JsonRpcClientException

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

the class UserSyncOperationsTest method testSingleErrorHandlingAcceptableErrorCode.

@Test
public void testSingleErrorHandlingAcceptableErrorCode() throws FreeIpaClientException, TimeoutException {
    Multimap<String, String> warnings = ArrayListMultimap.create();
    Set<String> users = Set.of("user1", "user2");
    ArgumentCaptor<List<Object>> flagsCaptor = ArgumentCaptor.forClass(List.class);
    ArgumentCaptor<Map<String, Object>> paramsCaptor = ArgumentCaptor.forClass(Map.class);
    when(freeIpaClient.invoke(eq("user_enable"), flagsCaptor.capture(), paramsCaptor.capture(), eq(Object.class))).thenThrow(new FreeIpaClientException("Asdf", new JsonRpcClientException(FreeIpaErrorCodes.ALREADY_ACTIVE.getValue(), "fdsa", null)));
    underTest.enableUsers(false, freeIpaClient, users, warnings::put);
    assertTrue(warnings.isEmpty());
    verifyNoInteractions(batchPartitionSizeProperties);
    verify(freeIpaClient, never()).callBatch(any(), any(), any(), any(), any());
    List<List<Object>> flagsList = flagsCaptor.getAllValues();
    assertThat(flagsList, allOf(hasItem(hasItem("user1")), hasItem(hasItem("user2"))));
    List<Map<String, Object>> paramsList = paramsCaptor.getAllValues();
    assertThat(paramsList, everyItem(aMapWithSize(0)));
    verify(interruptChecker, times(4)).throwTimeoutExIfInterrupted();
}
Also used : JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) List(java.util.List) Map(java.util.Map) 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