public Statement apply()

in src/main/java/org/apache/sling/testing/teleporter/client/ClientSideTeleporter.java [291:330]


    public Statement apply(final Statement base, final Description description) {
        customize();
        initLogger();
        if(baseUrl == null) {
            fail("base URL is not set");
        }
        
        if(serverCredentials == null || serverCredentials.isEmpty()) {
            fail("server credentials are not set");
        }
        
        if(baseUrl.endsWith("/")) {
            baseUrl = baseUrl.substring(0, baseUrl.length() - 1);
        }

        final TeleporterHttpClient httpClient = setupTeleporterHttpClient();
        
        // As this is not a ClassRule (which wouldn't map the test results correctly in an IDE)
        // we currently create and install a test bundle for every test method. It might be good
        // to optimize this, but as those test bundles are usually very small that doesn't seem
        // to be a real problem in terms of performance.
        return new Statement() {
            @Override
            public void evaluate() throws Throwable {
                
                final String bundleSymbolicName = installTestBundle(httpClient);
                final String testPath = description.getClassName() + "/" + description.getMethodName();
                try {
                    httpClient.runTests(testPath, testReadyTimeoutSeconds);
                } finally {
                    if (!preventToUninstallBundle) {
                        log.info("Uninstalling bundle '{}' from {}", bundleSymbolicName, baseUrl);
                        httpClient.uninstallBundle(bundleSymbolicName, webConsoleReadyTimeoutSeconds);
                    } else {
                        log.info("Not uninstalling bundle '{}' from {} due to according configuration", bundleSymbolicName, baseUrl);
                    }
                }
            }
        };
    }