Package marauroa.functional

Examples of marauroa.functional.SimpleClient$MockPerceptionListener


        public void run() {
          try {
            Random rand=new Random();
            System.out.println("Initing client");
            i = index++;
            SimpleClient client = new SimpleClient("client.properties");

            Thread.sleep(Math.abs(rand.nextInt() % 20) * 1000);

            client.connect("localhost", PORT);
            AccountResult resAcc = client.createAccount("testUsername" + i, "password","email");
            assertTrue("Account creation must not fail", !resAcc.failed());

            assertEquals("testUsername" + i, resAcc.getUsername());
            assertEquals(Result.OK_CREATED, resAcc.getResult());

            Thread.sleep(Math.abs(rand.nextInt() % 100) * 1000 + 5000);

            client.login("testUsername" + i, "password");

            RPObject template = new RPObject();
            template.put("client", "junit" + i);
            CharacterResult resChar = client.createCharacter("testCharacter", template);
            assertEquals("testCharacter", resChar.getCharacter());

            RPObject result = resChar.getTemplate();
            assertTrue(result.has("client"));
            assertEquals("junit" + i, result.get("client"));

            client.logout();

            for (int logins = 0; logins < TIMES_TO_LOGIN; logins++) {
              Thread.sleep(Math.abs(rand.nextInt() % 30) * 1000 + 5000);
              client.login("testUsername" + i, "password");

              String[] characters = client.getCharacters();
              assertEquals(1, characters.length);
              assertEquals("testCharacter", characters[0]);

              boolean choosen = client.chooseCharacter("testCharacter");
              assertTrue(choosen);

              int amount = Math.abs(rand.nextInt() % 90) + 10;
              while (client.getPerceptions() < amount) {
                client.loop(0);

                if (rand.nextInt() % 10 == 0) {
                  /*
                   * Send an action to server.
                   */
                  RPAction action = new RPAction();
                  action.put("type", "chat");
                  action.put("text", "Hello world");
                  client.send(action);
                }

                if (rand.nextInt() % 1000 == 0) {
                  /*
                   * Randomly close the connection
                   */
                  System.out
                          .println("FORCED CLOSE CONNECTION: Testint random disconnects on server");
                  client.close();
                  return;
                }

                Thread.sleep(1000);
              }

              client.logout();
            }

            client.close();
            Thread.sleep(Math.abs(rand.nextInt() % 60) * 1000);

          } catch (Exception e) {
            System.out.println("Problem for player: testUsername" + i);
            e.printStackTrace();
View Full Code Here


        @Override
        public void run() {
          try {
            System.out.println("Initing client");
            int i = index++;
            SimpleClient client = new SimpleClient("client.properties");

            client.connect("localhost", PORT);

            AccountResult resAcc = client.createAccount("testUsername" + i, "password", "email");
            assertTrue("Account creation must not fail", !resAcc.failed());
            assertEquals("testUsername" + i, resAcc.getUsername());

            Thread.sleep(Math.abs(new Random().nextInt() % 20) * 1000);

            client.login("testUsername" + i, "password");

            RPObject template = new RPObject();
            template.put("client", "junit" + i);
            CharacterResult resChar = client.createCharacter("testCharacter", template);
            assertEquals("testCharacter", resChar.getCharacter());

            RPObject result = resChar.getTemplate();
            assertTrue(result.has("client"));
            assertEquals("junit" + i, result.get("client"));

            String[] characters = client.getCharacters();
            assertEquals(1, characters.length);
            assertEquals("testCharacter", characters[0]);

            boolean choosen = client.chooseCharacter("testCharacter");
            assertTrue(choosen);

            int amount = Math.abs(new Random().nextInt() % 30) + 10;
            while (client.getPerceptions() < amount) {
              client.loop(0);

              if (new Random().nextInt() % 10 == 0) {
                /*
                 * Send an action to server.
                 */
                RPAction action = new RPAction();
                action.put("type", "chat");
                action.put("text", "Hello world");
                client.send(action);
              }

              for (RPObject object : client.getObjects().values()) {
                if (object.has("hidden")) {
                  fail("Not expected hidden object");
                }
              }

              Thread.sleep(1000);
            }

            System.out.println("Trying to leave server");
            assertTrue(client.logout());
            client.close();
            System.out.println("Leaved the server");
          } catch (Exception e) {
            e.printStackTrace();
            fail("Exception");
          } finally {
View Full Code Here

   * @throws BannedAddressException
   */

  public void t0_createAccount() throws IOException, TimeoutException,
      InvalidVersionException, BannedAddressException {
    client = new SimpleClient("log4j.properties");
    client.connect("localhost", PORT);
    AccountResult res = client.createAccount("testUsername", "password",
        "email");
    assertTrue("Account creation must not fail", !res.failed());

View Full Code Here

   * @throws Exception
   */

  public void t1_login() throws Exception {
    try {
      client = new SimpleClient("log4j.properties");
      client.connect("localhost", PORT);
      client.login("testUsername", "password");

      String[] characters = client.getCharacters();
      assertEquals(0, characters.length);
View Full Code Here

   *
   * @throws Exception
   */
  public void t1_1_loginTimeout() throws Exception {
    try {
      client = new SimpleClient("log4j.properties");
      client.connect("localhost", PORT);
      client.logout();

      client.close();
    } catch (TimeoutException e) {
View Full Code Here

   * @throws Exception
   */

  public void t1_1_login() throws Exception {
    try {
      client = new SimpleClient("log4j.properties");
      client.connect("localhost", PORT);
      client.login("testAnotherUsername", "NoPassword");
      fail("It must not login");
    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

   * @throws Exception
   */

  public void t3_loginDouble() throws Exception {
    try {
      client = new SimpleClient("log4j.properties");
      client.connect("localhost", PORT);
      client.login("testUsername", "password");

      SimpleClient altClient = new SimpleClient("log4j.properties");
      altClient.connect("localhost", PORT);
      altClient.login("testUsername", "password");

      String[] characters = altClient.getCharacters();
      assertEquals(0, characters.length);
    } catch (Exception e) {
      e.printStackTrace();
      throw e;
    }
View Full Code Here

   * @throws Exception
   */

  public void t4_createCharacter() throws Exception {
    try {
      client = new SimpleClient("log4j.properties");
      client.connect("localhost", PORT);
      client.login("testUsername", "password");

      RPObject template = new RPObject();
      template.put("client", "junit");
View Full Code Here

   * @throws Exception
   */

  public void t4_1_createCharacterFailure() throws Exception {
    try {
      client = new SimpleClient("log4j.properties");
      client.connect("localhost", PORT);
      client.login("testUsername", "password");

      RPObject template = new RPObject();
      template.put("client", "junit");
View Full Code Here

   * @throws Exception
   */

  public void t5_chooseCharacter() throws Exception {
    try {
      client = new SimpleClient("log4j.properties");
      client.connect("localhost", PORT);
      client.login("testUsername", "password");

      String[] characters = client.getCharacters();
      assertEquals(1, characters.length);
View Full Code Here

TOP

Related Classes of marauroa.functional.SimpleClient$MockPerceptionListener

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.