Search in sources :

Example 1 with Validator

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

the class ConfigDataStoreTest method testUpdate.

@Test
public void testUpdate(@TempDir Path configPath) {
    String configRoot = configPath.toFile().getPath();
    Validator validator = new DynamicConfigValidator(DefaultClassScanner.getInstance(), configRoot);
    ConfigDataStore store = new ConfigDataStore(configRoot, validator);
    createFile("test", store, false);
    ConfigFile updateFile = updateFile(configRoot, store);
    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(updateFile, 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 2 with Validator

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

the class ConfigDataStoreTest method testUpdateWithPermissionError.

@Test
public void testUpdateWithPermissionError(@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;
    }
    assertThrows(UnsupportedOperationException.class, () -> updateFile(configRoot, store));
}
Also used : ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile) ConfigFile(com.yahoo.elide.modelconfig.store.models.ConfigFile) File(java.io.File) 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 3 with Validator

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

the class ConfigDataStoreTest method testCreateInvalid.

@Test
public void testCreateInvalid(@TempDir Path configPath) {
    String configRoot = configPath.toFile().getPath();
    Validator validator = new DynamicConfigValidator(DefaultClassScanner.getInstance(), configRoot);
    ConfigDataStore store = new ConfigDataStore(configRoot, validator);
    assertThrows(BadRequestException.class, () -> createInvalidFile(configRoot, store));
}
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 4 with Validator

use of com.yahoo.elide.modelconfig.validator.Validator 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 5 with Validator

use of com.yahoo.elide.modelconfig.validator.Validator 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)

Aggregations

DynamicConfigValidator (com.yahoo.elide.modelconfig.validator.DynamicConfigValidator)11 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