Search in sources :

Example 16 with JsonRpcClientException

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

the class KerberosMgmtRoleComponentV1Test method testAddRoleAndPrivilegesForHostWithRoleRaceCondition.

@Test
public void testAddRoleAndPrivilegesForHostWithRoleRaceCondition() throws Exception {
    Host host = new Host();
    host.setFqdn(HOST);
    RoleRequest roleRequest = new RoleRequest();
    roleRequest.setRoleName(ROLE);
    Set<String> privileges = new HashSet<>();
    privileges.add(PRIVILEGE1);
    privileges.add(PRIVILEGE2);
    roleRequest.setPrivileges(privileges);
    Role role = new Role();
    role.setCn(ROLE);
    Mockito.when(mockIpaClient.addRole(anyString())).thenThrow(new FreeIpaClientException("duplicate", new JsonRpcClientException(FreeIpaErrorCodes.DUPLICATE_ENTRY.getValue(), "duplicate", null)));
    Privilege privilege = new Privilege();
    Set<String> hosts = new HashSet<>();
    hosts.add(HOST);
    Set<String> noServices = new HashSet<>();
    Mockito.when(mockIpaClient.showRole(roleRequest.getRoleName())).thenThrow(new FreeIpaClientException("notfound", new JsonRpcClientException(NOT_FOUND, "notfound", null))).thenReturn(role);
    Mockito.when(mockIpaClient.showPrivilege(any())).thenReturn(privilege);
    Mockito.when(mockIpaClient.addRolePrivileges(any(), any())).thenReturn(role);
    Mockito.when(mockIpaClient.addRoleMember(any(), any(), any(), any(), any(), any())).thenReturn(role);
    underTest.addRoleAndPrivileges(Optional.empty(), Optional.of(host), roleRequest, mockIpaClient);
    Mockito.verify(mockIpaClient).addRole(ROLE);
    Mockito.verify(mockIpaClient).addRolePrivileges(ROLE, privileges);
    Mockito.verify(mockIpaClient).addRoleMember(ROLE, null, null, hosts, null, noServices);
}
Also used : Role(com.sequenceiq.freeipa.client.model.Role) JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Host(com.sequenceiq.freeipa.client.model.Host) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Privilege(com.sequenceiq.freeipa.client.model.Privilege) RoleRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 17 with JsonRpcClientException

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

the class KerberosMgmtRoleComponentV1Test method testAddRoleAndPrivilegesForHostWithRole.

@Test
public void testAddRoleAndPrivilegesForHostWithRole() throws Exception {
    Host host = new Host();
    host.setFqdn(HOST);
    RoleRequest roleRequest = new RoleRequest();
    roleRequest.setRoleName(ROLE);
    Set<String> privileges = new HashSet<>();
    privileges.add(PRIVILEGE1);
    privileges.add(PRIVILEGE2);
    roleRequest.setPrivileges(privileges);
    Role role = new Role();
    role.setCn(ROLE);
    Mockito.when(mockIpaClient.addRole(anyString())).thenReturn(role);
    Privilege privilege = new Privilege();
    Set<String> hosts = new HashSet<>();
    hosts.add(HOST);
    Set<String> noServices = new HashSet<>();
    Mockito.when(mockIpaClient.showRole(roleRequest.getRoleName())).thenThrow(new FreeIpaClientException("notfound", new JsonRpcClientException(NOT_FOUND, "notfound", null))).thenReturn(role);
    Mockito.when(mockIpaClient.showPrivilege(any())).thenReturn(privilege);
    Mockito.when(mockIpaClient.addRolePrivileges(any(), any())).thenReturn(role);
    Mockito.when(mockIpaClient.addRoleMember(any(), any(), any(), any(), any(), any())).thenReturn(role);
    underTest.addRoleAndPrivileges(Optional.empty(), Optional.of(host), roleRequest, mockIpaClient);
    Mockito.verify(mockIpaClient).addRole(ROLE);
    Mockito.verify(mockIpaClient).addRolePrivileges(ROLE, privileges);
    Mockito.verify(mockIpaClient).addRoleMember(ROLE, null, null, hosts, null, noServices);
}
Also used : Role(com.sequenceiq.freeipa.client.model.Role) JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Host(com.sequenceiq.freeipa.client.model.Host) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Privilege(com.sequenceiq.freeipa.client.model.Privilege) RoleRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 18 with JsonRpcClientException

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

the class KerberosMgmtRoleComponentV1Test method testAddRoleAndPrivilegesForHostWithException.

@Test
public void testAddRoleAndPrivilegesForHostWithException() throws Exception {
    Host host = new Host();
    host.setFqdn(HOST);
    RoleRequest roleRequest = new RoleRequest();
    roleRequest.setRoleName(ROLE);
    Set<String> privileges = new HashSet<>();
    privileges.add(PRIVILEGE1);
    privileges.add(PRIVILEGE2);
    roleRequest.setPrivileges(privileges);
    Role role = new Role();
    role.setCn(ROLE);
    Mockito.when(mockIpaClient.addRole(anyString())).thenThrow(new FreeIpaClientException("expected"));
    Mockito.when(mockIpaClient.showRole(roleRequest.getRoleName())).thenThrow(new FreeIpaClientException("notfound", new JsonRpcClientException(NOT_FOUND, "notfound", null))).thenReturn(role);
    assertThrows(FreeIpaClientException.class, () -> underTest.addRoleAndPrivileges(Optional.empty(), Optional.of(host), roleRequest, mockIpaClient));
}
Also used : Role(com.sequenceiq.freeipa.client.model.Role) JsonRpcClientException(com.googlecode.jsonrpc4j.JsonRpcClientException) FreeIpaClientException(com.sequenceiq.freeipa.client.FreeIpaClientException) Host(com.sequenceiq.freeipa.client.model.Host) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RoleRequest(com.sequenceiq.freeipa.api.v1.kerberosmgmt.model.RoleRequest) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 19 with JsonRpcClientException

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

the class FreeIpaClientExceptionUtilV1Test method testIsDuplicateEntryException.

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

Example 20 with JsonRpcClientException

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

the class FreeIpaClientExceptionUtilV1Test method testIsExceptionWithErrorCode.

@Test
public void testIsExceptionWithErrorCode() throws Exception {
    Assertions.assertFalse(FreeIpaClientExceptionUtil.isExceptionWithErrorCode(new FreeIpaClientException(MESSAGE, new IllegalStateException(MESSAGE)), Set.of(FreeIpaErrorCodes.DUPLICATE_ENTRY)));
    Assertions.assertFalse(FreeIpaClientExceptionUtil.isExceptionWithErrorCode(new FreeIpaClientException(MESSAGE, new JsonRpcClientException(NOT_FOUND, MESSAGE, null)), Set.of(FreeIpaErrorCodes.DUPLICATE_ENTRY)));
    assertTrue(FreeIpaClientExceptionUtil.isExceptionWithErrorCode(new FreeIpaClientException(MESSAGE, new JsonRpcClientException(DUPLICATE_ENTRY, MESSAGE, null)), Set.of(FreeIpaErrorCodes.DUPLICATE_ENTRY)));
    assertTrue(FreeIpaClientExceptionUtil.isExceptionWithErrorCode(new FreeIpaClientException(MESSAGE, new JsonRpcClientException(DUPLICATE_ENTRY, MESSAGE, null)), Set.of(FreeIpaErrorCodes.DUPLICATE_ENTRY, FreeIpaErrorCodes.COMMAND_ERROR)));
}
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