use of com.fasterxml.jackson.core.type.TypeReference in project Gaffer by gchq.
the class OperationChainTest method shouldDetermineOperationChainOutputType.
@Test
public void shouldDetermineOperationChainOutputType() {
// Given
final Operation operation1 = mock(Operation.class);
final Operation operation2 = mock(Operation.class);
final TypeReference typeRef = mock(TypeReference.class);
given(operation2.getOutputTypeReference()).willReturn(typeRef);
// When
final OperationChain opChain = new OperationChain.Builder().first(operation1).then(operation2).build();
// When / Then
assertSame(typeRef, opChain.getOutputTypeReference());
}
use of com.fasterxml.jackson.core.type.TypeReference in project Gaffer by gchq.
the class GeneratorsIT method shouldConvertToDomainObjects.
@Test
public void shouldConvertToDomainObjects() throws OperationException, UnsupportedEncodingException {
// Given
final OperationChain<CloseableIterable<DomainObject>> opChain = new OperationChain.Builder().first(new GetElements.Builder<>().addSeed(new EntitySeed(SOURCE_1)).build()).then(new GenerateObjects.Builder<Element, DomainObject>().generator(new BasicGenerator()).outputType(new TypeReference<CloseableIterable<DomainObject>>() {
}).build()).build();
// When
final List<DomainObject> results = Lists.newArrayList(graph.execute(opChain, getUser()));
final EntityDomainObject entityDomainObject = new EntityDomainObject(SOURCE_1, "3", null);
final EdgeDomainObject edgeDomainObject = new EdgeDomainObject(SOURCE_1, DEST_1, false, 1, 1L);
// Then
assertNotNull(results);
assertEquals(2, results.size());
assertThat(results, IsCollectionContaining.hasItems(entityDomainObject, edgeDomainObject));
}
use of com.fasterxml.jackson.core.type.TypeReference in project riposte by Nike-Inc.
the class RequestInfoImplTest method setupContentDeserializer_and_getContent_work_as_expected.
@Test
@DataProvider(value = { "UTF-8", "UTF-16", "UTF-16BE", "UTF-16LE", "ISO-8859-1", "US-ASCII" })
public void setupContentDeserializer_and_getContent_work_as_expected(String charsetName) throws IOException {
// given
ObjectMapper objectMapper = new ObjectMapper();
TypeReference<TestContentObject> typeRef = new TypeReference<TestContentObject>() {
};
TestContentObject contentObj = new TestContentObject(UUID.randomUUID().toString(), UUID.randomUUID().toString());
String contentString = objectMapper.writeValueAsString(contentObj);
RequestInfoImpl<TestContentObject> requestInfo = (RequestInfoImpl<TestContentObject>) RequestInfoImpl.dummyInstanceForUnknownRequests();
requestInfo.rawContentBytes = contentString.getBytes(Charset.forName(charsetName));
// when
requestInfo.setupContentDeserializer(objectMapper, typeRef);
// then
assertThat(requestInfo.getContent(), notNullValue());
assertThat(requestInfo.getContent().foo, is(contentObj.foo));
assertThat(requestInfo.getContent().bar, is(contentObj.bar));
}
use of com.fasterxml.jackson.core.type.TypeReference in project riposte by Nike-Inc.
the class RequestInfoImplTest method getContent_throws_RequestContentDeserializationException_if_an_error_occurs_during_deserialization.
@Test
public void getContent_throws_RequestContentDeserializationException_if_an_error_occurs_during_deserialization() throws IOException {
// given
RequestInfo<TestContentObject> requestInfoSpy = spy((RequestInfo<TestContentObject>) RequestInfoImpl.dummyInstanceForUnknownRequests());
ObjectMapper objectMapperSpy = spy(new ObjectMapper());
byte[] rawBytes = new byte[] {};
doReturn(rawBytes).when(requestInfoSpy).getRawContentBytes();
RuntimeException expectedRootCause = new RuntimeException("splat");
doThrow(expectedRootCause).when(objectMapperSpy).readValue(any(byte[].class), any(TypeReference.class));
HttpMethod method = HttpMethod.CONNECT;
String path = UUID.randomUUID().toString();
TypeReference<TestContentObject> typeRef = new TypeReference<TestContentObject>() {
};
doReturn(method).when(requestInfoSpy).getMethod();
doReturn(path).when(requestInfoSpy).getPath();
// when
requestInfoSpy.setupContentDeserializer(objectMapperSpy, typeRef);
Throwable actualEx = catchThrowable(() -> requestInfoSpy.getContent());
// then
assertThat(actualEx, notNullValue());
assertThat(actualEx, instanceOf(RequestContentDeserializationException.class));
RequestContentDeserializationException rcde = (RequestContentDeserializationException) actualEx;
assertThat(rcde.desiredObjectType, sameInstance(typeRef));
assertThat(rcde.httpMethod, is(String.valueOf(method)));
assertThat(rcde.requestPath, is(path));
assertThat(actualEx.getCause(), is(expectedRootCause));
}
use of com.fasterxml.jackson.core.type.TypeReference in project riposte by Nike-Inc.
the class RequestInfoImplTest method getContent_returns_object_deserialized_from_raw_bytes_if_content_type_is_not_CharSequence_or_String.
@Test
public void getContent_returns_object_deserialized_from_raw_bytes_if_content_type_is_not_CharSequence_or_String() throws IOException {
// given
RequestInfo<TestContentObject> requestInfoSpy = spy((RequestInfo<TestContentObject>) RequestInfoImpl.dummyInstanceForUnknownRequests());
ObjectMapper objectMapper = new ObjectMapper();
TestContentObject expectedTco = new TestContentObject(UUID.randomUUID().toString(), UUID.randomUUID().toString());
byte[] rawBytes = objectMapper.writeValueAsString(expectedTco).getBytes(CharsetUtil.UTF_8);
doReturn(rawBytes).when(requestInfoSpy).getRawContentBytes();
ObjectMapper objectMapperSpy = spy(objectMapper);
TypeReference<TestContentObject> typeRef = new TypeReference<TestContentObject>() {
};
// when
requestInfoSpy.setupContentDeserializer(objectMapperSpy, typeRef);
TestContentObject result = requestInfoSpy.getContent();
// then
assertThat(result, notNullValue());
assertThat(result.foo, is(expectedTco.foo));
assertThat(result.bar, is(expectedTco.bar));
verify(requestInfoSpy).getRawContentBytes();
verify(requestInfoSpy, never()).getRawContent();
verify(objectMapperSpy).readValue(rawBytes, typeRef);
}
Aggregations