Search in sources :

Example 36 with EntityDictionary

use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.

the class PathTest method testIsComputed.

@Test
public void testIsComputed() {
    EntityDictionary dictionary = EntityDictionary.builder().build();
    dictionary.bindEntity(Book.class);
    dictionary.bindEntity(Editor.class);
    Path computedRelationshipPath = new Path(List.of(new Path.PathElement(Book.class, Editor.class, "editor"), new Path.PathElement(Editor.class, String.class, "firstName")));
    Path computedAttributePath = new Path(List.of(new Path.PathElement(Editor.class, String.class, "fullName")));
    Path attributePath = new Path(List.of(new Path.PathElement(Book.class, String.class, "title")));
    assertTrue(computedRelationshipPath.isComputed(dictionary));
    assertTrue(computedAttributePath.isComputed(dictionary));
    assertFalse(attributePath.isComputed(dictionary));
}
Also used : EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Test(org.junit.jupiter.api.Test)

Example 37 with EntityDictionary

use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.

the class PersistenceResourceTestSetup method initDictionary.

protected static EntityDictionary initDictionary() {
    EntityDictionary dictionary = TestDictionary.getTestDictionary();
    dictionary.bindEntity(UpdateAndCreate.class);
    dictionary.bindEntity(Author.class);
    dictionary.bindEntity(Book.class);
    dictionary.bindEntity(Publisher.class);
    dictionary.bindEntity(Child.class);
    dictionary.bindEntity(Parent.class);
    dictionary.bindEntity(FunWithPermissions.class);
    dictionary.bindEntity(Job.class);
    dictionary.bindEntity(Left.class);
    dictionary.bindEntity(Right.class);
    dictionary.bindEntity(NoReadEntity.class);
    dictionary.bindEntity(NoDeleteEntity.class);
    dictionary.bindEntity(NoUpdateEntity.class);
    dictionary.bindEntity(NoCreateEntity.class);
    dictionary.bindEntity(NoShareEntity.class);
    dictionary.bindEntity(example.User.class);
    dictionary.bindEntity(FirstClassFields.class);
    dictionary.bindEntity(MapColorShape.class);
    dictionary.bindEntity(PersistentResourceTest.ChangeSpecModel.class);
    dictionary.bindEntity(PersistentResourceTest.ChangeSpecChild.class);
    dictionary.bindEntity(Invoice.class);
    dictionary.bindEntity(LineItem.class);
    dictionary.bindEntity(ComputedBean.class);
    dictionary.bindEntity(ContainerWithPackageShare.class);
    dictionary.bindEntity(ShareableWithPackageShare.class);
    dictionary.bindEntity(NoTransferBiDirectional.class);
    dictionary.bindEntity(StrictNoTransfer.class);
    dictionary.bindEntity(Untransferable.class);
    dictionary.bindEntity(Company.class);
    dictionary.bindTrigger(Book.class, "price", LifeCycleHookBinding.Operation.UPDATE, LifeCycleHookBinding.TransactionPhase.PRESECURITY, bookUpdatePrice);
    return dictionary;
}
Also used : EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary)

Example 38 with EntityDictionary

use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.

the class RequestScopeTest method testNewObjectsForInheritedTypes.

@Test
public void testNewObjectsForInheritedTypes() throws Exception {
    @Entity
    @Include(rootLevel = false)
    class MyBaseClass {

        @Id
        public long id;
    }
    @Entity
    @Include(rootLevel = false)
    class MyInheritedClass extends MyBaseClass {

        public String myField;
    }
    EntityDictionary dictionary = EntityDictionary.builder().build();
    dictionary.bindEntity(MyBaseClass.class);
    dictionary.bindEntity(MyInheritedClass.class);
    RequestScope requestScope = new RequestScope(null, "/", NO_VERSION, null, null, null, null, null, UUID.randomUUID(), new ElideSettingsBuilder(null).withEntityDictionary(dictionary).build());
    String myId = "myId";
    // Test that a new inherited class is counted for base type
    requestScope.setUUIDForObject(ClassType.of(MyInheritedClass.class), myId, new MyInheritedClass());
    assertNotNull(requestScope.getObjectById(ClassType.of(MyBaseClass.class), myId));
}
Also used : Entity(javax.persistence.Entity) ElideSettingsBuilder(com.yahoo.elide.ElideSettingsBuilder) Include(com.yahoo.elide.annotation.Include) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) Test(org.junit.jupiter.api.Test)

Example 39 with EntityDictionary

use of com.yahoo.elide.core.dictionary.EntityDictionary 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 40 with EntityDictionary

use of com.yahoo.elide.core.dictionary.EntityDictionary in project elide by yahoo.

the class DataStoreTransactionTest method setupMocks.

@BeforeEach
public void setupMocks() {
    // this will test with the default interface implementation
    scope = mock(RequestScope.class);
    EntityDictionary dictionary = mock(EntityDictionary.class);
    when(scope.getDictionary()).thenReturn(dictionary);
    when(dictionary.getIdType(STRING_TYPE)).thenReturn(new ClassType(Long.class));
    when(dictionary.getValue(ENTITY, NAME, scope)).thenReturn(3L);
    when(dictionary.getValue(ENTITY, NAME2, scope)).thenReturn(new DataStoreIterableBuilder(List.of(1L, 2L, 3L)).build());
}
Also used : ClassType(com.yahoo.elide.core.type.ClassType) RequestScope(com.yahoo.elide.core.RequestScope) EntityDictionary(com.yahoo.elide.core.dictionary.EntityDictionary) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)87 Test (org.junit.jupiter.api.Test)31 RequestScope (com.yahoo.elide.core.RequestScope)27 Include (com.yahoo.elide.annotation.Include)17 Entity (javax.persistence.Entity)17 HashSet (java.util.HashSet)16 Type (com.yahoo.elide.core.type.Type)13 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)12 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)10 Map (java.util.Map)10 BeforeAll (org.junit.jupiter.api.BeforeAll)10 PersistentResource (com.yahoo.elide.core.PersistentResource)9 Set (java.util.Set)9 ReadPermission (com.yahoo.elide.annotation.ReadPermission)8 ClassType (com.yahoo.elide.core.type.ClassType)8 List (java.util.List)8 ElideSettingsBuilder (com.yahoo.elide.ElideSettingsBuilder)7 DataStore (com.yahoo.elide.core.datastore.DataStore)7 InvalidObjectIdentifierException (com.yahoo.elide.core.exceptions.InvalidObjectIdentifierException)7 Check (com.yahoo.elide.core.security.checks.Check)7