@Test
public void testMoveApplicationSubmitTargetQueue() throws Exception {

  // move the application as the owner
  ApplicationId applicationId = getApplicationId(1);
  UserGroupInformation aclUGI = UserGroupInformation.getCurrentUser();
  QueueACLsManager queueACLsManager = getQueueAclManager("allowed_queue",
      QueueACL.SUBMIT_APPLICATIONS, aclUGI);
  ApplicationACLsManager appAclsManager = getAppAclManager();
  ClientRMService rmService = createClientRMServiceForMoveApplicationRequest(
      applicationId, aclUGI.getShortUserName(), appAclsManager,
      queueACLsManager);
  // move as the owner queue in the acl
  MoveApplicationAcrossQueuesRequest moveAppRequest =
      MoveApplicationAcrossQueuesRequest.
      newInstance(applicationId, "allowed_queue");
  rmService.moveApplicationAcrossQueues(moveAppRequest);
  // move as the owner queue not in the acl
  moveAppRequest = MoveApplicationAcrossQueuesRequest.newInstance(
      applicationId, "not_allowed");
  try {
    rmService.moveApplicationAcrossQueues(moveAppRequest);
    Assert.fail("The request should fail with an AccessControlException");
  } catch (YarnException rex) {
    Assert.assertTrue("AccessControlException is expected",
        rex.getCause() instanceof AccessControlException);
  }
  // ACL is owned by "moveuser", move is performed as a different user
  aclUGI = UserGroupInformation.createUserForTesting("moveuser",
      new String[]{});
  queueACLsManager = getQueueAclManager("move_queue",
      QueueACL.SUBMIT_APPLICATIONS, aclUGI);
  appAclsManager = getAppAclManager();
  ClientRMService rmService2 =
      createClientRMServiceForMoveApplicationRequest(applicationId,
          aclUGI.getShortUserName(), appAclsManager, queueACLsManager);
  // access to the queue not OK: user not allowed in this queue
  MoveApplicationAcrossQueuesRequest moveAppRequest2 =
      MoveApplicationAcrossQueuesRequest.
          newInstance(applicationId, "move_queue");
  try {
    rmService2.moveApplicationAcrossQueues(moveAppRequest2);
    Assert.fail("The request should fail with an AccessControlException");
  } catch (YarnException rex) {
    Assert.assertTrue("AccessControlException is expected",
        rex.getCause() instanceof AccessControlException);
  }
  // execute the move as the acl owner
  // access to the queue OK: user allowed in this queue
  aclUGI.doAs(new PrivilegedExceptionAction<Object>() {
    @Override
    public Object run() throws Exception {
      return rmService2.moveApplicationAcrossQueues(moveAppRequest2);
    }
  });
}