use of org.sakuli.services.forwarder.gearman.model.NagiosCachedCheckResult in project sakuli by ConSol.
the class GearmanResultServiceImplTest method testCreateJobEncryptionEnabled.
@Test
public void testCreateJobEncryptionEnabled() throws Exception {
when(properties.getServiceType()).thenReturn("passive");
final String queueName = "check_results";
when(properties.getServerQueue()).thenReturn(queueName);
final String host = "99.99.99.20";
when(properties.getServerHost()).thenReturn(host);
final int port = 4730;
when(properties.getServerPort()).thenReturn(port);
when(properties.getNagiosHost()).thenReturn("win7sakuli");
when(properties.isEncryption()).thenReturn(true);
final String secretKey = "abcdefghijklmnopqrstuvwxyz";
when(properties.getSecretKey()).thenReturn(secretKey);
GearmanJob gearmanJob = testling.creatJob(new NagiosCachedCheckResult(queueName, "sakuli_demo22__2015_03_07_12_59_00_00", testResult));
assertEquals(Aes.decrypt(gearmanJob.getData(), secretKey), testResult);
}
use of org.sakuli.services.forwarder.gearman.model.NagiosCachedCheckResult in project sakuli by ConSol.
the class GearmanResultServiceImplTest method testSaveAllResultsWrongConnectionCacheResults.
@Test
public void testSaveAllResultsWrongConnectionCacheResults() throws Exception {
when(properties.getServiceType()).thenReturn("passive");
final String queueName = "check_results";
when(properties.getServerQueue()).thenReturn(queueName);
final String host = "not-resolveable-host.de";
when(properties.getServerHost()).thenReturn(host);
final int port = 4730;
when(properties.getServerPort()).thenReturn(port);
when(properties.getNagiosHost()).thenReturn("win7sakuli");
when(properties.isCacheEnabled()).thenReturn(true);
when(checkResultBuilder.build()).thenReturn(new NagiosCachedCheckResult(queueName, "sakuli_demo22__2015_03_07_12_59_00_00", testResult));
GearmanClient gearmanClient = mock(GearmanClientImpl.class);
doReturn(gearmanClient).when(testling).getGearmanClient();
GearmanJobServerConnection connection = mock(GearmanJobServerConnection.class);
doReturn(connection).when(testling).getGearmanConnection(host, port);
when(gearmanClient.addJobServer(connection)).thenThrow(new UnresolvedAddressException());
when(gearmanCacheService.getCachedResults()).thenReturn(Collections.emptyList());
doAnswer(invocationOnMock -> {
assertEquals(((List) invocationOnMock.getArguments()[0]).size(), 1L);
return null;
}).when(gearmanCacheService).cacheResults(anyList());
doAnswer(invocationOnMock -> {
Exception exception = (Exception) invocationOnMock.getArguments()[0];
assertRegExMatch(exception.getMessage(), "Could not transfer Sakuli results to the Gearman server.*");
assertEquals(exception.getSuppressed()[0].getClass(), UnresolvedAddressException.class);
return null;
}).when(exceptionHandler).handleException(any(Throwable.class), anyBoolean());
testling.saveAllResults();
//checks
verify(gearmanCacheService).cacheResults(anyList());
verify(gearmanCacheService).getCachedResults();
verify(exceptionHandler).handleException(any(SakuliForwarderException.class), anyBoolean());
verify(testling).getGearmanClient();
verify(testling).getGearmanConnection(host, port);
verify(gearmanClient).addJobServer(connection);
verify(gearmanClient).shutdown();
}
use of org.sakuli.services.forwarder.gearman.model.NagiosCachedCheckResult in project sakuli by ConSol.
the class GearmanResultServiceImplTest method testSaveAllResultsConnectionFailedCacheResults.
@Test
public void testSaveAllResultsConnectionFailedCacheResults() throws Exception {
when(properties.getServiceType()).thenReturn("passive");
final String queueName = "check_results";
when(properties.getServerQueue()).thenReturn(queueName);
final String host = "99.99.99.20";
when(properties.getServerHost()).thenReturn(host);
final int port = 4730;
when(properties.getServerPort()).thenReturn(port);
when(properties.getNagiosHost()).thenReturn("win7sakuli");
when(properties.isCacheEnabled()).thenReturn(true);
when(checkResultBuilder.build()).thenReturn(new NagiosCachedCheckResult(queueName, "sakuli_demo22__2015_03_07_12_59_00_00", testResult));
GearmanClient gearmanClient = mock(GearmanClientImpl.class);
doReturn(gearmanClient).when(testling).getGearmanClient();
GearmanJobServerConnection connection = mock(GearmanJobServerConnection.class);
doReturn(connection).when(testling).getGearmanConnection(host, port);
when(gearmanClient.addJobServer(connection)).thenReturn(false);
when(gearmanCacheService.getCachedResults()).thenReturn(Collections.emptyList());
doAnswer(invocationOnMock -> {
assertEquals(((List) invocationOnMock.getArguments()[0]).size(), 1L);
return null;
}).when(gearmanCacheService).cacheResults(anyList());
testling.saveAllResults();
//checks
verify(gearmanCacheService).cacheResults(anyList());
verify(gearmanCacheService).getCachedResults();
verify(exceptionHandler).handleException(any(Throwable.class), eq(true));
verify(testling).getGearmanClient();
verify(testling).getGearmanConnection(host, port);
verify(gearmanClient).addJobServer(connection);
verify(gearmanClient).shutdown();
}
use of org.sakuli.services.forwarder.gearman.model.NagiosCachedCheckResult in project sakuli by ConSol.
the class GearmanResultServiceImplTest method testSaveAllResultsConnectionFailed.
@Test
public void testSaveAllResultsConnectionFailed() throws Exception {
when(properties.getServiceType()).thenReturn("passive");
final String queueName = "check_results";
when(properties.getServerQueue()).thenReturn(queueName);
final String host = "99.99.99.20";
when(properties.getServerHost()).thenReturn(host);
final int port = 4730;
when(properties.getServerPort()).thenReturn(port);
when(properties.getNagiosHost()).thenReturn("win7sakuli");
when(checkResultBuilder.build()).thenReturn(new NagiosCachedCheckResult(queueName, "sakuli_demo22__2015_03_07_12_59_00_00", testResult));
GearmanClient gearmanClient = mock(GearmanClientImpl.class);
doReturn(gearmanClient).when(testling).getGearmanClient();
GearmanJobServerConnection connection = mock(GearmanJobServerConnection.class);
doReturn(connection).when(testling).getGearmanConnection(host, port);
when(gearmanClient.addJobServer(connection)).thenReturn(false);
testling.saveAllResults();
//checks
verify(gearmanCacheService, never()).cacheResults(anyList());
verify(gearmanCacheService, never()).getCachedResults();
verify(exceptionHandler).handleException(any(Throwable.class), eq(true));
verify(testling).getGearmanClient();
verify(testling).getGearmanConnection(host, port);
verify(gearmanClient).addJobServer(connection);
verify(gearmanClient).shutdown();
}
Aggregations