Search in sources :

Example 51 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project xtext-core by eclipse.

the class AbstractScenarioRunner method methodBlock.

@Override
protected Statement methodBlock(final FrameworkMethod method) {
    IInjectorProvider injectorProvider = getOrCreateInjectorProvider();
    final IRegistryConfigurator registryConfigurator = (IRegistryConfigurator) injectorProvider;
    registryConfigurator.setupRegistry();
    final Statement methodBlock = superMethodBlock(method);
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            try {
                try {
                    methodBlock.evaluate();
                    throw new AssumptionViolatedException("Method " + method.getName() + " did parse any input");
                } finally {
                    registryConfigurator.restoreRegistry();
                }
            } catch (TestDataCarrier testData) {
                process(testData.getData());
            }
        }
    };
}
Also used : IInjectorProvider(org.eclipse.xtext.testing.IInjectorProvider) AssumptionViolatedException(org.junit.AssumptionViolatedException) Statement(org.junit.runners.model.Statement) IRegistryConfigurator(org.eclipse.xtext.testing.IRegistryConfigurator)

Example 52 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project xtext-core by eclipse.

the class AbstractParallelScenarioRunner method prepareMethodBlock.

protected Statement prepareMethodBlock(final FrameworkMethod method, final RunNotifier notifier) {
    final Statement methodBlock = superMethodBlock(method);
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            try {
                methodBlock.evaluate();
                Description description = describeChild(method);
                try {
                    notifier.fireTestStarted(description);
                    notifier.fireTestAssumptionFailed(new Failure(description, new AssumptionViolatedException("Method " + method.getName() + " did parse any input")));
                } finally {
                    notifier.fireTestFinished(description);
                }
            } catch (TestDataCarrier testData) {
                AbstractParallelScenarioRunner.this.testData.put(method, testData.getData());
            }
        }
    };
}
Also used : Description(org.junit.runner.Description) AssumptionViolatedException(org.junit.AssumptionViolatedException) Statement(org.junit.runners.model.Statement) Failure(org.junit.runner.notification.Failure)

Example 53 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project sonarqube by SonarSource.

the class CoreTestDb method init.

private CoreTestDb init(@Nullable String schemaPath, boolean databaseToUpper) {
    Consumer<Settings> noExtraSettingsLoaded = settings -> {
    };
    Function<Settings, Database> databaseCreator = settings -> {
        String dialect = settings.getString("sonar.jdbc.dialect");
        // test relying on CoreTestDb can only run on H2
        if (dialect != null && !"h2".equals(dialect)) {
            throw new AssumptionViolatedException("This test is intended to be run on H2 only");
        }
        String name = "h2Tests-" + (schemaPath == null ? "empty" : DigestUtils.md5Hex(schemaPath));
        if (!databaseToUpper) {
            name = name + ";DATABASE_TO_UPPER=FALSE";
        }
        name = name + ";NON_KEYWORDS=VALUE";
        return new CoreH2Database(name);
    };
    Consumer<Database> databaseInitializer = database -> {
        if (schemaPath == null) {
            return;
        }
        ((CoreH2Database) database).executeScript(schemaPath);
    };
    BiConsumer<Database, Boolean> noPostStartAction = (db, created) -> {
    };
    init(noExtraSettingsLoaded, databaseCreator, databaseInitializer, noPostStartAction);
    return this;
}
Also used : AssumptionViolatedException(org.junit.AssumptionViolatedException) Settings(org.sonar.api.config.internal.Settings) Connection(java.sql.Connection) MapSettings(org.sonar.api.config.internal.MapSettings) Function(java.util.function.Function) Consumer(java.util.function.Consumer) Loggers(org.sonar.api.utils.log.Loggers) SQLException(java.sql.SQLException) JDBC_USERNAME(org.sonar.process.ProcessProperties.Property.JDBC_USERNAME) ResultSet(java.sql.ResultSet) Objects.requireNonNull(java.util.Objects.requireNonNull) Statement(java.sql.Statement) BiConsumer(java.util.function.BiConsumer) DataSource(javax.sql.DataSource) DigestUtils(org.apache.commons.codec.digest.DigestUtils) SqTables(org.sonar.db.version.SqTables) Nullable(javax.annotation.Nullable) Logger(org.sonar.api.utils.log.Logger) AssumptionViolatedException(org.junit.AssumptionViolatedException) Settings(org.sonar.api.config.internal.Settings) MapSettings(org.sonar.api.config.internal.MapSettings)

