Search in sources :

Example 21 with DataStoreTransaction

use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.

the class PersistentResourceNoopUpdateTest method testNOOPToOneAddRelation.

@Test
public void testNOOPToOneAddRelation() {
    FunWithPermissions fun = new FunWithPermissions();
    Child child = newChild(1);
    fun.setRelation3(child);
    DataStoreTransaction tx = mock(DataStoreTransaction.class);
    RequestScope goodScope = new RequestScope(null, null, NO_VERSION, null, tx, goodUser, null, null, UUID.randomUUID(), elideSettings);
    PersistentResource<FunWithPermissions> funResource = new PersistentResource<>(fun, "3", goodScope);
    PersistentResource<Child> childResource = new PersistentResource<>(child, "1", goodScope);
    when(tx.getToOneRelation(eq(tx), eq(fun), any(), any())).thenReturn(child);
    // We do not want the update to one method to be called when we add the existing entity to the relation
    funResource.addRelation("relation3", childResource);
    verify(tx, never()).updateToOneRelation(eq(tx), eq(fun), any(), any(), eq(goodScope));
}
Also used : DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) FunWithPermissions(example.FunWithPermissions) Child(example.Child) Test(org.junit.jupiter.api.Test)

Example 22 with DataStoreTransaction

use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.

the class PersistentResourceNoopUpdateTest method testToManyAddRelation.

@Test
public void testToManyAddRelation() {
    FunWithPermissions fun = new FunWithPermissions();
    Child child = newChild(1);
    DataStoreTransaction tx = mock(DataStoreTransaction.class);
    RequestScope goodScope = new RequestScope(null, null, NO_VERSION, null, tx, goodUser, null, null, UUID.randomUUID(), elideSettings);
    PersistentResource<FunWithPermissions> funResource = new PersistentResource<>(fun, "3", goodScope);
    PersistentResource<Child> childResource = new PersistentResource<>(child, null, goodScope);
    funResource.addRelation("relation1", childResource);
    verify(tx, times(1)).updateToManyRelation(eq(tx), eq(fun), eq("relation1"), any(), any(), eq(goodScope));
}
Also used : DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) FunWithPermissions(example.FunWithPermissions) Child(example.Child) Test(org.junit.jupiter.api.Test)

Example 23 with DataStoreTransaction

use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.

the class PersistentResourceNoopUpdateTest method testToOneAddRelation.

@Test
public void testToOneAddRelation() {
    FunWithPermissions fun = new FunWithPermissions();
    Child child = newChild(1);
    DataStoreTransaction tx = mock(DataStoreTransaction.class);
    RequestScope goodScope = new RequestScope(null, null, NO_VERSION, null, tx, goodUser, null, null, UUID.randomUUID(), elideSettings);
    PersistentResource<FunWithPermissions> funResource = new PersistentResource<>(fun, "3", goodScope);
    PersistentResource<Child> childResource = new PersistentResource<>(child, "1", goodScope);
    funResource.addRelation("relation3", childResource);
    verify(tx, times(1)).updateToOneRelation(eq(tx), eq(fun), any(), any(), eq(goodScope));
}
Also used : DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) FunWithPermissions(example.FunWithPermissions) Child(example.Child) Test(org.junit.jupiter.api.Test)

Example 24 with DataStoreTransaction

use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.

the class InMemoryStoreTransactionTest method testInMemoryDataStore.

@Test
public void testInMemoryDataStore() {
    HashMapDataStore wrapped = new HashMapDataStore(DefaultClassScanner.getInstance(), Book.class.getPackage());
    InMemoryDataStore store = new InMemoryDataStore(wrapped);
    DataStoreTransaction tx = store.beginReadTransaction();
    assertEquals(InMemoryStoreTransaction.class, tx.getClass());
    assertEquals(wrapped, wrapped.getDataStore());
    // extract class names from DataStore string
    String tos = store.toString().replace("Data store contents", "").replace("Table ClassType{cls=class", "").replace("} contents", "").replace("Wrapped:[", "").replace("]", "").replace("\n\n", ",").replace(" ", "").replace("\n", "");
    // make sure count is correct
    assertEquals(ImmutableSet.copyOf(new String[] { "example.Author", "example.Book", "example.Child", "example.CoerceBean", "example.ComputedBean", "example.Editor", "example.FieldAnnotations", "example.FirstClassFields", "example.FunWithPermissions", "example.Invoice", "example.Job", "example.Left", "example.LineItem", "example.MapColorShape", "example.NoDeleteEntity", "example.NoReadEntity", "example.NoShareEntity", "example.NoUpdateEntity", "example.Parent", "example.Post", "example.PrimitiveId", "example.Publisher", "example.Right", "example.StringId", "example.UpdateAndCreate", "example.User", "example.Company", "example.models.generics.Employee", "example.models.generics.Manager", "example.models.generics.Overlord", "example.models.generics.Peon", "example.models.packageinfo.IncludedPackageLevel", "example.models.packageinfo.included.IncludedSubPackage", "example.models.triggers.Invoice", "example.models.versioned.BookV2", "example.nontransferable.ContainerWithPackageShare", "example.nontransferable.NoTransferBiDirectional", "example.nontransferable.ShareableWithPackageShare", "example.nontransferable.StrictNoTransfer", "example.nontransferable.Untransferable" }), ImmutableSet.copyOf(tos.split(",")));
}
Also used : Book(example.Book) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) Test(org.junit.jupiter.api.Test)

Example 25 with DataStoreTransaction

use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.

the class TransactionWrapperTest method testFlush.

@Test
public void testFlush() {
    DataStoreTransaction wrapped = mock(DataStoreTransaction.class);
    DataStoreTransaction wrapper = new TestTransactionWrapper(wrapped);
    wrapper.flush(null);
    verify(wrapped, times(1)).flush(any());
}
Also used : DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) Test(org.junit.jupiter.api.Test)

Aggregations

DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)139 Test (org.junit.jupiter.api.Test)101 RequestScope (com.yahoo.elide.core.RequestScope)40 DataStore (com.yahoo.elide.core.datastore.DataStore)30 FilterExpression (com.yahoo.elide.core.filter.expression.FilterExpression)28 Elide (com.yahoo.elide.Elide)27 ElideResponse (com.yahoo.elide.ElideResponse)22 EntityProjection (com.yahoo.elide.core.request.EntityProjection)22 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)18 PersistentResource (com.yahoo.elide.core.PersistentResource)17 Item (com.yahoo.elide.datastores.search.models.Item)17 Book (example.Book)13 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)9 BeforeEach (org.junit.jupiter.api.BeforeEach)9 Author (example.Author)8 FilterPredicate (com.yahoo.elide.core.filter.predicates.FilterPredicate)7 FirstBean (com.yahoo.elide.example.beans.FirstBean)7 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 AndFilterExpression (com.yahoo.elide.core.filter.expression.AndFilterExpression)6