TestLogSystem.java

 
 
// Lapetus Ltd Java Class.  Copyright (c) Lapetus Systems Ltd, 2009, 2010. 
// ----------------------------------------------------------------------- 
// This is the intellectual property of Lapetus Systems Ltd, Artemis, Greece. 
// -------------------------------------------------------------------------- 
// www.lapetus-ltd.com, www.lapetus.com.gr, www.lapetus.eu 
// ------------------------------------------------------- 
// $LastChangedRevision: 1168 $ 
// $LastChangedDate:: 2010-11-06 16:41:19#$ 
// ---------------------------------------- 
 
 
import com.lapetus_ltd.api.TLptsMainJut; 
import com.lapetus_ltd.api.common.logger.TLptsLog; 
import com.lapetus_ltd.api.common.logger.TLptsLogger; 
import junit.framework.TestCase; 
 
 
// ###################################################################################################### 
// ####    Test code for the JUT build process.  This code will stop the build process on ERROR      #### 
// ###################################################################################################### 
 
// Class Description : This is the test class for the Logger. 
// 
// As our test classes go, this is a fairly simple one. 
// It adds 10000 logs of known types and then reads them for verification. 
// 
 
 
 
public class TestLogSystem extends TestCase 
{ 
  public static void main(String[] args) 
  { 
    TestLogSystem test = new TestLogSystem(); 
    test.testGenerateLotsOfLogsAndReadThem(false); 
  } 
 
  public void testGenerateLotsOfLogsAndReadThem(boolean isExit) 
  { 
    TLptsMainJut.init(); 
    synchroLogger(); 
 
    if (isExit) 
      System.exit(0); 
  } 
 
  private void synchroLogger() 
  { 
    int logNo = 10000; 
    TLptsLogger.clearLogList(); 
    TLptsLogger.setMaxLogListSize(logNo); 
 
    System.out.println("Generating "  + logNo + " logs ... "); 
 
    for (int i=1; i<=logNo; i++) 
    { 
      if ((i % 4)==0) 
        TLptsLogger.logError("Error Test #" + i, new Exception("New Exception for " + i)); 
      if ((i % 4)==1) 
        TLptsLogger.logDebug("Debug Test #" + i, new Exception("New Exception for " + i)); 
      if ((i % 4)==2) 
        TLptsLogger.logMessage("Message Test #" + i, new Exception("New Exception for " + i)); 
      if ((i % 4)==3) 
        TLptsLogger.logWarning("Warning Test #" + i, new Exception("New Exception for " + i)); 
    } 
    System.out.println("Completed ..."); 
 
    try 
    { 
      int logs = TLptsLogger.getLogListSize(); 
      assertEquals("Incorrect number of logs in system : " + logs,logNo,logs); 
    } catch (Exception e) 
    { 
      fail("Could not get log list"); 
    } 
 
    System.out.println("Showing last 100 logs : "); 
    int i=0; 
    for (TLptsLog log : TLptsLogger.getLogList(true)) 
    { 
      if (i++==100) 
        break; 
 
      System.out.println("log  " + log.getMessage() + log.getExceptionMessage()); 
      if (log.getType().equals(TLptsLogger.LOG_TYPE.DEBUG)) 
        if (!log.getMessage().startsWith("Debug")) 
          fail("Type of log is inconsistent for debug : " + log.getMessage()); 
      if (log.getType().equals(TLptsLogger.LOG_TYPE.ERROR)) 
        if (!log.getMessage().startsWith("Error")) 
          fail("Type of log is inconsistent for error : " + log.getMessage()); 
      if (log.getType().equals(TLptsLogger.LOG_TYPE.WARNING)) 
        if (!log.getMessage().startsWith("Warning")) 
          fail("Type of log is inconsistent for warning : " + log.getMessage()); 
      if (log.getType().equals(TLptsLogger.LOG_TYPE.MESSAGE)) 
        if (!log.getMessage().startsWith("Message")) 
          fail("Type of log is inconsistent for message : " + log.getMessage()); 
    } 
    System.out.println("Logs were verified correctly ..."); 
  } 
}