use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.
the class LifeCycleTest method testElideGetRelationship.
@Test
public void testElideGetRelationship() throws Exception {
DataStore store = mock(DataStore.class);
DataStoreTransaction tx = mock(DataStoreTransaction.class);
FieldTestModel mockModel = mock(FieldTestModel.class);
FieldTestModel child = mock(FieldTestModel.class);
when(mockModel.getModels()).thenReturn(ImmutableSet.of(child));
Elide elide = getElide(store, dictionary, MOCK_AUDIT_LOGGER);
when(store.beginReadTransaction()).thenCallRealMethod();
when(store.beginTransaction()).thenReturn(tx);
when(tx.loadObject(isA(EntityProjection.class), any(), isA(RequestScope.class))).thenReturn(mockModel);
MultivaluedMap<String, String> queryParams = new MultivaluedHashMap<>();
ElideResponse response = elide.get(baseUrl, "/testModel/1/relationships/models", queryParams, null, NO_VERSION);
assertEquals(HttpStatus.SC_OK, response.getResponseCode());
verify(mockModel, never()).classAllFieldsCallback(any(), any());
verify(mockModel, never()).classCallback(eq(CREATE), any());
verify(mockModel, never()).classCallback(eq(UPDATE), any());
verify(mockModel, never()).classCallback(eq(DELETE), any());
verify(mockModel, never()).attributeCallback(eq(CREATE), any(), any());
verify(mockModel, never()).attributeCallback(eq(UPDATE), any(), any());
verify(mockModel, never()).attributeCallback(eq(DELETE), any(), any());
verify(mockModel, never()).relationCallback(eq(CREATE), any(), any());
verify(mockModel, never()).relationCallback(eq(UPDATE), any(), any());
verify(mockModel, never()).relationCallback(eq(DELETE), any(), any());
verify(tx).preCommit(any());
verify(tx).flush(any());
verify(tx).commit(any());
verify(tx).close();
}
use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.
the class LifeCycleTest method testRead.
@Test
public void testRead() {
FieldTestModel mockModel = mock(FieldTestModel.class);
DataStoreTransaction tx = mock(DataStoreTransaction.class);
RequestScope scope = buildRequestScope(dictionary, tx);
when(tx.createNewObject(ClassType.of(FieldTestModel.class), scope)).thenReturn(mockModel);
PersistentResource resource = new PersistentResource(mockModel, "1", scope);
resource.getAttribute(Attribute.builder().type(String.class).name("field").build());
verify(mockModel, never()).classCallback(any(), any());
verify(mockModel, never()).attributeCallback(any(), any(), any());
verify(mockModel, never()).classAllFieldsCallback(any(), any());
verify(mockModel, never()).relationCallback(any(), any(), any());
clearInvocations(mockModel);
scope.runQueuedPreSecurityTriggers();
verify(mockModel, never()).classCallback(any(), any());
verify(mockModel, never()).classAllFieldsCallback(any(), any());
verify(mockModel, never()).relationCallback(any(), any(), any());
verify(mockModel, never()).attributeCallback(any(), any(), any());
clearInvocations(mockModel);
scope.runQueuedPreFlushTriggers();
verify(mockModel, never()).classCallback(any(), any());
verify(mockModel, never()).attributeCallback(any(), any(), any());
verify(mockModel, never()).classAllFieldsCallback(any(), any());
verify(mockModel, never()).relationCallback(any(), any(), any());
clearInvocations(mockModel);
scope.runQueuedPreCommitTriggers();
verify(mockModel, never()).classCallback(any(), any());
verify(mockModel, never()).attributeCallback(any(), any(), any());
verify(mockModel, never()).classAllFieldsCallback(any(), any());
verify(mockModel, never()).relationCallback(any(), any(), any());
clearInvocations(mockModel);
scope.runQueuedPostCommitTriggers();
verify(mockModel, never()).classCallback(any(), any());
verify(mockModel, never()).attributeCallback(any(), any(), any());
verify(mockModel, never()).classAllFieldsCallback(any(), any());
verify(mockModel, never()).relationCallback(any(), any(), any());
}
use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.
the class LifeCycleTest method testElideDelete.
@Test
public void testElideDelete() throws Exception {
DataStore store = mock(DataStore.class);
DataStoreTransaction tx = mock(DataStoreTransaction.class);
FieldTestModel mockModel = mock(FieldTestModel.class);
Elide elide = getElide(store, dictionary, MOCK_AUDIT_LOGGER);
dictionary.setValue(mockModel, "id", "1");
when(store.beginTransaction()).thenReturn(tx);
when(tx.loadObject(isA(EntityProjection.class), any(), isA(RequestScope.class))).thenReturn(mockModel);
ElideResponse response = elide.delete(baseUrl, "/testModel/1", "", null, NO_VERSION);
assertEquals(HttpStatus.SC_NO_CONTENT, response.getResponseCode());
verify(mockModel, never()).classAllFieldsCallback(any(), any());
verify(mockModel, never()).classCallback(eq(UPDATE), any());
verify(mockModel, never()).classCallback(eq(CREATE), any());
verify(mockModel, times(1)).classCallback(eq(DELETE), eq(PRESECURITY));
verify(mockModel, times(1)).classCallback(eq(DELETE), eq(PREFLUSH));
verify(mockModel, times(1)).classCallback(eq(DELETE), eq(PRECOMMIT));
verify(mockModel, times(1)).classCallback(eq(DELETE), eq(POSTCOMMIT));
verify(mockModel, never()).attributeCallback(eq(UPDATE), any(), any());
verify(mockModel, never()).attributeCallback(eq(CREATE), any(), any());
verify(mockModel, never()).attributeCallback(eq(DELETE), any(), any());
verify(mockModel, never()).relationCallback(eq(UPDATE), any(), any());
verify(mockModel, never()).relationCallback(eq(CREATE), any(), any());
verify(mockModel, never()).relationCallback(eq(DELETE), any(), any());
verify(tx).preCommit(any());
verify(tx).delete(eq(mockModel), isA(RequestScope.class));
verify(tx).flush(isA(RequestScope.class));
verify(tx).commit(isA(RequestScope.class));
verify(tx).close();
}
use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.
the class LifeCycleTest method testPreSecurityLifecycleHookException.
@Test
public void testPreSecurityLifecycleHookException() {
DataStoreTransaction tx = mock(DataStoreTransaction.class);
FieldTestModel testModel = mock(FieldTestModel.class);
doThrow(IllegalStateException.class).when(testModel).attributeCallback(eq(UPDATE), eq(PRESECURITY), any(ChangeSpec.class));
RequestScope scope = buildRequestScope(dictionary, tx);
PersistentResource resource = new PersistentResource(testModel, "1", scope);
assertThrows(IllegalStateException.class, () -> resource.updateAttribute("field", "New value"));
}
use of com.yahoo.elide.core.datastore.DataStoreTransaction 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));
}
Aggregations