// Path: runAs-common/src/main/java/jetbrains/buildServer/runAs/common/Constants.java
// public class Constants {
//     // Plugin's ids
//     public static final String BUILD_FEATURE_TYPE = "runAs-build-feature";
//     public static final String RUN_AS_TOOL_NAME = "runAs";
// 
//     // Parameter names
//     public static final String USER = "teamcity.runAs.username";
//     public static final String PASSWORD = "secure:teamcity.runAs.password";
//     public static final String CONFIG_PASSWORD = "teamcity.runAs.password";
//     public static final String ADDITIONAL_ARGS = "teamcity.runAs.additionalCommandLine";
//     public static final String RUN_AS_ENABLED = "teamcity.agent.runAs.enabled";
//     public static final String CREDENTIALS_PROFILE_ID = "teamcity.runAs.profileId";
//     public static final String WINDOWS_INTEGRITY_LEVEL = "teamcity.runAs.windowsIntegrityLlevel";
//     public static final String LOGGING_LEVEL = "teamcity.runAs.loggingLevel";
//     public static final String ALLOW_CUSTOM_CREDENTIALS = "teamcity.runAs.allowCustomCredentials";
//     public static final String ALLOW_PROFILE_ID_FROM_SERVER = "teamcity.runAs.allowProfileIdFromServer";
//     public static final String CREDENTIALS_DIRECTORY = "teamcity.runAs.configDir";
//     public static final String RUN_AS_UI_ENABLED = "teamcity.runAs.ui.enabled";
//     public static final String RUN_AS_UI_STEPS_ENABLED = "teamcity.runAs.ui.steps.enabled";
//     public static final String RUN_AS_LOG_ENABLED = "teamcity.runAs.log.enabled";
//     public static final String RUN_AS_ACL = "teamcity.runAs.acl";
//     public static final String RUN_AS_ACL_DEFAULTS_ENABLED = "teamcity.runAs.acl.defaults.enabled";
// }
// 
// Path: runAs-common/src/main/java/jetbrains/buildServer/runAs/common/LoggingLevel.java
// public enum LoggingLevel {
//   Off("off", "Off"),
//   Errors("errors", "Errors"),
//   Normal("normal", "Normal"),
//   Debug("debug", "Debug");
// 
//   private final String myValue;
//   private final String myDescription;
// 
//   private LoggingLevel(String value, final String description) {
//     myValue = value;
//     myDescription = description;
//   }
// 
//   public String getValue() {
//     return myValue;
//   }
// 
//   public String getDescription() {
//     return myDescription;
//   }
// 
//   public static LoggingLevel tryParse(String value) {
//     for (LoggingLevel v : values()) {
//       if (v.getValue().equals(value)) return v;
//     }
// 
//     return Off;
//   }
// }
// 
// Path: runAs-common/src/main/java/jetbrains/buildServer/runAs/common/WindowsIntegrityLevel.java
// public enum WindowsIntegrityLevel {
//   Auto("auto", "Default"),
//   Untrusted("untrusted", "Untrusted"),
//   Low("low", "Low"),
//   Medium("medium", "Medium"),
//   MediumPlus("medium_plus", "Medium Plus"),
//   High("high", "High");
// 
//   private final String myValue;
//   private final String myDescription;
// 
//   private WindowsIntegrityLevel(String value, final String description) {
//     myValue = value;
//     myDescription = description;
//   }
// 
//   public String getValue() {
//     return myValue;
//   }
// 
//   public String getDescription() {
//     return myDescription;
//   }
// 
//   public static WindowsIntegrityLevel tryParse(String value) {
//     for (WindowsIntegrityLevel v : values()) {
//       if (v.getValue().equals(value)) return v;
//     }
// 
//     return Auto;
//   }
// }


