Search in sources :

Example 1 with FunWithPermissions

use of example.FunWithPermissions in project elide by yahoo.

the class IncludedProcessorTest method newFunWithPermissions.

private FunWithPermissions newFunWithPermissions(int id) {
    FunWithPermissions funWithPermissions = new FunWithPermissions();
    funWithPermissions.setId(id);
    funWithPermissions.setRelation1(new HashSet<>());
    return funWithPermissions;
}
Also used : FunWithPermissions(example.FunWithPermissions)

Example 2 with FunWithPermissions

use of example.FunWithPermissions in project elide by yahoo.

the class PersistentResourceNoopUpdateTest method testNOOPToManyAddRelation.

@Test
public void testNOOPToManyAddRelation() {
    FunWithPermissions fun = new FunWithPermissions();
    Child child = newChild(1);
    Set<Child> children = new HashSet<>();
    children.add(child);
    fun.setRelation1(children);
    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);
    // We do not want the update to one method to be called when we add the existing entity to the relation
    funResource.addRelation("relation1", childResource);
    verify(tx, never()).updateToManyRelation(eq(tx), eq(child), eq("relation1"), any(), any(), eq(goodScope));
}
Also used : DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) FunWithPermissions(example.FunWithPermissions) Child(example.Child) HashSet(java.util.HashSet) Test(org.junit.jupiter.api.Test)

Example 3 with FunWithPermissions

use of example.FunWithPermissions 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 4 with FunWithPermissions

use of example.FunWithPermissions 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 5 with FunWithPermissions

use of example.FunWithPermissions 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)

Aggregations

FunWithPermissions (example.FunWithPermissions)40 Test (org.junit.jupiter.api.Test)36 PatchRequestScope (com.yahoo.elide.jsonapi.extensions.PatchRequestScope)29 Child (example.Child)27 DataStoreIterableBuilder (com.yahoo.elide.core.datastore.DataStoreIterableBuilder)5 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)5 HashSet (java.util.HashSet)5 ImmutableSet (com.google.common.collect.ImmutableSet)3 Parent (example.Parent)3 LinkedHashSet (java.util.LinkedHashSet)3 Set (java.util.Set)3 BeforeEach (org.junit.jupiter.api.BeforeEach)2 ElideSettings (com.yahoo.elide.ElideSettings)1 ElideSettingsBuilder (com.yahoo.elide.ElideSettingsBuilder)1 RequestScope (com.yahoo.elide.core.RequestScope)1 TestRequestScope (com.yahoo.elide.core.TestRequestScope)1 AuditLogger (com.yahoo.elide.core.audit.AuditLogger)1 TestAuditLogger (com.yahoo.elide.core.audit.TestAuditLogger)1 TestUser (com.yahoo.elide.core.security.TestUser)1 Relationship (com.yahoo.elide.jsonapi.models.Relationship)1