use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.
the class EntityManagerLifeCycleHookIT method setUp.
@BeforeEach
public void setUp() throws IOException {
try (DataStoreTransaction tx = dataStore.beginTransaction()) {
Book book1 = new Book();
book1.setTitle("Test Book1");
tx.createObject(book1, null);
Book book2 = new Book();
book2.setTitle("Test Book2");
tx.createObject(book2, null);
Book book3 = new Book();
book3.setTitle("Test Book3");
tx.createObject(book3, null);
tx.commit(null);
}
}
use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.
the class PersistentResourceTest method testPatchRequestScope.
@Test
public void testPatchRequestScope() {
DataStoreTransaction tx = mock(DataStoreTransaction.class);
PatchRequestScope parentScope = new PatchRequestScope(null, "/book", NO_VERSION, tx, new TestUser("1"), UUID.randomUUID(), null, Collections.emptyMap(), elideSettings);
PatchRequestScope scope = new PatchRequestScope(parentScope.getPath(), parentScope.getJsonApiDocument(), parentScope);
// verify wrap works
assertEquals(parentScope.getUpdateStatusCode(), scope.getUpdateStatusCode());
assertEquals(parentScope.getObjectEntityCache(), scope.getObjectEntityCache());
Parent parent = newParent(7);
PersistentResource<Parent> parentResource = new PersistentResource<>(parent, "1", scope);
parentResource.updateAttribute("firstName", "foobar");
ArgumentCaptor<Attribute> attributeArgument = ArgumentCaptor.forClass(Attribute.class);
verify(tx, times(1)).setAttribute(eq(parent), attributeArgument.capture(), eq(scope));
assertEquals(attributeArgument.getValue().getName(), "firstName");
assertEquals(attributeArgument.getValue().getArguments().iterator().next().getValue(), "foobar");
}
use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.
the class PersistentResourceTest method testRelationshipMissingData.
/**
* Verify that Relationship toMany cannot contain null resources, but toOne can.
*
* @throws Exception
*/
@Test
public void testRelationshipMissingData() throws Exception {
User goodUser = new TestUser("1");
@SuppressWarnings("resource") DataStoreTransaction tx = mock(DataStoreTransaction.class);
RequestScope goodScope = new RequestScope(null, null, NO_VERSION, null, tx, goodUser, null, null, UUID.randomUUID(), elideSettings);
// null resource in toMany relationship is not valid
List<Resource> idList = new ArrayList<>();
idList.add(new ResourceIdentifier("child", "3").castToResource());
idList.add(new ResourceIdentifier("child", "6").castToResource());
idList.add(null);
assertThrows(NullPointerException.class, () -> new Relationship(Collections.emptyMap(), new Data<>(idList)));
// However null toOne relationship is valid
Relationship toOneRelationship = new Relationship(Collections.emptyMap(), new Data<>((Resource) null));
assertTrue(toOneRelationship.getData().get().isEmpty());
assertNull(toOneRelationship.toPersistentResources(goodScope));
// no Data
Relationship nullRelationship = new Relationship(Collections.emptyMap(), null);
assertNull(nullRelationship.getData());
assertNull(nullRelationship.toPersistentResources(goodScope));
}
use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.
the class TransactionWrapperTest method testPreCommit.
@Test
public void testPreCommit() {
DataStoreTransaction wrapped = mock(DataStoreTransaction.class);
DataStoreTransaction wrapper = new TestTransactionWrapper(wrapped);
wrapper.preCommit(null);
verify(wrapped, times(1)).preCommit(any());
}
use of com.yahoo.elide.core.datastore.DataStoreTransaction in project elide by yahoo.
the class TransactionWrapperTest method testGetAttribute.
@Test
public void testGetAttribute() {
DataStoreTransaction wrapped = mock(DataStoreTransaction.class);
DataStoreTransaction wrapper = new TestTransactionWrapper(wrapped);
when(wrapped.getAttribute(any(), isA(Attribute.class), any())).thenReturn(1L);
Object actual = wrapper.getAttribute(null, Attribute.builder().name("foo").type(String.class).build(), null);
verify(wrapped, times(1)).getAttribute(any(), isA(Attribute.class), any());
assertEquals(1L, actual);
}
Aggregations