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);
}
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));
}
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));
}
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));
}
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());
}
Aggregations