@@ -0,0 +1,3214 @@
+package com.outbrain.ob1k.common.marshalling;%0A%0Aimport com.fasterxml.jackson.databind.ObjectMapper;%0Aimport com.outbrain.ob1k.http.Response;%0Aimport io.netty.buffer.ByteBuf;%0Aimport io.netty.handler.codec.http.HttpContent;%0Aimport io.netty.handler.codec.http.HttpResponseStatus;%0Aimport io.netty.util.CharsetUtil;%0Aimport org.junit.After;%0Aimport org.junit.Before;%0Aimport org.junit.Rule;%0Aimport org.junit.Test;%0Aimport org.junit.rules.ExpectedException;%0A%0Aimport java.io.IOException;%0A%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertNotNull;%0Aimport static org.junit.Assert.assertNull;%0Aimport static org.mockito.Mockito.mock;%0Aimport static org.mockito.Mockito.when;%0A%0A%0Apublic class EventRequestMarshallerTest %7B%0A%0A  private EventRequestMarshaller eventRequestMarshaller;%0A  private final ObjectMapper om = new ObjectMapper();%0A%0A  @Rule%0A  public final ExpectedException expectedException = ExpectedException.none();%0A%0A  @Before%0A  public void setUp() throws Exception %7B%0A    eventRequestMarshaller = new EventRequestMarshaller();%0A  %7D%0A%0A  @After%0A  public void tearDown() throws Exception %7B%0A    eventRequestMarshaller = null;%0A  %7D%0A%0A  @Test%0A  public void testUnmarshallNoContent() throws IOException %7B%0A    final Response response = mockResponse(HttpResponseStatus.NO_CONTENT.code(), null);%0A    assertNull(eventRequestMarshaller.unmarshallResponse(response, TestBody.class));%0A  %7D%0A%0A  @Test%0A  public void testUnmarshalWithOK() throws IOException %7B%0A    final String body = %22%7B%5C%22prop%5C%22: %5C%22test%5C%22%7D%22;%0A%0A    final Response response = mockResponse(HttpResponseStatus.OK.code(), body);%0A    final TestBody result = eventRequestMarshaller.unmarshallResponse(response, TestBody.class);%0A    assertEquals(%22test%22, result.getProp());%0A  %7D%0A%0A%0A  @Test%0A  public void testmarshalStreamWithOK() throws IOException %7B%0A%0A    final String body = %22%7B%5C%22prop%5C%22:%5C%22test%5C%22%7D%22;%0A    final TestBody testBody = om.readValue(body, TestBody.class);%0A%0A    final HttpContent result = eventRequestMarshaller.marshallResponsePart(testBody, HttpResponseStatus.OK, true);%0A    final ByteBuf jsonBuf = result.content();%0A    final String jsonStr = jsonBuf.toString(CharsetUtil.UTF_8);%0A%0A    assertNotNull(%22response shouldn't be null%22, result);%0A    assertEquals(%22data not equals%22, %22data: %22 + body + %22%5Cn%5Cn%22, jsonStr);%0A  %7D%0A%0A%0A  @Test%0A  public void testUnmarshalWithError() throws IOException %7B%0A    expectedException.expect(IOException.class);%0A    final Response response = mockResponse(HttpResponseStatus.NOT_FOUND.code(), null);%0A    eventRequestMarshaller.unmarshallResponse(response, TestBody.class);%0A  %7D%0A%0A  private Response mockResponse(final int statusCode, final String body) throws IOException %7B%0A    final Response response = mock(Response.class);%0A    when(response.getStatusCode()).thenReturn(statusCode);%0A    when(response.getResponseBody()).thenReturn(body);%0A    when(response.getResponseBodyAsBytes()).thenReturn(body == null ? null : body.getBytes());%0A    when(response.hasResponseBody()).thenReturn(true);%0A    return response;%0A  %7D%0A%0A  public static class TestBody %7B%0A    String prop;%0A%0A    public String getProp() %7B%0A      return prop;%0A    %7D%0A%0A    @SuppressWarnings(%22unused%22)%0A    public void setProp(final String prop) %7B%0A      this.prop = prop;%0A    %7D%0A  %7D%0A%0A%7D%0A

add test for EventRequestMarshaller