use of org.sakuli.exceptions.SakuliRuntimeException in project sakuli by ConSol.
the class AbstractSakuliTest method getSakuliHomeFolder.
protected String getSakuliHomeFolder() {
String packageName = "/org/sakuli/common";
Path sakuliHomeFolder = resolveResource(AbstractSakuliTest.class, packageName);
if (Files.exists(sakuliHomeFolder)) {
return sakuliHomeFolder.normalize().toAbsolutePath().toString();
}
throw new SakuliRuntimeException("Cannot load SAKULI_HOME folder! Should be normally under 'target/classes/" + packageName + "'");
}
use of org.sakuli.exceptions.SakuliRuntimeException in project sakuli by ConSol.
the class AbstractSakuliTest method getSahiFolder.
/**
* Override this method to specify a custom Sahi installation folder!
*
* @return the installation folder of Sahi
*/
protected String getSahiFolder() {
String packageName = "/sahi";
Path sahHomeFolder = resolveResource(AbstractSakuliTest.class, packageName);
if (Files.exists(sahHomeFolder)) {
return sahHomeFolder.normalize().toAbsolutePath().toString();
}
throw new SakuliRuntimeException("Cannot load SAHI_HOME folder! Should be normally under 'target/classes/" + packageName + "'");
}
use of org.sakuli.exceptions.SakuliRuntimeException in project sakuli by ConSol.
the class GearmanResultServiceImplTest method testSaveAllResultsJobSubmitFailedAddCacheResults.
@Test
public void testSaveAllResultsJobSubmitFailedAddCacheResults() 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);
GearmanClient gearmanClient = mock(GearmanClientImpl.class);
doReturn(gearmanClient).when(testling).getGearmanClient();
GearmanJobServerConnection connection = mock(GearmanJobServerConnection.class);
doReturn(connection).when(testling).getGearmanConnection(host, port);
GearmanJob job = mock(GearmanJob.class);
doReturn(job).when(testling).creatJob(any(NagiosCheckResult.class));
when(gearmanClient.addJobServer(connection)).thenReturn(true);
when(gearmanClient.submit(job)).thenThrow(new SakuliRuntimeException("Something went wrong!"));
NagiosCheckResult mockedResult1 = Mockito.mock(NagiosCheckResult.class);
NagiosCheckResult mockedResult2 = Mockito.mock(NagiosCheckResult.class);
when(gearmanCacheService.getCachedResults()).thenReturn(Arrays.asList(mockedResult1, mockedResult2));
NagiosCheckResult newResult = new NagiosCachedCheckResult(queueName, "sakuli_demo22__2015_03_07_12_59_00_00", testResult);
when(checkResultBuilder.build()).thenReturn(newResult);
doAnswer(invocationOnMock -> {
List<NagiosCheckResult> results = ((List) invocationOnMock.getArguments()[0]);
assertEquals(results.size(), 3L);
assertEquals(results.get(0), newResult);
assertEquals(results.get(1), mockedResult1);
assertEquals(results.get(2), mockedResult2);
return null;
}).when(gearmanCacheService).cacheResults(anyList());
StringBuilder sendOrder = new StringBuilder();
doAnswer(invocationOnMock -> {
Object result = invocationOnMock.getArguments()[1];
Assert.assertTrue(result instanceof NagiosCheckResult);
sendOrder.append(result.hashCode());
return invocationOnMock.callRealMethod();
}).when(testling).sendResult(any(), any());
testling.saveAllResults();
//checks
assertEquals(sendOrder.toString(), "" + mockedResult2.hashCode() + mockedResult1.hashCode() + newResult.hashCode());
verify(gearmanCacheService).cacheResults(anyList());
verify(gearmanCacheService).getCachedResults();
verify(exceptionHandler, times(3)).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.exceptions.SakuliRuntimeException in project sakuli by ConSol.
the class Icinga2RestCient method getTrustEverythingSSLContext.
private SSLContext getTrustEverythingSSLContext() {
try {
final SSLContext sslContext = SSLContext.getInstance("SSL");
// set up a TrustManager that trusts everything
sslContext.init(null, new TrustManager[] { new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
@Override
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
} }, new SecureRandom());
return sslContext;
} catch (Exception e) {
throw new SakuliRuntimeException("Unable to create SSL-Context", e);
}
}
Aggregations