[Batchserver-cvs] batchserver/test/org/jmonks/batch/framework ErrorCodeTest.java, NONE, 1.1 Framewo
Brought to you by:
suresh_pragada
From: Suresh <sur...@us...> - 2006-09-15 20:21:16
|
Update of /cvsroot/batchserver/batchserver/test/org/jmonks/batch/framework In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv26727 Added Files: ErrorCodeTest.java FrameworkTestSuite.java JobStatisticsTest.java LoggingManagerTest.java MainTest.java RepositoryTest.java Log Message: no message --- NEW FILE: MainTest.java --- /* * MainTest.java * JUnit based test * * Created on September 5, 2006, 3:32 PM */ package org.jmonks.batch.framework; import java.util.HashMap; import java.util.Map; import junit.framework.*; /** * * @author w951h8m */ public class MainTest extends TestCase { public MainTest(String testName) { super(testName); } public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest(new MainTest("testProcess")); //suite.addTest(new MainTest("testProcessNoArgs")); //suite.addTest(new MainTest("testProcessNullArgs")); //suite.addTest(new MainTest("testProcessWrongJobName")); return suite; } /** * Test of process method by passing the right configuration. */ public void testProcess() { Map args=new HashMap(); args.put(Main.JOB_NAME_KEY_NAME, "process_file_xyz"); ErrorCode returnCode=Main.process(args); assertNotNull(returnCode); assertEquals(ErrorCode.JOB_COMPLETED_SUCCESSFULLY.getCode(), returnCode.getCode()); } /** * Test of process method by passing the empty configMap. */ public void testProcessNoArgs() { Map args=new HashMap(); ErrorCode returnCode=Main.process(args); assertNotNull(returnCode); int exitCode=returnCode.getCode(); assertEquals(ErrorCode.JOB_INVOKATION_CONFIGURAION_ERROR.getCode(), exitCode); } /** * Test of process method by passing the null configMap. */ public void testProcessNullArgs() { try { ErrorCode returnCode=Main.process(null); fail("Framework is accepting the null configMap"); } catch(IllegalArgumentException exception){} } /** * Test of process method by passing the wrong job name in config map. */ public void testProcessWrongJobName() { Map args=new HashMap(); args.put(Main.JOB_NAME_KEY_NAME, "NOT_AVAILABLE"); ErrorCode returnCode=Main.process(args); assertNotNull(returnCode); int exitCode=returnCode.getCode(); assertEquals(ErrorCode.JOB_IS_NOT_CONFIGURED.getCode(), exitCode); } } --- NEW FILE: FrameworkTestSuite.java --- /* * FrameworkTestSuite.java * JUnit based test * * Created on March 3, 2006, 8:29 PM */ package org.jmonks.batch.framework; import junit.framework.*; import org.jmonks.batch.framework.repository.jdbc.MySQLJdbcRepositoryTest; import org.jmonks.batch.framework.repository.jdbc.OracleJdbcRepositoryTest; import org.jmonks.batch.framework.util.FrameworkUtilTest; import org.jmonks.batch.framework.config.BasicJobControllerConfigTest; import org.jmonks.batch.framework.config.ConfigurationExceptionTest; import org.jmonks.batch.framework.config.FrameworkConfigTest; import org.jmonks.batch.framework.config.JobConfigFactoryTest; import org.jmonks.batch.framework.config.JobConfigTest; import org.jmonks.batch.framework.config.JobControllerConfigTest; import org.jmonks.batch.framework.config.PoolJobControllerConfigTest; import org.jmonks.batch.framework.repository.db4o.Db4oRepositoryTest; import org.jmonks.batch.framework.util.JdbcConnectionHelperTest; /** * This is the main suite for the framework. This actually decides which suites * needs to be considered as the framework suite. * * @author Suresh Pragada */ public class FrameworkTestSuite extends TestCase { public FrameworkTestSuite(String testName) { super(testName); } protected void setUp() throws Exception { } protected void tearDown() throws Exception { } /** * suite method returns all the suites to be considered as a framework suite. */ public static Test suite() { TestSuite mainSuite = new TestSuite(); mainSuite.addTest(ErrorCodeTest.suite()); mainSuite.addTest(JobStatisticsTest.suite()); mainSuite.addTest(RepositoryTest.suite()); mainSuite.addTest(LoggingManagerTest.suite()); mainSuite.addTest(FrameworkUtilTest.suite()); mainSuite.addTest(JdbcConnectionHelperTest.suite()); mainSuite.addTest(FrameworkConfigTest.suite()); mainSuite.addTest(ConfigurationExceptionTest.suite()); mainSuite.addTest(JobConfigTest.suite()); mainSuite.addTest(JobControllerConfigTest.suite()); mainSuite.addTest(JobConfigFactoryTest.suite()); mainSuite.addTest(BasicJobControllerConfigTest.suite()); mainSuite.addTest(PoolJobControllerConfigTest.suite()); mainSuite.addTest(Db4oRepositoryTest.suite()); mainSuite.addTest(MySQLJdbcRepositoryTest.suite()); mainSuite.addTest(OracleJdbcRepositoryTest.suite()); mainSuite.addTest(MainTest.suite()); return mainSuite; } } --- NEW FILE: LoggingManagerTest.java --- /* * LoggingManagerTest.java * JUnit based test * * Created on March 12, 2006, 1:31 PM */ package org.jmonks.batch.framework; import junit.framework.*; import org.apache.log4j.Logger; import org.jmonks.batch.framework.config.JobLoggingConfig; import org.jmonks.batch.framework.config.JobConfigFactory; import org.jmonks.batch.framework.config.FrameworkConfig; import org.jmonks.batch.framework.config.JobConfig; /** * * @author Suresh Pragada */ public class LoggingManagerTest extends TestCase { private FrameworkConfig frameworkConfig=null; public LoggingManagerTest(String testName) { super(testName); } protected void setUp() throws Exception { frameworkConfig=FrameworkConfig.getInstance(); } protected void tearDown() throws Exception { } public static Test suite() { //TestSuite suite = new TestSuite(LoggingManagerTest.class); TestSuite suite=new TestSuite(); suite.addTest(new LoggingManagerTest("testInitializeFrameworkLogging")); suite.addTest(new LoggingManagerTest("testInitializeJobLogging")); return suite; } /** * Test of initializeJobLogging method, of class org.jmonks.batchserver.framework.LoggingManager. */ public void testInitializeJobLogging() { assertNotNull(frameworkConfig); FrameworkConfig.FrameworkLoggingConfig loggingConfig=frameworkConfig.getFrameworkLoggingConfig(); assertNotNull(loggingConfig); FrameworkConfig.JobConfigFactoryConfig configFactoryConfig=frameworkConfig.getJobConfigFactoryConfig(); assertNotNull(configFactoryConfig); JobConfigFactory factory=JobConfigFactory.getJobConfigFactory(configFactoryConfig); assertNotNull(factory); JobConfig jobConfig=factory.getJobConfig("process_file_xyz"); assertNotNull(jobConfig); JobLoggingConfig jobLoggingConfig=jobConfig.getJobLoggingConfig(); assertNotNull(jobLoggingConfig); LoggingManager.initializeJobLogging("process_file_xyz", loggingConfig,jobLoggingConfig); Logger logger=Logger.getLogger(LoggingManagerTest.class); logger.debug("This is debug message after job initialization"); logger.info("This is info message after job initialization"); logger.warn("This is warn message after job initialization"); logger.error("This is error message after job initialization"); } /** * Test of initializeLogging method, of class org.jmonks.batchserver.framework.LoggingManager. */ public void testInitializeFrameworkLogging() { assertNotNull(frameworkConfig); FrameworkConfig.FrameworkLoggingConfig loggingConfig=frameworkConfig.getFrameworkLoggingConfig(); assertNotNull(loggingConfig); LoggingManager.initializeFrameworkLogging(loggingConfig); Logger logger=Logger.getLogger(LoggingManagerTest.class); logger.debug("This is debug message"); logger.info("This is info message"); logger.warn("This is warn message"); logger.error("This is error message"); } } --- NEW FILE: ErrorCodeTest.java --- /* * ErrorCodeTest.java * JUnit based test * * Created on March 3, 2006, 8:12 PM */ package org.jmonks.batch.framework; import junit.framework.*; /** * Test cases to test the ErrorCode.java. * * @author Suresh Pragada */ public class ErrorCodeTest extends TestCase { public ErrorCodeTest(String testName) { super(testName); } protected void setUp() throws Exception { super.setUp(); } protected void tearDown() throws Exception { super.tearDown(); } public static Test suite() { TestSuite suite = new TestSuite(ErrorCodeTest.class); return suite; } /** * Test that getCode is returning the expected errorCode. */ public void testGetCode() { ErrorCode errorCode=ErrorCode.JOB_COMPLETED_SUCCESSFULLY; assertEquals(0,errorCode.getCode()); } /** * Test that getMessage is not returning null. */ public void testGetMessage() { ErrorCode errorCode=ErrorCode.JOB_COMPLETED_SUCCESSFULLY; assertNotNull(errorCode.getMessage()); } /** * Test that ErrorCode cannot be instantiated. */ public void testInstantiation() { try { ErrorCode errorCode=(ErrorCode)ErrorCode.class.newInstance(); fail("ErrorCode should not be instantiated."); } catch(InstantiationException ex) { /** * This is expected as ErrorCode cannot be instantiated. */ } catch(IllegalAccessException ex) { /** * This is expected as the constructor of ErrorCode is private. */ } } public void testCreateErrorCode() { ErrorCode errorCode=ErrorCode.createErrorCode(10001,"This is my error code."); assertNotNull(errorCode); assertEquals(10001, errorCode.getCode()); assertEquals("This is my error code.",errorCode.getMessage()); errorCode=errorCode.appendMessage("New Message"); assertTrue(errorCode.getMessage().startsWith("This is my error code.")); assertTrue(errorCode.getMessage().endsWith("New Message")); } public void testEquality() { ErrorCode errorCode1=ErrorCode.createErrorCode(10001,"This is my first error code."); ErrorCode errorCode2=ErrorCode.createErrorCode(10001,"This is my second error code."); assertTrue(errorCode1.equals(errorCode2)); assertFalse(errorCode1==errorCode2); } } --- NEW FILE: JobStatisticsTest.java --- /* * JobStatisticsTest.java * JUnit based test * * Created on September 13, 2006, 11:12 PM */ package org.jmonks.batch.framework; import java.util.Calendar; import junit.framework.*; /** * * @author Suresh Pragada */ public class JobStatisticsTest extends TestCase { public JobStatisticsTest(String testName) { super(testName); } protected void setUp() throws Exception { } protected void tearDown() throws Exception { } public static Test suite() { TestSuite suite = new TestSuite(JobStatisticsTest.class); return suite; } public void testJobStatistics() { JobStatistics stats=new JobStatistics("process_file_abc"); stats.setStartTime(Calendar.getInstance().getTime()); stats.setEndTime(Calendar.getInstance().getTime()); stats.setExitCode(ErrorCode.createErrorCode(10001, "This is my error code")); stats.setMaxMemeoryUsage(100001); stats.setRecordsProcessed(10001); assertEquals("process_file_abc",stats.getJobname()); assertNotNull(stats.getStartTime()); assertNotNull(stats.getEndTime()); assertEquals(100001, stats.getMaxMemoryUsage()); assertEquals(10001, stats.getRecordsProcessed()); assertTrue(ErrorCode.createErrorCode(10001, "This is my error code").equals(stats.getExitCode())); } } --- NEW FILE: RepositoryTest.java --- /* * RepositoryTest.java * JUnit based test * * Created on September 12, 2006, 10:16 PM */ package org.jmonks.batch.framework; import junit.framework.*; /** * * @author Suresh Pragada */ public class RepositoryTest extends TestCase { public RepositoryTest(String testName) { super(testName); } protected void setUp() throws Exception { } protected void tearDown() throws Exception { } public static Test suite() { TestSuite suite = new TestSuite(); suite.addTest(new RepositoryTest("testInstantiation")); suite.addTest(new RepositoryTest("testCreateReport")); return suite; } /** * Test to make sure repository cannot be instantiated. */ public void testInstantiation() { try { Repository repository=(Repository)Repository.class.newInstance(); fail("Repository should not be instantiated."); } catch(InstantiationException ex) { /** * This is expected as Repository cannot be instantiated. */ } catch(IllegalAccessException ex) { /** * This is expected as the constructor of Repository is protected. */ } } public void testCreateReport() { try { Repository.createRepository("process_file_abc", null, null); fail("Should have thrown SecurityException."); } catch(SecurityException ex) { } } } |