
|
Deriving Structural and Interaction Test Cases Testing distributed
architectures State based testing Event based testing
of JavaBean |
TicTacToe Game Testing distributed architectures Test case scenario We have 3 ORBS - one for the Game, and one for each Player, Player0 and Player1. Each of the 3 ORBS can be filled in any order, although we will be showing the order as Game, Player 0 and Player 1 in our animation. The Game is looking for 2 players. Each Player is programmed to look for a game. Game and the 2 players will query the ORB until what they need shows up. Both Game and Player contain the same logic except what they are looking for. ORB on the Game end of the Deployment diagram has been created and initialized.
import RemoteInterface.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
public abstract class Game extends _RemoteGameImplBase
{
abstract public void setMove(RemoteInterface.Move newMove);
abstract public void resetGame();
static NamingContext ncRef = null; // move to game
// PreCondition: This should be one of the first methods called
// ORBArgs = options for initializing the Corba ORB
// i.e. "-ORBInitialPort 1050" or null
// PostCondition: The ORB is initialized, the Game is made servant
// on the ORB, and the NamingContect, ncRef,
// is set in order to obtain ORB servants.
void connect(String ORBArgs[])
{
try {
// create and initialize the ORB
ORB orb = ORB.init(ORBArgs, null);
// register game with ORB
orb.connect(this);
// get the root naming context
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
ncRef = NamingContextHelper.narrow(objRef);
// bind the Object Reference in Naming
NameComponent nc = new NameComponent("Game", "");
NameComponent path[] = {nc};
ncRef.rebind(path, this);
}
catch (Exception e) {
System.err.println("Error in game.connect" + e);
e.printStackTrace();
System.exit(1); // we should throw an exception here
}
... // more code ...
public abstract class Game
... ( as shown above)
// PreCondition: The Game.connect() method has been
// succesfully executed
// PostCondition: returns a "RemotePlayer" with the
// name "PlayerName" from the orb
public RemotePlayer getRemotePlayer(String playerName)
{
RemotePlayer remotePlayer = null;
while( true){ // remotePlayer == null
try {
// resolve the Object Reference in Naming
NameComponent nc = new NameComponent(playerName, "");
NameComponent path[] = {nc};
remotePlayer = RemotePlayerHelper.narrow(ncRef.resolve(path));
return remotePlayer;
}
catch (Exception e) {
System.out.println("waiting for player = " + playerName);
}
}
}
}
ORB on the Player end of the Deployment diagram now shows Player0 and Player1 ORBS have been created and initialized, and Naming has happened.
// package Java.TicTacToe.Game;
import RemoteInterface.*;
import org.omg.CosNaming.*;
import org.omg.CORBA.*;
// Player is a Corba Servant Class for the Game Framework
public abstract class Player
extends _RemotePlayerImplBase{
... (more code here - related to other aspect of Player Class goes here)
// Establishes connection with RemoteGame
// and makes player a servant class so
// that the RemoteGame can call us.
public void initialize( String ORBArgs[] )
{
try {
// create and initialize the ORB
orb = ORB.init(ORBArgs, null);
// get the root naming context
org.omg.CORBA.Object objRef =
orb.resolve_initial_references("NameService");
NamingContext ncRef = NamingContextHelper.narrow(objRef);
// resolve the Object Reference in Naming
NameComponent nc = new NameComponent("Game", "");
NameComponent path[] = {nc};
//System.out.println("Going after Game\n");
while( true ) {
try {
remoteGame = RemoteGameHelper.narrow(ncRef.resolve(path));
break;
}
catch (Exception e) {
e.printStackTrace();
}
}
// create servant and register it with the ORB
orb.connect(this);
// bind the Object Reference in Naming
// Register Player as Player
Animation of test result
Demonstration: Complete deployment diagram Illustrate success by all 3 ORBs, the TicTacToe Game, and the 2 Players on the Deployment diagram filled in blue to show they have been created and initialized and the connections have happened. The connections between the components to show in red. |
Funded by Committee of University Teaching And Staff Development (CUTSD) through DEETYA, 1998