use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.
the class BatchOperationTest method testInvokeIfOtherErrorOccurs.
@Test
public void testInvokeIfOtherErrorOccurs() throws FreeIpaClientException {
Map warnings = Maps.newHashMap();
List<Object> operations = Lists.newArrayList();
when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenThrow(new FreeIpaClientException("error", new JsonRpcClientException(5000, "", null)));
operations.add(UserAddOperation.create("user", "first", "last", false).getOperationParamsForBatchCall());
BatchOperation.create(operations, warnings::put, Set.of(FreeIpaErrorCodes.NOT_FOUND)).invoke(freeIpaClient);
verify(freeIpaClient).invoke(eq("batch"), anyList(), any(), any());
assertEquals(1, warnings.size());
}
use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.
the class BatchOperationTest method testInvokeIfAcceptableErrorOccurs.
@Test
public void testInvokeIfAcceptableErrorOccurs() throws FreeIpaClientException {
Map warnings = Maps.newHashMap();
List<Object> operations = Lists.newArrayList();
when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenThrow(new FreeIpaClientException("error", new JsonRpcClientException(4002, "", null)));
operations.add(UserAddOperation.create("user", "first", "last", false).getOperationParamsForBatchCall());
BatchOperation.create(operations, warnings::put, Set.of(FreeIpaErrorCodes.DUPLICATE_ENTRY)).invoke(freeIpaClient);
verify(freeIpaClient).invoke(eq("batch"), anyList(), any(), any());
assertEquals(0, warnings.size());
}
use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.
the class GroupAddOperationTest method testInvokeIfDuplicateErrorOccurs.
@Test
public void testInvokeIfDuplicateErrorOccurs() throws FreeIpaClientException {
Map warnings = Maps.newHashMap();
when(freeIpaClient.invoke(any(), anyList(), any(), any())).thenThrow(new FreeIpaClientException("error", new JsonRpcClientException(4002, "", null)));
GroupAddOperation.create(GROUP_NAME, POSIX, warnings::put).invoke(freeIpaClient);
verify(freeIpaClient).invoke(eq("group_add"), anyList(), any(), any());
assertEquals(0, warnings.size());
}
use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.
the class DnsRecordServiceTest method testARecordCreateReturnDuplicate.
@Test
public void testARecordCreateReturnDuplicate() throws FreeIpaClientException {
AddDnsARecordRequest request = new AddDnsARecordRequest();
request.setEnvironmentCrn(ENV_CRN);
request.setHostname("Asdf");
request.setIp("1.1.1.2");
request.setCreateReverse(true);
Stack stack = createStack();
when(stackService.getByEnvironmentCrnAndAccountId(ENV_CRN, ACCOUNT_ID)).thenReturn(stack);
FreeIpa freeIpa = createFreeIpa();
when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(freeIpaClient);
when(freeIpaClient.addDnsARecord(anyString(), eq(request.getHostname()), eq(request.getIp()), eq(true))).thenThrow(new FreeIpaClientException("Duplicate", new JsonRpcClientException(4002, "Duplicate reverse", null)));
Assertions.assertThrows(DnsRecordConflictException.class, () -> underTest.addDnsARecord(ACCOUNT_ID, request));
}
use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.
the class DnsRecordServiceTest method testCnameRecordAddNotFound.
@Test
public void testCnameRecordAddNotFound() throws FreeIpaClientException {
AddDnsCnameRecordRequest request = new AddDnsCnameRecordRequest();
request.setEnvironmentCrn(ENV_CRN);
request.setCname("Asdf");
request.setTargetFqdn(TARGET_FQDN);
Stack stack = createStack();
when(stackService.getByEnvironmentCrnAndAccountId(ENV_CRN, ACCOUNT_ID)).thenReturn(stack);
FreeIpa freeIpa = createFreeIpa();
when(freeIpaService.findByStack(stack)).thenReturn(freeIpa);
when(freeIpaClientFactory.getFreeIpaClientForStack(stack)).thenReturn(freeIpaClient);
when(freeIpaClient.showDnsRecord(DOMAIN, request.getCname())).thenThrow(new FreeIpaClientException("Not found", new JsonRpcClientException(FreeIpaErrorCodes.NOT_FOUND.getValue(), "Not found", null)));
underTest.addDnsCnameRecord(ACCOUNT_ID, request);
verify(freeIpaClient).addDnsCnameRecord(DOMAIN, request.getCname(), request.getTargetFqdn());
}
Aggregations