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();
}
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();
}
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();
}
Aggregations