Example 54 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project sonarqube by SonarSource.

the class TestDbImpl method init.

private void init(@Nullable String schemaPath, MyBatisConfExtension[] confExtensions) {
    Consumer<Settings> loadOrchestratorSettings = OrchestratorSettingsUtils::loadOrchestratorSettings;
    Function<Settings, Database> databaseCreator = settings -> {
        String dialect = settings.getString("sonar.jdbc.dialect");
        if (dialect != null && !"h2".equals(dialect)) {
            return new DefaultDatabase(new LogbackHelper(), settings);
        }
        return SQDatabase.newH2Database("h2Tests" + DigestUtils.md5Hex(StringUtils.defaultString(schemaPath)), schemaPath == null);
    };
    Consumer<Database> schemaPathExecutor = database -> {
        if (schemaPath == null) {
            return;
        }
        // scripts are assumed to be using H2 specific syntax, ignore the test if not on H2
        if (!database.getDialect().getId().equals("h2")) {
            database.stop();
            throw new AssumptionViolatedException("This test is intended to be run on H2 only");
        }
        ((SQDatabase) database).executeScript(schemaPath);
    };
    BiConsumer<Database, Boolean> createMyBatis = (db, created) -> myBatis = newMyBatis(db, confExtensions);
    init(loadOrchestratorSettings, databaseCreator, schemaPathExecutor, createMyBatis);
}
Also used : Arrays(java.util.Arrays) StringUtils(org.apache.commons.lang.StringUtils) AssumptionViolatedException(org.junit.AssumptionViolatedException) Settings(org.sonar.api.config.internal.Settings) H2(org.sonar.db.dialect.H2) Set(java.util.Set) HashMap(java.util.HashMap) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) DigestUtils(org.apache.commons.codec.digest.DigestUtils) LogbackHelper(org.sonar.process.logging.LogbackHelper) Nullable(javax.annotation.Nullable) LogbackHelper(org.sonar.process.logging.LogbackHelper) AssumptionViolatedException(org.junit.AssumptionViolatedException) Settings(org.sonar.api.config.internal.Settings)

Example 55 with AssumptionViolatedException

use of org.junit.AssumptionViolatedException in project xtext-eclipse by eclipse.

the class AbstractParallelScenarioRunner method prepareMethodBlock.

protected Statement prepareMethodBlock(final FrameworkMethod method, final RunNotifier notifier) {
    final Statement methodBlock = superMethodBlock(method);
    return new Statement() {

        @Override
        public void evaluate() throws Throwable {
            try {
                methodBlock.evaluate();
                Description description = describeChild(method);
                try {
                    notifier.fireTestStarted(description);
                    notifier.fireTestAssumptionFailed(new Failure(description, new AssumptionViolatedException("Method " + method.getName() + " did parse any input")));
                } finally {
                    notifier.fireTestFinished(description);
                }
            } catch (TestDataCarrier testData) {
                AbstractParallelScenarioRunner.this.testData.put(method, testData.getData());
            }
        }
    };
}
Also used : Description(org.junit.runner.Description) AssumptionViolatedException(org.junit.AssumptionViolatedException) Statement(org.junit.runners.model.Statement) Failure(org.junit.runner.notification.Failure)

Aggregations

AssumptionViolatedException (org.junit.AssumptionViolatedException)79 Test (org.junit.Test)26 IOException (java.io.IOException)16 Statement (org.junit.runners.model.Statement)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Method (java.lang.reflect.Method)6 Set (java.util.Set)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 File (java.io.File)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 ZipEntry (java.util.zip.ZipEntry)5 ZipOutputStream (java.util.zip.ZipOutputStream)5 InputStream (java.io.InputStream)4 HashSet (java.util.HashSet)4 ZipInputStream (java.util.zip.ZipInputStream)4 FilterInputStream (java.io.FilterInputStream)3 UnknownHostException (java.net.UnknownHostException)3 JarInputStream (java.util.jar.JarInputStream)3 Configuration (org.apache.flink.configuration.Configuration)3 IInjectorProvider (org.eclipse.xtext.junit4.IInjectorProvider)3