Package play.test

Examples of play.test.FakeRequest


  }
 
  public void routeDeleteFollowRelationship(String follower,String toUnfollow)
  {
   
    FakeRequest request = new FakeRequest(DELETE, getRouteAddress()+"/"+toUnfollow);
    request = request.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
    request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.encodeAuth(follower, "passw1"));
   
    Result result = routeAndCall(request);
    assertRoute(result, "Delete friendship.", Status.OK, null, false);
    //now if I ask for the ex-friend profile, I couldn't see its FriendAttributes fields
   
    request = new FakeRequest(GET, "/user/"+toUnfollow);
    request = request.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
    request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.encodeAuth(follower, "passw1"));
    result = routeAndCall(request);
    assertRoute(result, "Check no friendship.", Status.OK, null, false);
    String resultString = contentAsString(result);
    if (resultString.contains("+39334060606")) assertFail("FriendshipUserTest (routeDeleteFollowRelationship) failed! The ex-friend still see private fields!");
   
View Full Code Here


      new Runnable()
      {
        public void run()
        {
          // Default user credentials
          FakeRequest request = new FakeRequest(getMethod(), getRouteAddress());
          request = request.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
          request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_DEFAULT_ENC);
          Result result = routeAndCall(request);
          assertRoute(result, "testRouteDefaultUser", FORBIDDEN, null, false);
        }
      }
    );   
View Full Code Here

  }
 
  public void routeDeleteUnexistentFollowRelationship(String follower,String toUnfollow)
  {
   
    FakeRequest request = new FakeRequest(DELETE, getRouteAddress()+"/"+toUnfollow);
    request = request.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
    request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.encodeAuth(follower, "passw1"));
   
    Result result = routeAndCall(request);
    assertRoute(result, "Delete friendship.", Status.NOT_FOUND, null, false);

   
View Full Code Here

      new Runnable()
      {
        public void run()
        {
          // No AppCode, No Authorization
          FakeRequest request = new FakeRequest(getMethod(), getRouteAddress());
          Result result = routeAndCall(request);
          assertRoute(result, "No AppCode No Authorization", BAD_REQUEST, TestConfig.MSG_NO_APP_CODE_NO_AUTH, true);
 
         
          // Invalid AppCode
          request = request.withHeader(TestConfig.KEY_APPCODE, "12345890");
          request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
          result = routeAndCall(request);
          assertRoute(result, "Invalid AppCode", UNAUTHORIZED, TestConfig.MSG_INVALID_APP_CODE, true);
 
          // Invalid Authorization
          request = request.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
          request = request.withHeader(TestConfig.KEY_AUTH, "Basic dXNlcjE6cGFzc3c=");
          result = routeAndCall(request);
          assertRoute(result, "Invalid Authorization", UNAUTHORIZED, null, false);
         
          // No AppCode
          request = new FakeRequest(getMethod(), getRouteAddress());
          request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
          result = routeAndCall(request);
          assertRoute(result, "No AppCode", BAD_REQUEST, TestConfig.MSG_NO_APP_CODE, true);
        }
      }
    );   
View Full Code Here

   
  }
  public void routeCreateCollectionForTest()
  {
   
    FakeRequest request = new FakeRequest(POST, "/admin/collection/testFriendship");
    request = request.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
    request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
   
    Result result = routeAndCall(request);
   
  }
View Full Code Here

  }
 
  public String routeCreateDocument(String owner)
  {
   
    FakeRequest request = new FakeRequest(POST, "/document/testFriendship");
    request = request.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
    request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.encodeAuth(owner, "passw1"));
    request = request.withJsonBody(getPayload("/documentCreatePayload.json"));
    Result result = routeAndCall(request);
    assertRoute(result, "Create document.", Status.OK, null, false);
    return contentAsString(result);
   
  }
