package eu.dnetlib.enabling.inspector;

import static org.junit.Assert.assertNotNull;

import java.io.IOException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.xml.sax.SAXException;

import com.meterware.httpunit.WebConversation;
import com.meterware.httpunit.WebLink;
import com.meterware.httpunit.WebResponse;

import eu.dnetlib.test.AbstractIntegrationContainerTest;

/**
 * Test the inspector web interface.
 * 
 * @author marko
 * 
 */
@RunWith(SpringJUnit4ClassRunner.class)
public class InspectorTest extends AbstractIntegrationContainerTest {
	/**
	 * logger.
	 */
	private static final Log log = LogFactory.getLog(InspectorTest.class); 

	/**
	 * httpunit conversation.
	 */
	private transient WebConversation conversation;

	/**
	 * common initialization.
	 * 
	 * @throws Exception
	 */
	@Before
	public void setUp() {
		conversation = new WebConversation();
	}

	/**
	 * test list controller.
	 * 
	 * @throws IOException shouldn't happen
	 * @throws SAXException shouldn't happen
	 */
	@Test
	public void testList() throws IOException, SAXException {
		
		log.info("TEST LIST");
		
		final WebResponse home = conversation.getResponse("http://localhost:8090/app/mvc/inspector/index.do/db/list");

		final WebLink link = home.getLinkWith("DRIVER");
		link.click();

		final WebResponse driver = conversation.getCurrentPage();
		final WebLink resourceTypesLink = driver.getLinkWith("DRIVERResourceTypes");
		resourceTypesLink.click();
		
		final WebResponse resourceTypes = conversation.getCurrentPage();
		assertNotNull("check resource types page", resourceTypes);
		
	}

}
