/*
 * The Alluxio Open Foundation licenses this work under the Apache License, version 2.0
 * (the "License"). You may not use this work except in compliance with the License, which is
 * available at www.apache.org/licenses/LICENSE-2.0
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
 * either express or implied, as more fully set forth in the License.
 *
 * See the NOTICE file distributed with this work for information regarding copyright ownership.
 */

package alluxio.cli;

import static org.junit.Assert.assertEquals;

import alluxio.PropertyKey;
import alluxio.SystemOutRule;

import org.junit.Rule;
import org.junit.Test;

import java.io.ByteArrayOutputStream;

/**
 * Tests for {@link GetConfKey}.
 */
public final class GetConfKeyTest {
  private ByteArrayOutputStream mOutputStream = new ByteArrayOutputStream();

  @Rule
  public SystemOutRule mOutputStreamRule = new SystemOutRule(mOutputStream);

  @Test
  public void getConfKey() throws Exception {
    String varName = PropertyKey.WORKER_MEMORY_SIZE.getName().toUpperCase().replace(".", "_");
    assertEquals(0, GetConfKey.getConfKey(varName));
    assertEquals(String.format("%s\n", PropertyKey.WORKER_MEMORY_SIZE.getName()),
        mOutputStream.toString());

    mOutputStream.reset();
    varName = "AWS_ACCESSKEYID";
    assertEquals(0, GetConfKey.getConfKey(varName));
    assertEquals(String.format("%s\n", PropertyKey.S3A_ACCESS_KEY.getName()),
        mOutputStream.toString());

    mOutputStream.reset();
    assertEquals(1, GetConfKey.getConfKey("ALLUXIO_INVALID_COMMAND"));
  }
}

@@ -590,27 +590,29 @@
 alluxio.
-PropertyKey
+Configuration
 ;%0Aimport
@@ -995,16 +995,36 @@
 tConfKey
+WithAllPropertyNames
 () throw
@@ -1045,458 +1045,644 @@
     
+for (
 String 
-varName = PropertyKey.WORKER_MEMORY_SIZE.getName().toUpperCase().replace(%22.%22, %22_%22);%0A    assertEquals(0, GetConfKey.getConfKey(varName));%0A    assertEquals(String.format(%22%25s%5Cn%22, PropertyKey.WORKER_MEMORY_SIZE.getName()),%0A        mOutputStream.toString());%0A%0A    mOutputStream.reset();%0A    varName = %22AWS_ACCESSKEYID%22;%0A    assertEquals(0, GetConfKey.getConfKey(varName));%0A    assertEquals(String.format(%22%25s%5Cn%22, PropertyKey.S3A_ACCESS_KEY.get
+key : Configuration.toMap().keySet()) %7B%0A      assertConfKey(key.toUpperCase().replace(%22.%22, %22_%22), key, 0);%0A    %7D%0A  %7D%0A%0A  @Test%0A  public void getConfKeyWithInvalidName() throws Exception %7B%0A    assertConfKey(%22ALLUXIO_INVALID_COMMAND%22, %22%22, 1);%0A  %7D%0A%0A  private void assertConfKey(String varName, String confKey, int returnValue) %7B%0A    mOutputStream.reset();%0A    assertEquals(String.format(%22check return value of getConfKey with variable name %25s%22, varName),%0A        returnValue, GetConfKey.getConfKey(varName));%0A    if (returnValue == 0) %7B%0A      assertEquals(String.format(%22check output of getConfKey with variable name %25s%22, var
 Name
-()
 ),%0A 
@@ -1687,16 +1687,27 @@
 %0A       
+   confKey,
  mOutput
@@ -1727,109 +1727,23 @@
 ng()
-);%0A%0A    mOutputStream.reset();%0A    assertEquals(1, GetConfKey.getConfKey(%22ALLUXIO_INVALID_COMMAND%22));
+.trim());%0A    %7D
 %0A  %7D

improve unit tests for getConfKey