Search in sources :

Example 6 with DynamicConfigValidator

use of com.yahoo.elide.modelconfig.validator.DynamicConfigValidator in project elide by yahoo.

the class ConfigDataStoreTest method testCreateValidateOnly.

@Test
public void testCreateValidateOnly(@TempDir Path configPath) {
    String configRoot = configPath.toFile().getPath();
    Validator validator = new DynamicConfigValidator(DefaultClassScanner.getInstance(), configRoot);
    ConfigDataStore store = new ConfigDataStore(configRoot, validator);
    ConfigDataStoreTransaction readTx = store.beginReadTransaction();
    RequestScope scope = mock(RequestScope.class);
    ConfigFile loaded = readTx.loadObject(EntityProjection.builder().type(ClassType.of(ConfigFile.class)).build(), toId("models/tables/test.hjson", NO_VERSION), scope);
    assertNull(loaded);
}
Also used : ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile) RequestScope(com.yahoo.elide.core.RequestScope) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Validator(com.yahoo.elide.modelconfig.validator.Validator) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Test(org.junit.jupiter.api.Test)

Example 7 with DynamicConfigValidator

use of com.yahoo.elide.modelconfig.validator.DynamicConfigValidator in project elide by yahoo.

the class ConfigDataStoreTest method testCreateReadOnly.

@Test
public void testCreateReadOnly() {
    // This path is read only (Classpath)...
    String configRoot = "src/test/resources/validator/valid";
    Validator validator = new DynamicConfigValidator(DefaultClassScanner.getInstance(), configRoot);
    ConfigDataStore store = new ConfigDataStore(configRoot, validator);
    assertThrows(UnsupportedOperationException.class, () -> createFile("test", store, false));
}
Also used : DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Validator(com.yahoo.elide.modelconfig.validator.Validator) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Test(org.junit.jupiter.api.Test)

Example 8 with DynamicConfigValidator

use of com.yahoo.elide.modelconfig.validator.DynamicConfigValidator in project elide by yahoo.

the class ConfigDataStoreTest method testCreate.

@Test
public void testCreate(@TempDir Path configPath) {
    String configRoot = configPath.toFile().getPath();
    Validator validator = new DynamicConfigValidator(DefaultClassScanner.getInstance(), configRoot);
    ConfigDataStore store = new ConfigDataStore(configRoot, validator);
    ConfigFile newFile = createFile("test", store, false);
    ConfigDataStoreTransaction readTx = store.beginReadTransaction();
    RequestScope scope = mock(RequestScope.class);
    ConfigFile loaded = readTx.loadObject(EntityProjection.builder().type(ClassType.of(ConfigFile.class)).build(), toId("models/tables/test.hjson", NO_VERSION), scope);
    assertTrue(compare(newFile, loaded));
}
Also used : ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile) RequestScope(com.yahoo.elide.core.RequestScope) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Validator(com.yahoo.elide.modelconfig.validator.Validator) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Test(org.junit.jupiter.api.Test)

Example 9 with DynamicConfigValidator

use of com.yahoo.elide.modelconfig.validator.DynamicConfigValidator in project elide by yahoo.

the class ConfigDataStoreTest method testDeleteWithPermissionError.

@Test
public void testDeleteWithPermissionError(@TempDir Path configPath) {
    String configRoot = configPath.toFile().getPath();
    Validator validator = new DynamicConfigValidator(DefaultClassScanner.getInstance(), configRoot);
    ConfigDataStore store = new ConfigDataStore(configRoot, validator);
    ConfigFile createdFile = createFile("test", store, false);
    String createdFilePath = Path.of(configPath.toFile().getPath(), createdFile.getPath()).toFile().getPath();
    File file = new File(createdFilePath);
    boolean blockFailed = blockWrites(file);
    if (blockFailed) {
        // We can't actually test because setting permissions isn't working.
        return;
    }
    ConfigDataStoreTransaction tx = store.beginTransaction();
    RequestScope scope = mock(RequestScope.class);
    assertThrows(UnsupportedOperationException.class, () -> tx.delete(createdFile, scope));
}
Also used : ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile) ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile) File(java.io.File) RequestScope(com.yahoo.elide.core.RequestScope) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Validator(com.yahoo.elide.modelconfig.validator.Validator) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Test(org.junit.jupiter.api.Test)

Example 10 with DynamicConfigValidator

use of com.yahoo.elide.modelconfig.validator.DynamicConfigValidator in project elide by yahoo.

the class ConfigDataStoreTest method testLoadObjects.

