Search in sources :

Example 71 with RequestScope

use of com.yahoo.elide.core.RequestScope 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 72 with RequestScope

use of com.yahoo.elide.core.RequestScope 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 73 with RequestScope

use of com.yahoo.elide.core.RequestScope 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)

Example 74 with RequestScope

use of com.yahoo.elide.core.RequestScope in project elide by yahoo.

the class ConfigDataStoreTest method createInvalidFile.

protected ConfigFile createInvalidFile(String configRoot, ConfigDataStore store) {
    Supplier<String> contentProvider = () -> "{            \n" + "  tables: [{     \n" + "      name: Test\n" + "      table: test\n" + "      schema: test\n" + "      measures : [\n" + "         {\n" + "          name : measure\n" + "          type : INVALID_TYPE\n" + "          definition: 'MAX({{$measure}})'\n" + "         }\n" + "      ]      \n" + "      dimensions : [\n" + "         {\n" + "           name : dimension\n" + "           type : TEXT\n" + "           definition : '{{$dimension}}'\n" + "         }\n" + "      ]\n" + "  }]\n" + "}";
    ConfigFile newFile = ConfigFile.builder().type(TABLE).contentProvider(contentProvider).path("models/tables/test.hjson").build();
    ConfigDataStoreTransaction tx = store.beginTransaction();
    RequestScope scope = mock(RequestScope.class);
    tx.createObject(newFile, scope);
    tx.save(newFile, scope);
    tx.flush(scope);
    tx.commit(scope);
    return newFile;
}
Also used : ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile) RequestScope(com.yahoo.elide.core.RequestScope)

Example 75 with RequestScope

use of com.yahoo.elide.core.RequestScope in project elide by yahoo.

the class ConfigDataStoreTest method testMultipleFileOperations.

@Test
public void testMultipleFileOperations(@TempDir Path configPath) {
    String configRoot = configPath.toFile().getPath();
    Validator validator = new DynamicConfigValidator(DefaultClassScanner.getInstance(), configRoot);
    ConfigDataStore store = new ConfigDataStore(configRoot, validator);
    ConfigDataStoreTransaction tx = store.beginTransaction();
    RequestScope scope = mock(RequestScope.class);
    String[] tables = { "table1", "table2", "table3" };
    for (String tableName : tables) {
        Supplier<String> contentProvider = () -> String.format("{            \n" + "  tables: [{     \n" + "      name: %s\n" + "      table: test\n" + "      schema: test\n" + "      measures : [\n" + "         {\n" + "          name : measure\n" + "          type : INTEGER\n" + "          definition: 'MAX({{$measure}})'\n" + "         }\n" + "      ]      \n" + "      dimensions : [\n" + "         {\n" + "           name : dimension\n" + "           type : TEXT\n" + "           definition : '{{$dimension}}'\n" + "         }\n" + "      ]\n" + "  }]\n" + "}", tableName);
        ConfigFile newFile = ConfigFile.builder().type(TABLE).contentProvider(contentProvider).path(String.format("models/tables/%s.hjson", tableName)).build();
        tx.createObject(newFile, scope);
    }
    ConfigFile invalid = ConfigFile.builder().path("/tmp").contentProvider((() -> "Invalid")).build();
    tx.createObject(invalid, scope);
    tx.delete(invalid, scope);
    tx.flush(scope);
    tx.commit(scope);
    ConfigDataStoreTransaction readTx = store.beginReadTransaction();
    DataStoreIterable<ConfigFile> loaded = readTx.loadObjects(EntityProjection.builder().type(ClassType.of(ConfigFile.class)).build(), scope);
    List<ConfigFile> configFiles = Lists.newArrayList(loaded.iterator());
    assertEquals(3, configFiles.size());
    assertEquals("models/tables/table1.hjson", configFiles.get(0).getPath());
    assertEquals(TABLE, configFiles.get(0).getType());
    assertEquals("models/tables/table2.hjson", configFiles.get(1).getPath());
    assertEquals(TABLE, configFiles.get(1).getType());
    assertEquals("models/tables/table3.hjson", configFiles.get(2).getPath());
    assertEquals(TABLE, configFiles.get(2).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

RequestScope (com.yahoo.elide.core.RequestScope)132 Test (org.junit.jupiter.api.Test)99 PersistentResource (com.yahoo.elide.core.PersistentResource)63 TestRequestScope (com.yahoo.elide.core.TestRequestScope)28 Include (com.yahoo.elide.annotation.Include)27 Entity (javax.persistence.Entity)27 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)26 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)23 ReadPermission (com.yahoo.elide.annotation.ReadPermission)22 EntityProjection (com.yahoo.elide.core.request.EntityProjection)22 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)22 Book (example.Book)19 UpdatePermission (com.yahoo.elide.annotation.UpdatePermission)17 JsonApiDocument (com.yahoo.elide.jsonapi.models.JsonApiDocument)15 HashSet (java.util.HashSet)15 Publisher (example.Publisher)14 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)12 Author (example.Author)10 Editor (example.Editor)10 Collection (java.util.Collection)10