testrecordtimeworkflow.java

来自「考勤管理系统源码」· Java 代码 · 共 161 行

JAVA
161
字号
package com.wiley.compBooks.EJwithUML.Clients;

import javax.naming.*;
import javax.ejb.*;
import java.rmi.*;
import javax.rmi.PortableRemoteObject;
import java.util.*;
import com.wiley.compBooks.EJwithUML.TimeCardDomain.*;
import com.wiley.compBooks.EJwithUML.Dtos.*;
import com.wiley.compBooks.EJwithUML.TimeCardWorkflow.*;
import com.wiley.compBooks.EJwithUML.Base.ApplicationExceptions.*;
import com.wiley.compBooks.EJwithUML.Base.EjbUtil.*;
import com.wiley.compBooks.EJwithUML.Base.DateUtil;
import junit.framework.*;

/**
 * This is JUint test class for testing RecordTimeWorkflow EJB. This
 * test assumes that the EJB is running and accessible.
 */
public class TestRecordTimeWorkflow extends TestCase
{
  private static LoginWorkflow lwf;
  private static RecordTimeWorkflow rtwf;
  private static String testCaseToRun;

  public TestRecordTimeWorkflow(String name)
  {
    super(name);
  }

  /** Executes all the test case */
  public static void main(String[] args)throws CreateException, NamingException,
                                        RemoteException
  {
    Context initial = new InitialContext();
    Object objref = initial.lookup(EjbReferenceNames.RECORD_TIME_WORKFLOW_HOME);
    RecordTimeWorkflowHome rtwhome = (RecordTimeWorkflowHome )
                                     PortableRemoteObject.narrow(objref,
                                     RecordTimeWorkflowHome.class);
    rtwf = rtwhome.create("fred");
    if (args.length > 0)
    {
      TestRecordTimeWorkflow.testCaseToRun= args[0];
    }
    junit.textui.TestRunner.run(suite());
  }

  /** groups all test cases into a test suite. */
  public static Test suite()
  {
     TestSuite suite = null;
     if (TestRecordTimeWorkflow.testCaseToRun == null)
     {
        // runs all test cases
       suite = new TestSuite(TestRecordTimeWorkflow.class);
     }
     else
     {
       suite = new TestSuite();
       suite.addTest(new TestRecordTimeWorkflow(
                                TestRecordTimeWorkflow.testCaseToRun));
     }
     return suite;
  }

  public void testGetCurrentTimecard()
  {
    try
    {
      TimecardDTO card = rtwf.getCurrentTimecard();
      System.out.println(card);
    }
    catch(Exception e)
    {
      fail("received unexpected exception-" + e);
    }
  }

  public void testUpdateTimecardWithNewEntry()
  {
    try
    {
      TimecardDTO card = rtwf.getCurrentTimecard();
      TimeEntryDTO newEntry = new TimeEntryDTO("Ford", "Paint", "Mustang", 4,
          card.getStartDate());
      card.addEntry(newEntry);
      newEntry = new TimeEntryDTO("Ford", "UpgradeEngine","Mustang", 4,
                                  card.getStartDate());
      card.addEntry(newEntry);
      rtwf.updateTimecard(card);
    }
    catch(Exception e)
    {
      fail("received unexpected exception-" + e);
    }
  }

  public void testUpdateTimecardWithExistingEntry()
  {
   try
   {
     TimecardDTO card = rtwf.getCurrentTimecard();
     Iterator entryItr = card.getEntries();
     while(entryItr.hasNext())
     {
       TimeEntryDTO existingEntry = (TimeEntryDTO)entryItr.next();
       existingEntry.setHours(5);
       System.out.println("updated one entry- " + existingEntry);
       break;
     }
     rtwf.updateTimecard(card);
   }
   catch(Exception e)
   {
     fail("received unexpected exception-" + e);
   }
  }

  public void testGetClient()
  {
    try
    {
      ClientDTO client = rtwf.getClient("GM");
      System.out.println(client);
    }
    catch(Exception e)
    {
      fail("received unexpected exception-" + e);
    }
  }

  public void testGetAllClients()
  {
    try
    {
      Collection clients = rtwf.getAllClients();
      Iterator clientIterator = clients.iterator();
      while(clientIterator.hasNext())
      {
        System.out.println((ClientDTO)clientIterator.next());
      }

    }
    catch(Exception e)
    {
      fail("received unexpected exception-" + e);
    }
  }

  public void testSubmitTimecard()
  {
    try
    {
      rtwf.submitTimecard();
    }
    catch(Exception e)
    {
      fail("received unexpected exception-" + e);
    }
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?