Search in sources :

Example 6 with DataStore

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

the class LifeCycleTest method testElideCreate.

@Test
public void testElideCreate() 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);
    String body = "{\"data\": {\"type\":\"testModel\",\"id\":\"1\",\"attributes\": {\"field\":\"Foo\"}}}";
    when(store.beginTransaction()).thenReturn(tx);
    when(tx.createNewObject(eq(ClassType.of(FieldTestModel.class)), any())).thenReturn(mockModel);
    ElideResponse response = elide.post(baseUrl, "/testModel", body, null, NO_VERSION);
    assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
    verify(mockModel, times(1)).classCallback(eq(CREATE), eq(PRESECURITY));
    verify(mockModel, times(1)).classCallback(eq(CREATE), eq(PREFLUSH));
    verify(mockModel, times(1)).classCallback(eq(CREATE), eq(PRECOMMIT));
    verify(mockModel, times(1)).classCallback(eq(CREATE), eq(POSTCOMMIT));
    verify(mockModel, never()).classCallback(eq(UPDATE), any());
    verify(mockModel, never()).classCallback(eq(DELETE), any());
    verify(mockModel, times(2)).classAllFieldsCallback(any(), any());
    verify(mockModel, times(2)).classAllFieldsCallback(eq(CREATE), eq(PRECOMMIT));
    verify(mockModel, times(1)).attributeCallback(eq(CREATE), eq(PRESECURITY), any());
    verify(mockModel, times(1)).attributeCallback(eq(CREATE), eq(PREFLUSH), any());
    verify(mockModel, times(1)).attributeCallback(eq(CREATE), eq(PRECOMMIT), any());
    verify(mockModel, times(1)).attributeCallback(eq(CREATE), eq(POSTCOMMIT), any());
    verify(mockModel, never()).attributeCallback(eq(UPDATE), any(), any());
    verify(mockModel, never()).attributeCallback(eq(DELETE), any(), any());
    verify(mockModel, times(1)).relationCallback(eq(CREATE), eq(PRESECURITY), any());
    verify(mockModel, times(1)).relationCallback(eq(CREATE), eq(PREFLUSH), any());
    verify(mockModel, times(1)).relationCallback(eq(CREATE), eq(PRECOMMIT), any());
    verify(mockModel, times(1)).relationCallback(eq(CREATE), eq(POSTCOMMIT), any());
    verify(mockModel, never()).relationCallback(eq(UPDATE), any(), any());
    verify(mockModel, never()).relationCallback(eq(DELETE), any(), any());
    verify(tx).preCommit(any());
    verify(tx, times(1)).createObject(eq(mockModel), isA(RequestScope.class));
    verify(tx).flush(isA(RequestScope.class));
    verify(tx).commit(isA(RequestScope.class));
    verify(tx).close();
}
Also used : ElideResponse(com.yahoo.elide.ElideResponse) DataStore(com.yahoo.elide.core.datastore.DataStore) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Elide(com.yahoo.elide.Elide) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Example 7 with DataStore

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

the class LifeCycleTest method testElideGet.

@Test
public void testElideGet() 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);
    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", 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();
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) EntityProjection(com.yahoo.elide.core.request.EntityProjection) ElideResponse(com.yahoo.elide.ElideResponse) DataStore(com.yahoo.elide.core.datastore.DataStore) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Elide(com.yahoo.elide.Elide) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Example 8 with DataStore

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

the class LifeCycleTest method testElideGetSparse.

@Test
public void testElideGetSparse() 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);
    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<>();
    queryParams.putSingle("fields[testModel]", "field");
    ElideResponse response = elide.get(baseUrl, "/testModel/1", 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(any(), any(), any());
    verify(tx).preCommit(any());
    verify(tx).flush(any());
    verify(tx).commit(any());
    verify(tx).close();
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) EntityProjection(com.yahoo.elide.core.request.EntityProjection) ElideResponse(com.yahoo.elide.ElideResponse) DataStore(com.yahoo.elide.core.datastore.DataStore) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Elide(com.yahoo.elide.Elide) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Example 9 with DataStore

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

the class LifeCycleTest method testElidePatchExtensionUpdate.

