Search in sources :

Example 1 with FieldTestModel

use of com.yahoo.elide.core.lifecycle.FieldTestModel in project elide by yahoo.

the class ErrorMapperTest method testElideCreateNoErrorMapper.

@Test
public void testElideCreateNoErrorMapper() throws Exception {
    DataStore store = mock(DataStore.class);
    DataStoreTransaction tx = mock(DataStoreTransaction.class);
    FieldTestModel mockModel = mock(FieldTestModel.class);
    Elide elide = getElide(store, dictionary, null);
    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);
    doThrow(EXPECTED_EXCEPTION).when(tx).preCommit(any());
    RuntimeException result = assertThrows(RuntimeException.class, () -> elide.post(baseUrl, "/testModel", body, null, NO_VERSION));
    assertEquals(EXPECTED_EXCEPTION, result.getCause());
    verify(tx).close();
}
Also used : FieldTestModel(com.yahoo.elide.core.lifecycle.FieldTestModel) DataStore(com.yahoo.elide.core.datastore.DataStore) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) Elide(com.yahoo.elide.Elide) Test(org.junit.jupiter.api.Test)

Example 2 with FieldTestModel

use of com.yahoo.elide.core.lifecycle.FieldTestModel in project elide by yahoo.

the class ErrorMapperTest method testElideCreateWithErrorMapperMapped.

@Test
public void testElideCreateWithErrorMapperMapped() throws Exception {
    DataStore store = mock(DataStore.class);
    DataStoreTransaction tx = mock(DataStoreTransaction.class);
    FieldTestModel mockModel = mock(FieldTestModel.class);
    Elide elide = getElide(store, dictionary, MOCK_ERROR_MAPPER);
    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);
    doThrow(EXPECTED_EXCEPTION).when(tx).preCommit(any());
    when(MOCK_ERROR_MAPPER.map(EXPECTED_EXCEPTION)).thenReturn(MAPPED_EXCEPTION);
    ElideResponse response = elide.post(baseUrl, "/testModel", body, null, NO_VERSION);
    assertEquals(422, response.getResponseCode());
    assertEquals("{\"errors\":[{\"code\":\"SOME_ERROR\"}]}", response.getBody());
    verify(tx).close();
}
Also used : FieldTestModel(com.yahoo.elide.core.lifecycle.FieldTestModel) ElideResponse(com.yahoo.elide.ElideResponse) DataStore(com.yahoo.elide.core.datastore.DataStore) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) Elide(com.yahoo.elide.Elide) Test(org.junit.jupiter.api.Test)

Example 3 with FieldTestModel

use of com.yahoo.elide.core.lifecycle.FieldTestModel in project elide by yahoo.

the class ErrorMapperTest method testElideCreateWithErrorMapperUnmapped.

@Test
public void testElideCreateWithErrorMapperUnmapped() throws Exception {
    DataStore store = mock(DataStore.class);
    DataStoreTransaction tx = mock(DataStoreTransaction.class);
    FieldTestModel mockModel = mock(FieldTestModel.class);
    Elide elide = getElide(store, dictionary, MOCK_ERROR_MAPPER);
    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);
    doThrow(EXPECTED_EXCEPTION).when(tx).preCommit(any());
    RuntimeException result = assertThrows(RuntimeException.class, () -> elide.post(baseUrl, "/testModel", body, null, NO_VERSION));
    assertEquals(EXPECTED_EXCEPTION, result.getCause());
    verify(tx).close();
}
Also used : FieldTestModel(com.yahoo.elide.core.lifecycle.FieldTestModel) DataStore(com.yahoo.elide.core.datastore.DataStore) DataStoreTransaction(com.yahoo.elide.core.datastore.DataStoreTransaction) Elide(com.yahoo.elide.Elide) Test(org.junit.jupiter.api.Test)

Aggregations

Elide (com.yahoo.elide.Elide)3 DataStore (com.yahoo.elide.core.datastore.DataStore)3 DataStoreTransaction (com.yahoo.elide.core.datastore.DataStoreTransaction)3 FieldTestModel (com.yahoo.elide.core.lifecycle.FieldTestModel)3 Test (org.junit.jupiter.api.Test)3 ElideResponse (com.yahoo.elide.ElideResponse)1