Package web.servlets.tests

Source Code of web.servlets.tests.WebServletsTests

package web.servlets.tests;


import static net.sourceforge.jwebunit.junit.JWebUnit.*;
import static org.junit.Assert.*;

import java.io.IOException;


import net.sourceforge.jwebunit.junit.JWebUnit;

import org.junit.Before;
import org.junit.Test;
import org.scotlandyard.engine.constants.LoginStatus;
import org.scotlandyard.engine.json.ExceptionJsonContainer;
import org.scotlandyard.engine.json.JsonContainerAdapter;
import org.scotlandyard.engine.json.LoginStatusJsonContainer;

/**
* TODO add description
*
* @author Hussain Al-Mutawa
* @version 1.0
* @since Sept 2011
*
*/
public class WebServletsTests {


 
    @Before//TODO add description here
    public void prepare() {
        setBaseUrl("http://localhost:8084/sy");
        beginAt("/ResetGameEngine");
    }
 
  @Test//TODO add description here
  public void senarioTest() throws Exception{
    int users_count=0,games_count=0;
        gotoPage("/index.jsp");
        Thread.sleep(500);
        users_count = Integer.parseInt(getElementById("users_count").getTextContent());
        games_count = Integer.parseInt(getElementById("games_count").getTextContent());
       
        String json="";
        gotoPage("/GetLoginStatus");
        json=getPageSource();
        LoginStatus loginStatus=new LoginStatusJsonContainer().fromJson(json).loginStatus;
        if(loginStatus==LoginStatus.LoggedIn){
          gotoPage("/Logout");
          final JsonContainerAdapter jsonObj = new JsonContainerAdapter().fromJson(getServerResponse());
          if(jsonObj.objectName.equals("ExceptionJsonContainer")){
            throw new Exception(jsonObj.message.toString());
          }
        }
        gotoPage("/login.jsp");
        assertTitleEquals("ScotlandYard Game - Login");
        setTextField("name", "test");
        setTextField("email", "test123");
        clickButton("loginButton");
        //Thread.sleep(500);
        assertTitleEquals("ScotlandYard Game - Lobby");
        //getting the number of users online
       
        int users_count2 = Integer.parseInt(getElementById("users_count").getTextContent());
       
        assertEquals("testing that number of users is incremented by 1",
            users_count+1,
            users_count2);
       
        if(games_count==0){
          submit("createGameSubmit");
          assertTitleEquals("ScotlandYard Game - Game creattion zone");
          setTextField("gameId", "New Game");
          clickButton("createGameButton");
          //Thread.sleep(200);
          assertTitleEquals("ScotlandYard Game - Lobby");
          games_count = Integer.parseInt(getElementById("games_count").getTextContent());
          assertEquals(
              "games count should be one now",
              1, games_count);
         
          assertTitleEquals("ScotlandYard Game - Lobby");
         
          //this should fail for the time being
          //TODO remove this segment when creation of more
          //than one game is allowed
          synchronized(this){
            gotoPage("/createGame.jsp");
            setTextField("gameId", "New Game");
            clickButton("createGameButton");
            String expectedMessage = "Can not create more than one game at the moment, will add this feature later";
            assertEquals("the expected error message",
                expectedMessage,
                getElementById("lastInvokedJSONmessage").getAttribute("value"));
            games_count = Integer.parseInt(getElementById("games_count").getTextContent());
            assertEquals(
                "games count should be one,because it is not allowed to create more than one game",
                1, games_count);
          }
         
         
         
          //clickLink()
         
        }
       
  }
 
}



TOP

Related Classes of web.servlets.tests.WebServletsTests

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.