package routines;

import static org.junit.jupiter.api.Assertions.*;

import org.junit.jupiter.api.Test;

class LcagLoggerTest {

	@Test
	void testSetJobLogLevel() {
		Integer intLevel = LcagLogger.LOG_INFO;

		intLevel = LcagLogger.LOG_INFO;


		LcagLogger.setJobLogLevel(intLevel);
		assert LcagLogger.getJobLogLevel() == intLevel;
		
		LcagLogger.setJobLogLevel("ERROR");
		assert LcagLogger.getJobLogLevel() == LcagLogger.LOG_ERROR;

		LcagLogger.setJobLogLevel("warn");
		assert LcagLogger.getJobLogLevel() == LcagLogger.LOG_WARN;

		LcagLogger.setJobLogLevel("LOG_ERROR");
		assert LcagLogger.getJobLogLevel() == LcagLogger.LOG_ERROR;

		LcagLogger.setJobLogLevel(null);
		assert LcagLogger.getJobLogLevel() == LcagLogger.LOG_ERROR;

		LcagLogger.setJobLogLevel("");
		assert LcagLogger.getJobLogLevel() == LcagLogger.LOG_ERROR;
	}

	@Test
	void testRestoreLogLevels() {
		LcagLogger.setJobLogLevel("LOG_TRACE");
		Integer	intLevel = LcagLogger.getJobLogLevel();
		
		// check precondition for a useful test:
		assert intLevel != LcagLogger.LOG_ERROR;
		
		LcagLogger.setJobLogLevel("ERROR");
		assert LcagLogger.getJobLogLevel() == LcagLogger.LOG_ERROR;
		
		LcagLogger.restoreLogLevels();
		assert LcagLogger.getJobLogLevel() == intLevel;

		// Restoring twice shall restore to previous Level:
		LcagLogger.restoreLogLevels();
		assert LcagLogger.getJobLogLevel() == LcagLogger.LOG_ERROR;
	}

	@Test
	void testAsString() {
		assertEquals(LcagLogger.asString(LcagLogger.LOG_DEBUG), "DEBUG");
		assertEquals(LcagLogger.asString(LcagLogger.LOG_WARN), "WARN");
		assertEquals(LcagLogger.asString(-9999), "OTHER");
	}

	@Test
	void testAsLevel() {
		assert LcagLogger.asLevel(LcagLogger.LOG_DEBUG) == LcagLogger.LOG_DEBUG;
		assert LcagLogger.asLevel("LOG_DEBUG") == LcagLogger.LOG_DEBUG;
		assert LcagLogger.asLevel("DEBUG") == LcagLogger.LOG_DEBUG;

		assertNull (LcagLogger.asLevel(null));
	}
	
	@Test
	void testWarn() {
		String s = LcagLogger.getLogger(LcagLoggerTest.class).warn("%s WARN", "Test");
		
		assertEquals("Test WARN", s);
	}

}