import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.regex.Pattern;
import jetbrains.buildServer.dotNet.buildRunner.agent.*;
import jetbrains.buildServer.runAs.common.Constants;
import jetbrains.buildServer.runAs.common.LoggingLevel;
import jetbrains.buildServer.runAs.common.WindowsIntegrityLevel;
import jetbrains.buildServer.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.api.Invocation;
import org.jmock.lib.action.CustomAction;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.assertj.core.api.BDDAssertions.then;
          put(Constants.ALLOW_CUSTOM_CREDENTIALS, "true");
        }},
        new HashMap<String, HashMap<String, String>>() {{
          put("user2cred", new HashMap<String, String>() {{
          put(Constants.USER, "user2");
          put(Constants.PASSWORD, "password2");
          put(Constants.ADDITIONAL_ARGS, "arg1 arg2");
          put(Constants.WINDOWS_INTEGRITY_LEVEL, WindowsIntegrityLevel.High.getValue());
          put(Constants.LOGGING_LEVEL, LoggingLevel.Debug.getValue());
          }});
        }},
        new UserCredentials("user2cred", "user2", "password2", WindowsIntegrityLevel.High, LoggingLevel.Debug, Arrays.asList(new CommandLineArgument("arg1", CommandLineArgument.Type.PARAMETER), new CommandLineArgument("arg2", CommandLineArgument.Type.PARAMETER))),
        null
      },

      // Enabled && default credentials && update username in ACL
      {
        new HashMap<String, String>(),
        new HashMap<String, String>() {{
          put(Constants.ALLOW_PROFILE_ID_FROM_SERVER, "true");
          put(Constants.ALLOW_CUSTOM_CREDENTIALS, "true");
        }},
        new HashMap<String, HashMap<String, String>>() {{
          put(UserCredentialsServiceImpl.DEFAULT_PROFILE, new HashMap<String, String>() {{
          put(Constants.USER, "user78");
          put(Constants.PASSWORD, "password78");
          put(Constants.ADDITIONAL_ARGS, "arg1 arg2");
          put(Constants.WINDOWS_INTEGRITY_LEVEL, WindowsIntegrityLevel.High.getValue());
          put(Constants.LOGGING_LEVEL, LoggingLevel.Debug.getValue());
          put(Constants.RUN_AS_ACL, "acl");
// Path: runAs-common/src/main/java/jetbrains/buildServer/runAs/common/Constants.java
// public class Constants {
//     // Plugin's ids
//     public static final String BUILD_FEATURE_TYPE = "runAs-build-feature";
//     public static final String RUN_AS_TOOL_NAME = "runAs";
// 
//     // Parameter names
//     public static final String USER = "teamcity.runAs.username";
//     public static final String PASSWORD = "secure:teamcity.runAs.password";
//     public static final String CONFIG_PASSWORD = "teamcity.runAs.password";
//     public static final String ADDITIONAL_ARGS = "teamcity.runAs.additionalCommandLine";
//     public static final String RUN_AS_ENABLED = "teamcity.agent.runAs.enabled";
//     public static final String CREDENTIALS_PROFILE_ID = "teamcity.runAs.profileId";
//     public static final String WINDOWS_INTEGRITY_LEVEL = "teamcity.runAs.windowsIntegrityLlevel";
//     public static final String LOGGING_LEVEL = "teamcity.runAs.loggingLevel";
//     public static final String ALLOW_CUSTOM_CREDENTIALS = "teamcity.runAs.allowCustomCredentials";
//     public static final String ALLOW_PROFILE_ID_FROM_SERVER = "teamcity.runAs.allowProfileIdFromServer";
//     public static final String CREDENTIALS_DIRECTORY = "teamcity.runAs.configDir";
//     public static final String RUN_AS_UI_ENABLED = "teamcity.runAs.ui.enabled";
//     public static final String RUN_AS_UI_STEPS_ENABLED = "teamcity.runAs.ui.steps.enabled";
//     public static final String RUN_AS_LOG_ENABLED = "teamcity.runAs.log.enabled";
//     public static final String RUN_AS_ACL = "teamcity.runAs.acl";
//     public static final String RUN_AS_ACL_DEFAULTS_ENABLED = "teamcity.runAs.acl.defaults.enabled";
// }
// 
// Path: runAs-common/src/main/java/jetbrains/buildServer/runAs/common/LoggingLevel.java
// public enum LoggingLevel {
//   Off("off", "Off"),
//   Errors("errors", "Errors"),
//   Normal("normal", "Normal"),
//   Debug("debug", "Debug");
// 
//   private final String myValue;
//   private final String myDescription;
// 
//   private LoggingLevel(String value, final String description) {
//     myValue = value;
//     myDescription = description;
//   }
// 
//   public String getValue() {
//     return myValue;
//   }
// 
//   public String getDescription() {
//     return myDescription;
//   }
// 
//   public static LoggingLevel tryParse(String value) {
//     for (LoggingLevel v : values()) {
//       if (v.getValue().equals(value)) return v;
//     }
// 
//     return Off;
//   }
// }
// 
// Path: runAs-common/src/main/java/jetbrains/buildServer/runAs/common/WindowsIntegrityLevel.java
// public enum WindowsIntegrityLevel {
//   Auto("auto", "Default"),
//   Untrusted("untrusted", "Untrusted"),
//   Low("low", "Low"),
//   Medium("medium", "Medium"),
//   MediumPlus("medium_plus", "Medium Plus"),
//   High("high", "High");
// 
//   private final String myValue;
//   private final String myDescription;
// 
//   private WindowsIntegrityLevel(String value, final String description) {
//     myValue = value;
//     myDescription = description;
//   }
// 
//   public String getValue() {
//     return myValue;
//   }
// 
//   public String getDescription() {
//     return myDescription;
//   }
// 
//   public static WindowsIntegrityLevel tryParse(String value) {
//     for (WindowsIntegrityLevel v : values()) {
//       if (v.getValue().equals(value)) return v;
//     }
// 
//     return Auto;
//   }
// }


// Path: runAs-agent/src/test/java/jetbrains/buildServer/runAs/agent/UserCredentialsServiceTest.java
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.regex.Pattern;
import jetbrains.buildServer.dotNet.buildRunner.agent.*;
import jetbrains.buildServer.runAs.common.Constants;
import jetbrains.buildServer.runAs.common.LoggingLevel;
import jetbrains.buildServer.runAs.common.WindowsIntegrityLevel;
import jetbrains.buildServer.util.StringUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jmock.Expectations;
import org.jmock.Mockery;
import org.jmock.api.Invocation;
import org.jmock.lib.action.CustomAction;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.assertj.core.api.BDDAssertions.then;

          put(Constants.ALLOW_CUSTOM_CREDENTIALS, "true");
        }},
        new HashMap<String, HashMap<String, String>>() {{
          put("user2cred", new HashMap<String, String>() {{
          put(Constants.USER, "user2");
          put(Constants.PASSWORD, "password2");
          put(Constants.ADDITIONAL_ARGS, "arg1 arg2");
          put(Constants.WINDOWS_INTEGRITY_LEVEL, WindowsIntegrityLevel.High.getValue());
          put(Constants.LOGGING_LEVEL, LoggingLevel.Debug.getValue());
          }});
        }},
        new UserCredentials("user2cred", "user2", "password2", WindowsIntegrityLevel.High, LoggingLevel.Debug, Arrays.asList(new CommandLineArgument("arg1", CommandLineArgument.Type.PARAMETER), new CommandLineArgument("arg2", CommandLineArgument.Type.PARAMETER))),
        null
      },

      // Enabled && default credentials && update username in ACL
      {
        new HashMap<String, String>(),
        new HashMap<String, String>() {{
          put(Constants.ALLOW_PROFILE_ID_FROM_SERVER, "true");
          put(Constants.ALLOW_CUSTOM_CREDENTIALS, "true");
        }},
        new HashMap<String, HashMap<String, String>>() {{
          put(UserCredentialsServiceImpl.DEFAULT_PROFILE, new HashMap<String, String>() {{
          put(Constants.USER, "user78");
          put(Constants.PASSWORD, "password78");
          put(Constants.ADDITIONAL_ARGS, "arg1 arg2");
          put(Constants.WINDOWS_INTEGRITY_LEVEL, WindowsIntegrityLevel.High.getValue());
          put(Constants.LOGGING_LEVEL, LoggingLevel.Debug.getValue());
          put(Constants.RUN_AS_ACL, "acl");
          }});