View Full Code Here

          String content = routeCreateDocument(secondUser);
          JSONObject result = (JSONObject)toJSON(content);
          try {
            String uuid = result.getJSONObject("data").getString("id");
            assertNotNull(uuid);
            FakeRequest fk = new FakeRequest(GET, "/document/testFriendship/"+uuid);
            fk = fk.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
            fk = fk.withHeader(TestConfig.KEY_AUTH, TestConfig.encodeAuth(firstUser, "passw1"));
            Result getDocumentResult = routeAndCall(fk);
            assertRoute(getDocumentResult, "Get document by friend", Status.NOT_FOUND, null, false);
           
            //the owner of the doc gives grant to its friends
            fk = new FakeRequest(PUT, "/document/testFriendship/"+uuid+"/read/role/friends_of_"+secondUser);
            fk = fk.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
            fk = fk.withHeader(TestConfig.KEY_AUTH, TestConfig.encodeAuth(secondUser, "passw1"));
            Result res = routeAndCall(fk);
            assertRoute(res, "Change the document permission", Status.OK, null, false);
           
            //now the friend reload the doc and read it
            fk = new FakeRequest(GET, "/document/testFriendship/"+uuid);
            fk = fk.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
            fk = fk.withHeader(TestConfig.KEY_AUTH, TestConfig.encodeAuth(firstUser, "passw1"));
            getDocumentResult = routeAndCall(fk);
            assertRoute(getDocumentResult, "Get document by friend 2", Status.OK, null, false);
            JSONObject createdDocument = (JSONObject)toJSON(contentAsString(getDocumentResult));
            String author = createdDocument.getJSONObject("data").getString("_author");
            assertEquals(secondUser,author);
           
            FakeRequest theFolloweds = new FakeRequest(GET, "/following");
            theFolloweds = theFolloweds.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
            theFolloweds = theFolloweds.withHeader(TestConfig.KEY_AUTH, TestConfig.encodeAuth(firstUser, "passw1"));
           
            Result getTheFollowedResult = routeAndCall(theFolloweds);
            JSONObject followedJson = (JSONObject)toJSON(contentAsString(getTheFollowedResult));
            String followed = followedJson.getJSONArray("data").getJSONObject(0).getJSONObject("user").getString("name");
            assertEquals(followed,secondUser);
           
            //check the followers
            FakeRequest followers = new FakeRequest(GET, "/followers");
            followers = followers.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
            followers = followers.withHeader(TestConfig.KEY_AUTH, TestConfig.encodeAuth(secondUser, "passw1"));
            Result getFollowersResult = routeAndCall(followers);
            JSONObject followersJson = (JSONObject)toJSON(contentAsString(getFollowersResult));
            String follower = followersJson.getJSONArray("data").getJSONObject(0).getJSONObject("user").getString("name");
            assertEquals(follower,firstUser);
           
            //the first user get the followers of the second one
            followers = new FakeRequest(GET, "/followers/"+secondUser);
            followers = followers.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
            followers = followers.withHeader(TestConfig.KEY_AUTH, TestConfig.encodeAuth(firstUser, "passw1"));
            getFollowersResult = routeAndCall(followers);
            followersJson = (JSONObject)toJSON(contentAsString(getFollowersResult));
            follower = followersJson.getJSONArray("data").getJSONObject(0).getJSONObject("user").getString("name");
            assertEquals("test: GET /followers/:secondUser firstUser="+firstUser+" secondUser="+secondUser,follower,firstUser);

            //the second user get the followed by the first one
            FakeRequest followeds = new FakeRequest(GET, "/following/"+firstUser);
            followeds = followeds.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
            followeds = followeds.withHeader(TestConfig.KEY_AUTH, TestConfig.encodeAuth(secondUser, "passw1"));
            Result getFollowedsResult = routeAndCall(followeds);
            JSONObject followedsJson = (JSONObject)toJSON(contentAsString(getFollowedsResult));
            followed = followedsJson.getJSONArray("data").getJSONObject(0).getJSONObject("user").getString("name");
            assertEquals("test: GET /following/:firstUser firstUser="+firstUser+" secondUser="+secondUser,followed,secondUser);
           
View Full Code Here

      getFakeApplication(),
      new Runnable()
      {
        public void run()
        {
          FakeRequest request = new FakeRequest(getMethod(), getRouteAddress());
          request = request.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
          request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
          Result result = routeAndCall(request);
          assertRoute(result, "testRouteOK", OK, null, true);
        }
      }
    );   
View Full Code Here

      new Runnable()
      {
        public void run()
        {
          // Default user credentials
          FakeRequest request = new FakeRequest(getMethod(), getRouteAddress());
          request = request.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
          request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_DEFAULT_ENC);
          Result result = routeAndCall(request);
          assertRoute(result, "testRouteDefaultUser", FORBIDDEN, null, false);
        }
      }
    );   
View Full Code Here

      new Runnable()
      {
        public void run()
        {
          //load settings
          FakeRequest request = new FakeRequest(GET, "/admin/configuration/dump.json");
          request = request.withHeader(TestConfig.KEY_APPCODE, TestConfig.VALUE_APPCODE);
          request = request.withHeader(TestConfig.KEY_AUTH, TestConfig.AUTH_ADMIN_ENC);
          Result result = routeAndCall(request);
          AbstractAdminTest.super.assertRoute(result, "checkSettingsBefore", OK, "application.name\":\"BaasBox\",\"description\":\"The App name\",\"type\":\"String\",\"editable\":true,\"visible\":true,\"overridden\":false", true);
        }
      }
      );
View Full Code Here

TOP

Related Classes of play.test.FakeRequest

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.