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);
}
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);
}
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));
}
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))));
}
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)));
}
Aggregations