Search in sources :

Example 11 with AssumptionViolatedException

use of org.junit.internal.AssumptionViolatedException in project cucumber-jvm by cucumber.

the class RuntimeTest method non_strict_with_failed_junit_assumption_prior_to_junit_412.

@Test
public void non_strict_with_failed_junit_assumption_prior_to_junit_412() {
    Runtime runtime = createNonStrictRuntime();
    runtime.addError(new AssumptionViolatedException("should be treated like pending"));
    assertEquals(0x0, runtime.exitStatus());
}
Also used : AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) Test(org.junit.Test)

Example 12 with AssumptionViolatedException

use of org.junit.internal.AssumptionViolatedException in project asterixdb by apache.

the class ParserTestUtil method runTest.

protected static void runTest(Logger logger, ParserTestExecutor parserTestExecutor, String pathQueries, File queryFile, File expectedFile, File actualFile, List<String> ignore, List<String> only, String separator) throws Exception {
    final char sep = separator.charAt(0);
    try {
        String queryFileShort = queryFile.getPath().substring(pathQueries.length()).replace(sep, '/');
        if (!only.isEmpty()) {
            boolean toRun = TestHelper.isInPrefixList(only, queryFileShort);
            if (!toRun) {
                logger.info("SKIP TEST: \"" + queryFile.getPath() + "\" \"only.txt\" not empty and not in \"only.txt\".");
            }
            Assume.assumeTrue(toRun);
        }
        boolean skipped = TestHelper.isInPrefixList(ignore, queryFileShort);
        if (skipped) {
            logger.info("SKIP TEST: \"" + queryFile.getPath() + "\" in \"ignore.txt\".");
        }
        Assume.assumeTrue(!skipped);
        logger.info("RUN TEST: \"" + queryFile.getPath() + "\"");
        parserTestExecutor.testSQLPPParser(queryFile, actualFile, expectedFile);
    } catch (Exception e) {
        if (!(e instanceof AssumptionViolatedException)) {
            final String msg = "Test \"" + queryFile.getPath() + "\" FAILED!";
            logger.severe(msg);
            throw new Exception(msg, e);
        } else {
            throw e;
        }
    }
}
Also used : AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) AssumptionViolatedException(org.junit.internal.AssumptionViolatedException)

Example 13 with AssumptionViolatedException

use of org.junit.internal.AssumptionViolatedException in project asterixdb by apache.

the class OptimizerTest method test.

@Test
public void test() throws Exception {
    try {
        String queryFileShort = queryFile.getPath().substring(PATH_QUERIES.length()).replace(SEPARATOR.charAt(0), '/');
        if (!only.isEmpty()) {
            boolean toRun = TestHelper.isInPrefixList(only, queryFileShort);
            if (!toRun) {
                LOGGER.info("SKIP TEST: \"" + queryFile.getPath() + "\" \"only.txt\" not empty and not in \"only.txt\".");
            }
            Assume.assumeTrue(toRun);
        }
        boolean skipped = TestHelper.isInPrefixList(ignore, queryFileShort);
        if (skipped) {
            LOGGER.info("SKIP TEST: \"" + queryFile.getPath() + "\" in \"ignore.txt\".");
        }
        Assume.assumeTrue(!skipped);
        LOGGER.info("RUN TEST: \"" + queryFile.getPath() + "\"");
        Reader query = new BufferedReader(new InputStreamReader(new FileInputStream(queryFile), "UTF-8"));
        // Forces the creation of actualFile.
        actualFile.getParentFile().mkdirs();
        PrintWriter plan = new PrintWriter(actualFile);
        ILangCompilationProvider provider = queryFile.getName().endsWith("aql") ? aqlCompilationProvider : sqlppCompilationProvider;
        if (extensionLangCompilationProvider != null) {
            provider = extensionLangCompilationProvider;
        }
        IHyracksClientConnection hcc = integrationUtil.getHyracksClientConnection();
        AsterixJavaClient asterix = new AsterixJavaClient((ICcApplicationContext) integrationUtil.cc.getApplicationContext(), hcc, query, plan, provider, statementExecutorFactory, storageComponentProvider);
        try {
            asterix.compile(true, false, false, true, true, false, false);
        } catch (AsterixException e) {
            plan.close();
            query.close();
            throw new Exception("Compile ERROR for " + queryFile + ": " + e.getMessage(), e);
        }
        plan.close();
        query.close();
        BufferedReader readerExpected = new BufferedReader(new InputStreamReader(new FileInputStream(expectedFile), "UTF-8"));
        BufferedReader readerActual = new BufferedReader(new InputStreamReader(new FileInputStream(actualFile), "UTF-8"));
        String lineExpected, lineActual;
        int num = 1;
        try {
            while ((lineExpected = readerExpected.readLine()) != null) {
                lineActual = readerActual.readLine();
                if (lineActual == null) {
                    throw new Exception("Result for " + queryFile + " changed at line " + num + ":\n< " + lineExpected + "\n> ");
                }
                if (!lineExpected.equals(lineActual)) {
                    throw new Exception("Result for " + queryFile + " changed at line " + num + ":\n< " + lineExpected + "\n> " + lineActual);
                }
                ++num;
            }
            lineActual = readerActual.readLine();
            if (lineActual != null) {
                throw new Exception("Result for " + queryFile + " changed at line " + num + ":\n< \n> " + lineActual);
            }
            LOGGER.info("Test \"" + queryFile.getPath() + "\" PASSED!");
            actualFile.delete();
        } finally {
            readerExpected.close();
            readerActual.close();
        }
    } catch (Exception e) {
        if (!(e instanceof AssumptionViolatedException)) {
            LOGGER.severe("Test \"" + queryFile.getPath() + "\" FAILED!");
            throw new Exception("Test \"" + queryFile.getPath() + "\" FAILED!", e);
        } else {
            throw e;
        }
    }
}
Also used : IHyracksClientConnection(org.apache.hyracks.api.client.IHyracksClientConnection) InputStreamReader(java.io.InputStreamReader) AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) AsterixJavaClient(org.apache.asterix.api.java.AsterixJavaClient) FileInputStream(java.io.FileInputStream) AsterixException(org.apache.asterix.common.exceptions.AsterixException) AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) AsterixException(org.apache.asterix.common.exceptions.AsterixException) ILangCompilationProvider(org.apache.asterix.compiler.provider.ILangCompilationProvider) BufferedReader(java.io.BufferedReader) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 14 with AssumptionViolatedException