@Test
public void testLoadObjects() {
    String configRoot = "src/test/resources/validator/valid";
    Validator validator = new DynamicConfigValidator(DefaultClassScanner.getInstance(), configRoot);
    ConfigDataStore store = new ConfigDataStore(configRoot, validator);
    ConfigDataStoreTransaction tx = store.beginReadTransaction();
    RequestScope scope = mock(RequestScope.class);
    DataStoreIterable<ConfigFile> loaded = tx.loadObjects(EntityProjection.builder().type(ClassType.of(ConfigFile.class)).build(), scope);
    List<ConfigFile> configFiles = Lists.newArrayList(loaded.iterator());
    Supplier<String> contentProvider = () -> "{\n" + "  dbconfigs:\n" + "  [\n" + "    {\n" + "      name: MyDB2Connection\n" + "      url: jdbc:db2:localhost:50000/testdb\n" + "      driver: COM.ibm.db2.jdbc.net.DB2Driver\n" + "      user: guestdb2\n" + "      dialect: com.yahoo.elide.datastores.aggregation.queryengines.sql.dialects.impl.PrestoDBDialect\n" + "      propertyMap:\n" + "      {\n" + "        hibernate.show_sql: true\n" + "        hibernate.default_batch_fetch_size: 100.1\n" + "        hibernate.hbm2ddl.auto: create\n" + "      }\n" + "    }\n" + "    {\n" + "      name: MySQLConnection\n" + "      url: jdbc:mysql://localhost/testdb?serverTimezone=UTC\n" + "      driver: com.mysql.jdbc.Driver\n" + "      user: guestmysql\n" + "      dialect: com.yahoo.elide.datastores.aggregation.queryengines.sql.dialects.impl.HiveDialect\n" + "    }\n" + "  ]\n" + "}\n";
    assertEquals(10, configFiles.size());
    assertTrue(compare(ConfigFile.builder().version("").type(ConfigFile.ConfigFileType.DATABASE).contentProvider(contentProvider).path("db/sql/multiple_db_no_variables.hjson").build(), configFiles.get(1)));
    assertEquals("db/sql/multiple_db.hjson", configFiles.get(0).getPath());
    assertEquals(DATABASE, configFiles.get(0).getType());
    assertEquals("db/sql/single_db.hjson", configFiles.get(2).getPath());
    assertEquals(DATABASE, configFiles.get(2).getType());
    assertEquals("db/variables.hjson", configFiles.get(3).getPath());
    assertEquals(VARIABLE, configFiles.get(3).getType());
    assertEquals("models/namespaces/player.hjson", configFiles.get(4).getPath());
    assertEquals(NAMESPACE, configFiles.get(4).getType());
    assertEquals("models/security.hjson", configFiles.get(5).getPath());
    assertEquals(SECURITY, configFiles.get(5).getType());
    assertEquals("models/tables/player_stats.hjson", configFiles.get(6).getPath());
    assertEquals(TABLE, configFiles.get(6).getType());
    assertEquals("models/tables/player_stats_extends.hjson", configFiles.get(7).getPath());
    assertEquals(TABLE, configFiles.get(7).getType());
    assertEquals("models/tables/referred_model.hjson", configFiles.get(8).getPath());
    assertEquals(TABLE, configFiles.get(8).getType());
    assertEquals("models/variables.hjson", configFiles.get(9).getPath());
    assertEquals(VARIABLE, configFiles.get(9).getType());
}
Also used : ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile) RequestScope(com.yahoo.elide.core.RequestScope) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Validator(com.yahoo.elide.modelconfig.validator.Validator) DynamicConfigValidator(com.yahoo.elide.modelconfig.validator.DynamicConfigValidator) Test(org.junit.jupiter.api.Test)

Aggregations

DynamicConfigValidator (com.yahoo.elide.modelconfig.validator.DynamicConfigValidator)15 Validator (com.yahoo.elide.modelconfig.validator.Validator)11 Test (org.junit.jupiter.api.Test)11 ConfigFile (com.yahoo.elide.modelconfig.store.models.ConfigFile)9 RequestScope (com.yahoo.elide.core.RequestScope)7 File (java.io.File)3 DefaultQueryValidator (com.yahoo.elide.datastores.aggregation.DefaultQueryValidator)1 MetaDataStore (com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore)1 DefaultQueryPlanMerger (com.yahoo.elide.datastores.aggregation.query.DefaultQueryPlanMerger)1 SQLQueryEngine (com.yahoo.elide.datastores.aggregation.queryengines.sql.SQLQueryEngine)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 ConditionalOnExpression (org.springframework.boot.autoconfigure.condition.ConditionalOnExpression)1 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)1 Bean (org.springframework.context.annotation.Bean)1 Scope (org.springframework.context.annotation.Scope)1