Package org.mozilla.javascript

Examples of org.mozilla.javascript.ScriptableObject$GetterSlot


  @Test
  @Ignore
  public void createSaveBoard() throws GameEngineException {
    API api = new API();
    ScriptableObject board = api.createBoard();

    String json = (String) ge.invoke(board, "stringify");

    Long id = api.getId(board);
    Entity result;
    if (id != null) {
      result = ge.persistence.save("Board", id, "json", json);
    } else {
      result = ge.persistence.save("Board");
      id = result.getKey().getId();
    }
    api.setId(board, result.getKey().getId());

    json = (String) ge.invoke(board, "stringify");

    result = ge.persistence.save("Board", id, "json", json);

    api.update(board, json);

    json = (String) ge.invoke(board, "stringify");

    assertEquals(1, board.get("id"));
  }
View Full Code Here


  }

  @Test
  public void createBoard() throws GameEngineException {

    ScriptableObject board = ge.execute("new Board();");

    ge.invoke(board, "grow", new Integer[] { 1, 0, 3, 1 });
    // board.grow(1, 0, 3, 1);

    ge.invoke(board, "grow", new Integer[] { 0, 1, 5, 3 });
    // board.grow(0, 1, 5, 3);

    ge.invoke(board, "grow", new Integer[] { 2, 4, 1, 1 });
    // board.grow(2, 4, 1, 1); // return the board data

    assertEquals(32, board.get("size"));

  }
View Full Code Here

  }

  @Test
  public void testAPI() throws GameEngineException {
    API api = new API();
    @SuppressWarnings("unused")
    ScriptableObject table = api.createTable("2", "50", "3", "6", "6",
        "neutral allowed", "annihilation");
  }
View Full Code Here

public class APITest extends GAETestCase {

  @Test
  public void newBoard() throws GameEngineException {
    API api = new API();
    ScriptableObject board = api.createBoard();
    assertEquals(32, board.get("size"));
  }
View Full Code Here

  @Test
  @Ignore
  public void stringify() throws GameEngineException {
    API api = new API();
    ScriptableObject board = api.save(api.createBoard());

    assertEquals(1L, board.get("id"));

    Object result = api.stringify(board);

    assertEquals("", result);
  }
View Full Code Here

  }

  @Test
  public void saveBoard() throws GameEngineException {
    API api = new API();
    ScriptableObject board = api.createBoard();
    assertEquals(32, board.get("size"));

    ScriptableObject s = api.save(board);

    assertEquals(1L, s.get("id"));
  }
View Full Code Here

  }

  @Test
  public void loadBoard() throws GameEngineException {
    API api = new API();
    ScriptableObject board1 = api.createBoard();
    assertEquals(32, board1.get("size"));

    board1 = api.save(board1);
    assertEquals(1L, board1.get("id"));

    ScriptableObject board2 = api.getBoard(1);
    assertEquals(1, board2.get("id"));
  }
View Full Code Here

  }

  @Test
  public void update() throws GameEngineException {
    API api = new API();
    ScriptableObject board = api.createBoard();
    assertEquals(32, board.get("size"));

    assertEquals(null, board.get("id"));

    GameEngine ge = new GameEngine(new String[] {
        "/com/antonytrupe/tend/Resource.js",
        "/com/antonytrupe/tend/ResourceGroup.js",
        "/com/antonytrupe/tend/Point.js",
        "/com/antonytrupe/tend/Board.js",
        "/com/antonytrupe/tend/Player.js",
        "/com/antonytrupe/tend/Trade.js",
        "/com/antonytrupe/tend/Settlement.js" });
    ge.invoke(board, "update", new String[] { "{\"board\":"
        + "{\"id\":1,\"players\":{}}" + "}" });
    assertEquals(1, board.get("id"));
  }
View Full Code Here

  @Test
  public void joinBoard() throws GameEngineException {
    API api = new API();
    Long boardId = null;
    String userName = "one";
    ScriptableObject board1 = api.joinBoard(boardId, userName);
    assertEquals(32, board1.get("size"));

    board1 = api.save(board1);
    assertEquals(1L, board1.get("id"));

    ScriptableObject board2 = api.getBoard(1);
    assertEquals(1, board2.get("id"));

    assertEquals(1, ((ScriptableObject) board2.get("players")).size());

    api.joinBoard(board2, userName);
    assertEquals(1, ((ScriptableObject) board2.get("players")).size());
    api.joinBoard(board2, "two");
    assertEquals(2, ((ScriptableObject) board2.get("players")).size());
  }
View Full Code Here

  @Test
  public void queueSettlement() throws GameEngineException {
    API api = new API();
    Long boardId = null;
    String playerName = "one";
    ScriptableObject board = api.joinBoard(boardId, playerName);
    assertEquals(32, board.get("size"));

    board = api.save(board);

    String settlementPoint = "{\"r\":1,\"g\":1,\"b\":1}";
    String resources = "{\"WHEAT\":1,\"FUR\":1,\"STONE\":1}";
    String settlementName = "HAMLET";
    api.queueSettlement(board, playerName, settlementPoint, settlementName,
        resources);

    // see if the location got saved
    ScriptableObject queuedSettlements = (ScriptableObject) ((ScriptableObject) ((ScriptableObject) board
        .get("players")).get(playerName)).get("queuedSettlements");
    assertEquals(1, queuedSettlements.size());
    assertEquals(settlementName, queuedSettlements.get(settlementPoint));

    // see if the queued resources got saved
    ScriptableObject queuedSettlementsResources = (ScriptableObject) ((ScriptableObject) ((ScriptableObject) board
        .get("players")).get(playerName))
        .get("queuedSettlementsResources");
    assertEquals(1, queuedSettlementsResources.size());
    assertEquals(1,
        ((ScriptableObject) queuedSettlementsResources
            .get(settlementPoint)).get("WHEAT"));
    assertEquals(1,
        ((ScriptableObject) queuedSettlementsResources
            .get(settlementPoint)).get("FUR"));
    assertEquals(1,
        ((ScriptableObject) queuedSettlementsResources
            .get(settlementPoint)).get("STONE"));

    // see if the queued resources got removed from the player
    ScriptableObject player = (ScriptableObject) ((ScriptableObject) board
        .get("players")).get(playerName);
    assertEquals(3.0,
        ((ScriptableObject) player.get("resources")).get("WHEAT"));
    assertEquals(2.0,
        ((ScriptableObject) player.get("resources")).get("FUR"));
    assertEquals(3.0,
        ((ScriptableObject) player.get("resources")).get("STONE"));
  }
View Full Code Here

TOP

Related Classes of org.mozilla.javascript.ScriptableObject$GetterSlot

Copyright © 2018 www.massapicom. 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.