package com.fagnerbrack.servlet.convention.test.integration;

import java.io.File;
import java.io.IOException;
import java.net.URL;

import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.fluent.Content;
import org.apache.http.client.fluent.Request;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.fagnerbrack.servlet.convention.test.util.IntegrationTest;

@RunWith( Arquillian.class )
public class Issue10IT {
	@Deployment
	public static Archive<?> createDeployment() {
		WebArchive war = IntegrationTest.createCommonDeployment()
			.addAsWebInfResource(
				new File( "src/test/resources/descriptors/web.xml" ),
				"web.xml"
			);
			
		return war;
	}
	
	@RunAsClient
	@Test
	public void should_set_default_contentype_for_html_response( @ArquillianResource URL baseURL )
	throws ClientProtocolException, IOException {
		Request request = Request.Get( baseURL.toString() + "issue-10/index" );
		Content content = request.execute().returnContent();
		
		String expected = "text/html";
		String actual = content.getType().getMimeType();
		
		Assert.assertEquals( expected, actual );
	}
}
