⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testloginworkflow.java

📁 考勤管理系统源码
💻 JAVA
字号:
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 junit.framework.*;

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

  public TestLoginWorkflow(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.LOGIN_WORKFLOW_HOME);
    LoginWorkflowHome lwhome = (LoginWorkflowHome)PortableRemoteObject.narrow(
                                          objref,LoginWorkflowHome.class);
    lwf = lwhome.create();
    junit.textui.TestRunner.run(TestLoginWorkflow.class);
  }

  public void testLoginWithInvalidName()throws RemoteException
  {
    try
    {
      boolean valid = lwf.isUserValid("syed", "abc123");
      fail("did not receive expected exception!");
    }
    catch(DataNotFoundException e)
    {
      System.out.println("received expected exception-" + " " + e);
    }
  }

  public void testLoginWithInvalidPassword()throws DataNotFoundException, RemoteException
  {
    boolean valid = lwf.isUserValid("fred", "a123");
    assertTrue("expected login failure.", !valid);
  }

  public static void testValidLogin()throws RemoteException
  {
    try
    {
      boolean valid = lwf.isUserValid("fred", "abc123");
      assertTrue("login falied.", valid);
    }
    catch(ApplicationException e)
    {
      fail("received unexpected exception-" + " " + e);
    }
  }

  public void testSetPasswordSuccess()throws RemoteException
  {
    try
    {
      lwf.setPassword("fred","abc123", "newp");
      boolean valid = lwf.isUserValid("fred", "newp");
      lwf.setPassword("fred","newp", "abc123");
    }
    catch(ApplicationException e)
    {
      fail("received unexpected exception-" + " " + e);
    }
  }

  public void testSetPasswordWithInvalidOldPassword() throws
  DataNotFoundException, RemoteException
  {
    try
    {
      lwf.setPassword("fred","ab123", "newp");
      fail("did not receive expected exception!");
    }
    catch(InvalidDataException e)
    {
      System.out.println("received expected exception-" + " " + e);
    }
  }

  public void testSetPasswordWithInvalidUser()throws RemoteException
  {
    try
    {
      lwf.setPassword("Syed","abc123", "newp");
      fail("did not receive expected exception!");
    }
    catch(DataNotFoundException e)
    {
      System.out.println("received expected exception-" + " " + e);
    }
    catch(InvalidDataException e)
    {
      fail("received unexpected exception-" + " " + e);
    }
  }

 public void testIsPasswordChangeRequiredWith()throws RemoteException
 {
   try
   {
     boolean isRequired = lwf.isPasswordChangeRequired("fred");
     assertTrue("expected fred's password to be not temporary.", !isRequired);
   }
   catch(DataNotFoundException e)
   {
     System.out.println("received expected exception-" + " " + e);
   }
  }
}

⌨️ 快捷键说明

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