Search in sources :

Example 1 with SakuliRuntimeException

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 + "'");
}
Also used : Path(java.nio.file.Path) SakuliRuntimeException(org.sakuli.exceptions.SakuliRuntimeException)

Example 2 with SakuliRuntimeException

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 + "'");
}
Also used : Path(java.nio.file.Path) SakuliRuntimeException(org.sakuli.exceptions.SakuliRuntimeException)

Example 3 with SakuliRuntimeException

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();
}
Also used : GearmanJobServerConnection(org.gearman.common.GearmanJobServerConnection) SakuliRuntimeException(org.sakuli.exceptions.SakuliRuntimeException) NagiosCheckResult(org.sakuli.services.forwarder.gearman.model.NagiosCheckResult) NagiosCachedCheckResult(org.sakuli.services.forwarder.gearman.model.NagiosCachedCheckResult) Test(org.testng.annotations.Test) BaseTest(org.sakuli.BaseTest)

Example 4 with SakuliRuntimeException

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);
    }
}
Also used : SakuliRuntimeException(org.sakuli.exceptions.SakuliRuntimeException) X509TrustManager(javax.net.ssl.X509TrustManager) SecureRandom(java.security.SecureRandom) SSLContext(javax.net.ssl.SSLContext) X509Certificate(java.security.cert.X509Certificate) SakuliRuntimeException(org.sakuli.exceptions.SakuliRuntimeException) IOException(java.io.IOException)

Aggregations

SakuliRuntimeException (org.sakuli.exceptions.SakuliRuntimeException)4 Path (java.nio.file.Path)2 IOException (java.io.IOException)1 SecureRandom (java.security.SecureRandom)1 X509Certificate (java.security.cert.X509Certificate)1 SSLContext (javax.net.ssl.SSLContext)1 X509TrustManager (javax.net.ssl.X509TrustManager)1 GearmanJobServerConnection (org.gearman.common.GearmanJobServerConnection)1 BaseTest (org.sakuli.BaseTest)1 NagiosCachedCheckResult (org.sakuli.services.forwarder.gearman.model.NagiosCachedCheckResult)1 NagiosCheckResult (org.sakuli.services.forwarder.gearman.model.NagiosCheckResult)1 Test (org.testng.annotations.Test)1