Search in sources :

Example 66 with RequestScope

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));
}
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 67 with RequestScope

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);
}
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 68 with RequestScope

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);
}
Also used : PersistentResource(com.yahoo.elide.core.PersistentResource) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) Parent(example.Parent) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Child(example.Child) RequestScope(com.yahoo.elide.core.RequestScope) TestUser(com.yahoo.elide.core.security.TestUser) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 69 with 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());
}
Also used : TestRequestScope(com.yahoo.elide.core.TestRequestScope) Book(example.Book) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) RSQLFilterDialect(com.yahoo.elide.core.filter.dialect.RSQLFilterDialect) RequestScope(com.yahoo.elide.core.RequestScope) TestRequestScope(com.yahoo.elide.core.TestRequestScope) Test(org.junit.jupiter.api.Test)

Example 70 with RequestScope

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)));
}
Also used : ComputedAttribute(com.yahoo.elide.annotation.ComputedAttribute) User(example.User) ExcludedPackageLevel(example.models.packageinfo.ExcludedPackageLevel) Arrays(java.util.Arrays) Date(java.util.Date) Publisher(example.Publisher) Assertions.assertNotEquals(org.junit.jupiter.api.Assertions.assertNotEquals) Include(com.yahoo.elide.annotation.Include) Role(com.yahoo.elide.core.security.checks.prefab.Role) Employee(example.models.generics.Employee) ClassType(com.yahoo.elide.core.type.ClassType) ExcludedSubPackage(example.models.packageinfo.excluded.ExcludedSubPackage) AppendOnly(com.yahoo.elide.core.security.checks.prefab.Collections.AppendOnly) ExcludedBySuperClass(example.models.packageinfo.included.ExcludedBySuperClass) BigDecimal(java.math.BigDecimal) CoerceBean(example.CoerceBean) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Map(java.util.Map) LifeCycleHookBinding(com.yahoo.elide.annotation.LifeCycleHookBinding) FilterExpressionPath(com.yahoo.elide.annotation.FilterExpressionPath) RequestScope(com.yahoo.elide.core.RequestScope) Entity(javax.persistence.Entity) ImmutableSet(com.google.common.collect.ImmutableSet) Right(example.Right) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultClassScanner(com.yahoo.elide.core.utils.DefaultClassScanner) Collection(java.util.Collection) Set(java.util.Set) CoerceUtil(com.yahoo.elide.core.utils.coerce.CoerceUtil) Collectors(java.util.stream.Collectors) Parent(example.Parent) SecurityCheck(com.yahoo.elide.annotation.SecurityCheck) Test(org.junit.jupiter.api.Test) StrictNoTransfer(example.nontransferable.StrictNoTransfer) List(java.util.List) GeneratedValue(javax.persistence.GeneratedValue) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Annotation(java.lang.annotation.Annotation) Job(example.Job) StringId(example.StringId) Mockito.mock(org.mockito.Mockito.mock) InvalidAttributeException(com.yahoo.elide.core.exceptions.InvalidAttributeException) LifeCycleHook(com.yahoo.elide.core.lifecycle.LifeCycleHook) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Left(example.Left) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) ISO8601DateSerde(com.yahoo.elide.core.utils.coerce.converters.ISO8601DateSerde) AccessibleObject(com.yahoo.elide.core.type.AccessibleObject) HashMap(java.util.HashMap) UserCheck(com.yahoo.elide.core.security.checks.UserCheck) Author(example.Author) BookV2(example.models.versioned.BookV2) NoTransferBiDirectional(example.nontransferable.NoTransferBiDirectional) Inject(javax.inject.Inject) Editor(example.Editor) ImmutableList(com.google.common.collect.ImmutableList) FunWithPermissions(example.FunWithPermissions) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) IncludedSubPackage(example.models.packageinfo.included.IncludedSubPackage) FilterExpression(com.yahoo.elide.core.filter.expression.FilterExpression) FilterExpressionCheck(com.yahoo.elide.core.security.checks.FilterExpressionCheck) UPDATE(com.yahoo.elide.annotation.LifeCycleHookBinding.Operation.UPDATE) Id(javax.persistence.Id) Price(example.Price) AccessType(javax.persistence.AccessType) Book(example.Book) Manager(example.models.generics.Manager) IncludedPackageLevel(example.models.packageinfo.IncludedPackageLevel) RemoveOnly(com.yahoo.elide.core.security.checks.prefab.Collections.RemoveOnly) Address(example.Address) Child(example.Child) OneToOne(javax.persistence.OneToOne) ReadPermission(com.yahoo.elide.annotation.ReadPermission) Transient(javax.persistence.Transient) Type(com.yahoo.elide.core.type.Type) Collections(java.util.Collections) FieldAnnotations(example.FieldAnnotations) Exclude(com.yahoo.elide.annotation.Exclude) GeoLocation(example.GeoLocation) Book(example.Book) Author(example.Author) RequestScope(com.yahoo.elide.core.RequestScope) 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