use of org.junit.internal.AssumptionViolatedException in project spock by spockframework.

the class JUnitSupervisor method error.

@Override
public int error(ErrorInfo error) {
    Throwable exception = error.getException();
    if (exception instanceof MultipleFailureException)
        return handleMultipleFailures(error);
    if (isFailedEqualityComparison(exception))
        exception = convertToComparisonFailure(exception);
    filter.filter(exception);
    Failure failure = new Failure(getCurrentDescription(), exception);
    if (exception instanceof AssumptionViolatedException) {
        // do notify JUnit listeners unless it's a data-driven iteration that's reported as one feature
        if (currentIteration == null || !currentFeature.isParameterized() || currentFeature.isReportIterations()) {
            notifier.fireTestAssumptionFailed(failure);
        }
    } else {
        masterListener.error(error);
        notifier.fireTestFailure(failure);
    }
    errorSinceLastReset = true;
    return statusFor(error);
}
Also used : MultipleFailureException(org.junit.runners.model.MultipleFailureException) AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) ComparisonFailure(org.junit.ComparisonFailure)

Example 15 with AssumptionViolatedException

use of org.junit.internal.AssumptionViolatedException in project drools by kiegroup.

the class ScenarioRunner4JUnit method runScenario.

private void runScenario(RunNotifier notifier, Scenario scenario) {
    Description childDescription = Description.createTestDescription(getClass(), scenario.getName());
    descr.addChild(childDescription);
    EachTestNotifier eachNotifier = new EachTestNotifier(notifier, childDescription);
    try {
        eachNotifier.fireTestStarted();
        // If a KieSession is not available, fail fast
        if (ksessions == null || ksessions.values().isEmpty()) {
            eachNotifier.addFailure(new NullKieSessionException("Unable to get a Session to run tests. Check the project for build errors."));
        } else {
            KieSession ksession = getKSession(scenario.getKSessions());
            if (ksession == null) {
                String ksessionName = getKSessionName(scenario.getKSessions());
                if (ksessionName == null) {
                    eachNotifier.addFailure(new NullPointerException("Test scenario runner could not find the default knowledge session."));
                } else {
                    eachNotifier.addFailure(new NullPointerException("Test Scenarios require Stateful KieSession to run."));
                }
            } else {
                final ScenarioRunner runner = new ScenarioRunner(ksession, maxRuleFirings);
                runner.run(scenario);
                if (!scenario.wasSuccessful()) {
                    StringBuilder builder = new StringBuilder();
                    for (String message : scenario.getFailureMessages()) {
                        builder.append(message).append("\n");
                    }
                    eachNotifier.addFailedAssumption(new AssumptionViolatedException(builder.toString()));
                }
                // FLUSSSSSH!
                for (FactHandle factHandle : ksession.getFactHandles()) {
                    ksession.delete(factHandle);
                }
                resetKieSession(ksession);
            }
        }
    } catch (Throwable t) {
        eachNotifier.addFailure(t);
    } finally {
        // has to always be called as per junit docs
        eachNotifier.fireTestFinished();
    }
}
Also used : Description(org.junit.runner.Description) AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) FactHandle(org.kie.api.runtime.rule.FactHandle) EachTestNotifier(org.junit.internal.runners.model.EachTestNotifier) KieSession(org.kie.api.runtime.KieSession)

Aggregations

AssumptionViolatedException (org.junit.internal.AssumptionViolatedException)29 Test (org.junit.Test)7 EachTestNotifier (org.junit.internal.runners.model.EachTestNotifier)6 Statement (org.junit.runners.model.Statement)6 Description (org.junit.runner.Description)4 URI (java.net.URI)3 Failure (org.junit.runner.notification.Failure)3 MultipleFailureException (org.junit.runners.model.MultipleFailureException)3 FileStatus (org.apache.hadoop.fs.FileStatus)2 Path (org.apache.hadoop.fs.Path)2 SuppressForbidden (com.carrotsearch.randomizedtesting.annotations.SuppressForbidden)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 PrintWriter (java.io.PrintWriter)1 Reader (java.io.Reader)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1