@Test
public void testElidePatchExtensionUpdate() 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);
    String body = "[{\"op\": \"replace\",\"path\": \"/testModel/1\",\"value\":{" + "\"type\":\"testModel\",\"id\": \"1\",\"attributes\": {\"field\":\"Foo\"}}}]";
    dictionary.setValue(mockModel, "id", "1");
    when(store.beginTransaction()).thenReturn(tx);
    when(tx.loadObject(any(), any(), isA(RequestScope.class))).thenReturn(mockModel);
    String contentType = JSONAPI_CONTENT_TYPE_WITH_JSON_PATCH_EXTENSION;
    ElideResponse response = elide.patch(baseUrl, contentType, contentType, "/", body, null, NO_VERSION);
    assertEquals(HttpStatus.SC_OK, response.getResponseCode());
    assertEquals("[{\"data\":null}]", response.getBody());
    verify(mockModel, times(1)).classCallback(eq(UPDATE), eq(PRESECURITY));
    verify(mockModel, times(1)).classCallback(eq(UPDATE), eq(PREFLUSH));
    verify(mockModel, times(1)).classCallback(eq(UPDATE), eq(PRECOMMIT));
    verify(mockModel, times(1)).classCallback(eq(UPDATE), eq(POSTCOMMIT));
    verify(mockModel, never()).classCallback(eq(CREATE), any());
    verify(mockModel, never()).classCallback(eq(DELETE), any());
    verify(mockModel, never()).classAllFieldsCallback(any(), any());
    verify(mockModel, never()).classAllFieldsCallback(eq(CREATE), eq(PRECOMMIT));
    verify(mockModel, times(1)).attributeCallback(eq(UPDATE), eq(PRESECURITY), any());
    verify(mockModel, times(1)).attributeCallback(eq(UPDATE), eq(PREFLUSH), any());
    verify(mockModel, times(1)).attributeCallback(eq(UPDATE), eq(PRECOMMIT), any());
    verify(mockModel, times(1)).attributeCallback(eq(UPDATE), eq(POSTCOMMIT), any());
    verify(mockModel, never()).attributeCallback(eq(CREATE), 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());
    // Twice because the patch extension request is broken into attributes & relationships separately.
    verify(tx, times(2)).loadObject(any(), any(), isA(RequestScope.class));
    verify(tx).flush(isA(RequestScope.class));
    verify(tx).commit(isA(RequestScope.class));
    verify(tx).close();
}
Also used : ElideResponse(com.yahoo.elide.ElideResponse) DataStore(com.yahoo.elide.core.datastore.DataStore) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Elide(com.yahoo.elide.Elide) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Example 10 with DataStore

use of com.yahoo.elide.core.datastore.DataStore 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();
}
Also used : MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) EntityProjection(com.yahoo.elide.core.request.EntityProjection) ElideResponse(com.yahoo.elide.ElideResponse) DataStore(com.yahoo.elide.core.datastore.DataStore) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Elide(com.yahoo.elide.Elide) RequestScope(com.yahoo.elide.core.RequestScope) Test(org.junit.jupiter.api.Test)

Aggregations

DataStore (com.yahoo.elide.core.datastore.DataStore)38 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)31 Test (org.junit.jupiter.api.Test)27 Elide (com.yahoo.elide.Elide)25 ElideResponse (com.yahoo.elide.ElideResponse)21 RequestScope (com.yahoo.elide.core.RequestScope)19 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)18 EntityProjection (com.yahoo.elide.core.request.EntityProjection)10 EntityDictionary (com.yahoo.elide.core.dictionary.EntityDictionary)5 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)5 HashMapDataStore (com.yahoo.elide.core.datastore.inmemory.HashMapDataStore)3 FieldTestModel (com.yahoo.elide.core.lifecycle.FieldTestModel)3 AggregationDataStore (com.yahoo.elide.datastores.aggregation.AggregationDataStore)3 MetaDataStore (com.yahoo.elide.datastores.aggregation.metadata.MetaDataStore)3 JpaDataStore (com.yahoo.elide.datastores.jpa.JpaDataStore)3 NonJtaTransaction (com.yahoo.elide.datastores.jpa.transaction.NonJtaTransaction)3 MultiplexManager (com.yahoo.elide.datastores.multiplex.MultiplexManager)3 NoopBean (com.yahoo.elide.beans.NoopBean)2 TemplateConfigValidator (com.yahoo.elide.datastores.aggregation.validator.TemplateConfigValidator)2 ConfigDataStore (com.yahoo.elide.modelconfig.store.ConfigDataStore)2