use of com.yahoo.elide.core.RequestScope 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));
}
use of com.yahoo.elide.core.RequestScope 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.core.RequestScope in project elide by yahoo.
the class LogMessageImplTest method init.
@BeforeAll
public static void init() {
final EntityDictionary dictionary = EntityDictionary.builder().build();
dictionary.bindEntity(Child.class);
dictionary.bindEntity(Parent.class);
final Child child = new Child();
child.setId(5);
final Parent parent = new Parent();
parent.setId(7);
final Child friend = new Child();
friend.setId(9);
child.setFriends(Sets.newHashSet(friend));
final RequestScope requestScope = new RequestScope(null, null, NO_VERSION, null, null, new TestUser("aaron"), null, null, UUID.randomUUID(), new ElideSettingsBuilder(null).withAuditLogger(new TestAuditLogger()).withEntityDictionary(dictionary).build());
final PersistentResource<Parent> parentRecord = new PersistentResource<>(parent, requestScope.getUUIDFor(parent), requestScope);
childRecord = new PersistentResource<>(child, parentRecord, "children", requestScope.getUUIDFor(child), requestScope);
friendRecord = new PersistentResource<>(friend, childRecord, "friends", requestScope.getUUIDFor(friend), requestScope);
}
use of com.yahoo.elide.core.RequestScope in project elide by yahoo.
the class FilteredIteratorTest method testEmptyResult.
@Test
public void testEmptyResult() throws Exception {
EntityDictionary dictionary = EntityDictionary.builder().build();
dictionary.bindEntity(Book.class);
List<Book> books = List.of();
RSQLFilterDialect filterDialect = RSQLFilterDialect.builder().dictionary(dictionary).build();
FilterExpression expression = filterDialect.parse(ClassType.of(Book.class), new HashSet<>(), "title==*bar", NO_VERSION);
RequestScope scope = new TestRequestScope(null, null, dictionary);
Iterator<Book> bookIterator = new FilteredIterator<>(expression, scope, books.iterator());
assertFalse(bookIterator.hasNext());
assertThrows(NoSuchElementException.class, () -> bookIterator.next());
}
use of com.yahoo.elide.core.RequestScope in project elide by yahoo.
the class EntityDictionaryTest method testFieldLookup.
@Test
public void testFieldLookup() throws Exception {
Book book = new Book() {
@Override
public String toString() {
return "ProxyBook";
}
};
book.setId(1234L);
Author author = new Author();
initializeEntity(book);
RequestScope scope = mock(RequestScope.class);
assertEquals("Book", getSimpleName(ClassType.of(Book.class)));
assertEquals("getEditor", findMethod(ClassType.of(Book.class), "getEditor").getName());
assertEquals("setGenre", findMethod(ClassType.of(Book.class), "setGenre", ClassType.of(String.class)).getName());
setValue(book, "genre", "Elide");
assertEquals("Elide", getValue(book, "genre", scope));
setValue(book, "authors", ImmutableSet.of(author));
assertEquals(ImmutableSet.of(author), getValue(book, "authors", scope));
assertThrows(InvalidAttributeException.class, () -> setValue(book, "badfield", "Elide"));
assertEquals("1234", getId(book));
assertTrue(isRoot(ClassType.of(Book.class)));
assertEquals(ClassType.of(Book.class), lookupBoundClass(ClassType.of(Book.class)));
assertNull(lookupBoundClass(ClassType.of(String.class)));
// check proxy lookup
assertNotEquals(ClassType.of(Book.class), book.getClass());
assertEquals(ClassType.of(Book.class), lookupBoundClass(ClassType.of(Book.class)));
assertFalse(isComputed(ClassType.of(Book.class), "genre"));
assertTrue(isComputed(ClassType.of(Book.class), "editor"));
assertTrue(isComputed(ClassType.of(Editor.class), "fullName"));
assertFalse(isComputed(ClassType.of(Editor.class), "badfield"));
assertEquals(ImmutableSet.of("awards", "genre", "language", "title"), getFieldsOfType(ClassType.of(Book.class), ClassType.of(String.class)));
assertTrue(isRelation(ClassType.of(Book.class), "editor"));
assertTrue(isAttribute(ClassType.of(Book.class), "title"));
assertEquals(Arrays.asList(ClassType.of(Book.class), ClassType.of(Author.class), ClassType.of(Editor.class), ClassType.of(Publisher.class)), walkEntityGraph(ImmutableSet.of(ClassType.of(Book.class)), x -> x));
assertTrue(hasBinding(ClassType.of(Book.class)));
assertFalse(hasBinding(ClassType.of(String.class)));
}
Aggregations