@Test
  public void testBeelineConnectEnvVar() throws Throwable {
    final String jdbcUrl = miniHS2.getBaseJdbcURL();
    List<String> argList = new ArrayList<>();
    argList.add("-u");
    argList.add("blue");
    argList.add("-d");
    argList.add(BeeLine.BEELINE_DEFAULT_JDBC_DRIVER);

    final String SCRIPT_TEXT =
        "create table blueconnecttest (d int);\nshow tables;\ndrop table blueconnecttest;\n";
    final String EXPECTED_PATTERN = "blueconnecttest";

    // We go through these hijinxes because java considers System.getEnv
    // to be read-only, and offers no way to set an env var from within
    // a process, only for processes that we sub-spawn.

    final BeeLineOpts.Env baseEnv = BeeLineOpts.getEnv();
    BeeLineOpts.Env newEnv = new BeeLineOpts.Env() {
      @Override
      public String get(String envVar) {
        if (envVar.equalsIgnoreCase("BEELINE_URL_BLUE")){
          return jdbcUrl;
        } else {
          return baseEnv.get(envVar);
        }
      }
    };
    BeeLineOpts.setEnv(newEnv);

    testScriptFile(SCRIPT_TEXT, argList, OutStream.OUT,
        Collections.singletonList(new Tuple<>(EXPECTED_PATTERN, true)),
        Collections.singletonList(Modes.SCRIPT));
  }
Test Beeline !connect with beeline saved vars
@throws Throwable
itests/hive-unit/src/test/java/org/apache/hive/beeline/TestBeeLineWithArgs.java