use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.
the class FreeipaClientTestServiceTest method testCheckUsersInGroup.
@Test
public void testCheckUsersInGroup() throws FreeIpaClientException {
JsonRpcClientException jsonRpcException = new JsonRpcClientException(FreeIpaErrorCodes.NOT_FOUND.getValue(), "group not found", null);
FreeIpaClientException notFound = new FreeIpaClientException("Invoke FreeIPA failed", jsonRpcException);
when(freeIpaClient.groupShow(OTHER_USER_OR_GROUP)).thenThrow(notFound);
when(freeIpaClient.groupShow(ADMIN_GROUP)).thenReturn(createGroup(ADMIN_GROUP, ADMIN_USER));
assertTrue(ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.checkUsersInGroup(ENV_CRN, Sets.newHashSet(ADMIN_USER), ADMIN_GROUP)));
assertFalse(ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.checkUsersInGroup(ENV_CRN, Sets.newHashSet(OTHER_USER_OR_GROUP), ADMIN_GROUP)));
assertFalse(ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.checkUsersInGroup(ENV_CRN, Sets.newHashSet(ADMIN_USER, OTHER_USER_OR_GROUP), ADMIN_GROUP)));
assertFalse(ThreadBasedUserCrnProvider.doAs(USER_CRN, () -> underTest.checkUsersInGroup(ENV_CRN, Sets.newHashSet(ADMIN_USER), OTHER_USER_OR_GROUP)));
}
use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.
the class DnsRecordServiceTest method testARecordAddEmptyModListIgnored.
@Test
public void testARecordAddEmptyModListIgnored() 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);
JsonRpcClientException noModEx = new JsonRpcClientException(FreeIpaErrorCodes.EMPTY_MODLIST.getValue(), "no modifications to be performed", null);
when(freeIpaClient.addDnsARecord(DOMAIN, request.getHostname(), request.getIp(), request.isCreateReverse())).thenThrow(new FreeIpaClientException("can't create", noModEx));
underTest.addDnsARecord(ACCOUNT_ID, request);
verify(freeIpaClient).addDnsARecord(DOMAIN, request.getHostname(), request.getIp(), request.isCreateReverse());
}
use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.
the class DnsRecordServiceTest method testARecordAddNotFound.
@Test
public void testARecordAddNotFound() 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.showDnsRecord(DOMAIN, request.getHostname())).thenThrow(new FreeIpaClientException("Not found", new JsonRpcClientException(FreeIpaErrorCodes.NOT_FOUND.getValue(), "Not found", null)));
underTest.addDnsARecord(ACCOUNT_ID, request);
verify(freeIpaClient).addDnsARecord(DOMAIN, request.getHostname(), request.getIp(), request.isCreateReverse());
}
use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.
the class FreeIpaTopologyServiceTest method testUpdateReplicationTopologyForDownscaleAndSegmentIsNotPresent.
@Test
void testUpdateReplicationTopologyForDownscaleAndSegmentIsNotPresent() throws FreeIpaClientException {
InstanceMetaData im1 = new InstanceMetaData();
InstanceMetaData im2 = new InstanceMetaData();
im1.setDiscoveryFQDN("ipaserver1.example.com");
im2.setDiscoveryFQDN("ipaserver2.example.com");
Set<InstanceMetaData> imSet = Set.of(im1, im2);
when(instanceMetaDataService.findNotTerminatedForStack(anyLong())).thenReturn(imSet);
TopologySuffix caSuffix = new TopologySuffix();
caSuffix.setCn("ca");
when(freeIpaClient.findAllTopologySuffixes()).thenReturn(List.of(caSuffix));
List<TopologySegment> topologySegments = new LinkedList<>();
TopologySegment segment = new TopologySegment();
segment.setLeftNode("ipaserver1.example.com");
segment.setRightNode("ipaserver2.example.com");
topologySegments.add(segment);
when(freeIpaClient.findTopologySegments(Mockito.anyString())).thenReturn(topologySegments);
String message = "already deleted";
when(freeIpaClient.deleteTopologySegment(Mockito.anyString(), Mockito.any())).thenThrow(new FreeIpaClientException(message, new JsonRpcClientException(NOT_FOUND, message, null)));
underTest.updateReplicationTopology(1L, Set.of("ipaserver2.example.com"), freeIpaClient);
Mockito.verify(freeIpaClient, Mockito.never()).addTopologySegment(Mockito.any(), Mockito.any());
Mockito.verify(freeIpaClient, Mockito.times(1)).deleteTopologySegment(Mockito.eq("ca"), Mockito.any());
}
use of com.googlecode.jsonrpc4j.JsonRpcClientException in project cloudbreak by hortonworks.
the class HostDeletionServiceTest method testOneAlreadyDeleted.
@Test
public void testOneAlreadyDeleted() throws FreeIpaClientException {
Set<String> hosts = Set.of("host1", "host2");
Host host1 = new Host();
host1.setFqdn("host1");
Host host2 = new Host();
host2.setFqdn("host2");
when(freeIpaClient.findAllHost()).thenReturn(Set.of(host1, host2));
String message = "already deleted";
when(freeIpaClient.deleteHost(host2.getFqdn())).thenThrow(new FreeIpaClientException(message, new JsonRpcClientException(NOT_FOUND, message, null)));
Pair<Set<String>, Map<String, String>> result = underTest.removeHosts(freeIpaClient, hosts);
assertEquals(2, result.getFirst().size());
assertEquals(0, result.getSecond().size());
assertTrue(result.getFirst().contains(host1.getFqdn()));
assertTrue(result.getFirst().contains(host2.getFqdn()));
}
Aggregations