package com.starbucks.eom.tools.log4j;

import org.apache.log4j.Logger;

import junit.framework.TestCase;

/**
 * Provides unit tests for the InterfaceLoggerFactoryTest class.
 */
public class InterfaceLoggerFactoryTest extends TestCase {

	private static final Logger log = Logger.getLogger(InterfaceLoggerFactoryTest.class);

    /**
     * Indicates that this class is of type <code>UnitTest</code>.
     * Used by the TestCaseLoader to dynamically locate tests to run in the suite method.
     */
    public static final String TEST_ALL_TEST_TYPE = "UnitTest";

    /**
     * Constructor to add this TestCase to the JUnit framework.
     */
     public InterfaceLoggerFactoryTest(String name) {
          super(name);
     }

    /**
     * Configures the test instance.
     */
	public void setUp() throws Exception {
        super.setUp();
        //
	}

    /**
     * Cleans up the test instance.
     */
	public void tearDown() throws Exception {
        super.tearDown();
        //
	}

	/**
	 * Ensures the custom log4j logger factory correctly concatenates the class name with
	 * the interface name.
	 */
	public void testGetLoggers() {

		String customerSubInterface = "CustomerInbound";
		String storePubInterface = "StoreOutbound";
	    LoggingClass a = new LoggingClassA();
	    LoggingClass b = new LoggingClassB();

	    String interfaceName = customerSubInterface;
	    String expected = a.getClass().getName() + "." + interfaceName;
	    Logger log = null;

	    //test simple case
	    log = a.getInterfaceLogger(interfaceName);
	    log.debug("test");
	    assertEquals("Failed to get correct logger name for class=" + a.getClass().getName() +
	    			 " and interface name=" + interfaceName,
	    			 expected,
	    			 log.getName());


		//test same class different interface
		interfaceName = storePubInterface;
		expected = a.getClass().getName() + "." + interfaceName;
		log = a.getInterfaceLogger(interfaceName);
		log.debug("test");
	    assertEquals("Failed to get correct logger name for class=" + a.getClass().getName() +
	    			 " and interface name=" + interfaceName,
	    			 expected,
	    			 log.getName());

		//test diff class diff interface
		interfaceName = customerSubInterface;
		expected = b.getClass().getName() + "." + interfaceName;
		log = b.getInterfaceLogger(interfaceName);
		log.debug("test");
	    assertEquals("Failed to get correct logger name for class=" + b.getClass().getName() +
	    			 " and interface name=" + interfaceName,
	    			 expected,
	    			 log.getName());

	    //test diff class same interface
		expected = b.getClass().getName() + "." + interfaceName;
		log = b.getInterfaceLogger(interfaceName);
		log.debug("test");
	    assertEquals("Failed to get correct logger name for class=" + b.getClass().getName() +
	    			 " and interface name=" + interfaceName,
	    			 expected,
	    			 log.getName());
	}
}