package com.buabook.http.common.test;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.UriInfo;

import org.junit.Before;
import org.junit.Test;

import com.buabook.http.common.jersey.UrlPrinterFilter;

public class UrlPrinterFilterTest {
	private UriInfo uriInfo;
	
	private ContainerRequestContext crc;
	
	@Before
	public void initialise() throws URISyntaxException {
		this.uriInfo = mock(UriInfo.class);
		when(uriInfo.getAbsolutePath()).thenReturn(new URI("http://test.url.com/with/path"));
		when(uriInfo.getQueryParameters()).thenReturn(testQueryParams());
		
		this.crc = mock(ContainerRequestContext.class);
		when(crc.getUriInfo()).thenReturn(uriInfo);
		when(crc.getHeaders()).thenReturn(testHeaders());
	}

	@Test
	public void testFilterLogsWithNoError() throws IOException {
		new UrlPrinterFilter().filter(crc);
	}
	
	private MultivaluedHashMap<String, String> testQueryParams() {
		MultivaluedHashMap<String, String> params = new MultivaluedHashMap<>();
		params.add("param1", "value1");
		params.add("param2", "value2");
		
		return params;
	}
	
	private MultivaluedHashMap<String, String> testHeaders() {
		MultivaluedHashMap<String, String> headers = new MultivaluedHashMap<>();
		headers.add("header1", "value1");
		headers.add("header2", "value2");
		
		return headers;
	}
}

@@ -253,16 +253,51 @@
 ontext;%0A
+import javax.ws.rs.core.MediaType;%0A
 import j
@@ -332,16 +332,16 @@
 ashMap;%0A
-
 import j
@@ -512,34 +512,8 @@
 t %7B%0A
-%09private UriInfo uriInfo;%0A
 %09%0A%09p
@@ -548,18 +548,17 @@
 xt crc;%0A
-%09
 %0A
+
 %09@Before
@@ -614,21 +614,24 @@
 ion %7B%0A%09%09
-this.
+UriInfo 
 uriInfo 
@@ -908,16 +908,88 @@
 iInfo);%0A
+%09%09when(crc.getMediaType()).thenReturn(MediaType.APPLICATION_JSON_TYPE);%0A
 %09%09when(c
@@ -1036,16 +1036,18 @@
 ));%0A%09%7D%0A%0A
+%09%0A
 %09@Test%0A%09
@@ -1145,21 +1145,23 @@
 r(crc);%0A
-
 %09%7D%0A%09%0A
+%09%0A
 %09private

Add media type to url printer filter test