Advertisement
Guest User

GlassFishTestHelper

a guest
Jan 17th, 2011
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.24 KB | None | 0 0
  1. public class GlassFishTestHelper {
  2.  
  3.  
  4.     public static void createFileUser(String userName, String userPassword, String userGroups) throws Exception {
  5.         // Get the running arquillian embedded glassfish
  6.         Server server = Server.getServer(Server.getServerNames().get(0));
  7.         String command = "create-file-user";
  8.         ParameterMap params = new ParameterMap();
  9.         params.add("userpassword", userPassword);
  10.         params.add("groups", userGroups);
  11.         params.add("username", userName);
  12.         CommandRunner runner = server.getHabitat().getComponent(CommandRunner.class);
  13.         ActionReport report = server.getHabitat().getComponent(ActionReport.class);
  14.         runner.getCommandInvocation(command, report).parameters(params).execute();
  15.  
  16.         if (report.getMessage() != null) {
  17.             throw new Exception(String.format("Failed to create user : %s - message %s",
  18.                     userName, report.getMessage()), report.getFailureCause());
  19.         }
  20.     }
  21.  
  22.     public static boolean loginFileUser(String userName, String userPassword) throws Exception {
  23.         ProgrammaticLogin pgLogin = new ProgrammaticLogin();
  24.         return pgLogin.login(userName, userPassword.toCharArray(), "fileRealm", true);
  25.     }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement