/*
 * 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.hadoop;

import alluxio.ConfigurationTestUtils;
import alluxio.conf.InstancedConfiguration;
import alluxio.conf.PropertyKey;
import alluxio.conf.Source;

import org.junit.After;
import org.junit.Assert;
import org.junit.Test;

/**
 * Tests for the {@link HadoopConfigurationUtils} class.
 */
public final class HadoopConfigurationUtilsTest {
  private static final String TEST_S3_ACCCES_KEY = "TEST ACCESS KEY";
  private static final String TEST_S3_SECRET_KEY = "TEST SECRET KEY";
  private static final String TEST_ALLUXIO_PROPERTY = "alluxio.unsupported.parameter";
  private static final String TEST_ALLUXIO_VALUE = "alluxio.unsupported.value";
  private InstancedConfiguration mConf = ConfigurationTestUtils.defaults();

  @After
  public void after() {
    mConf = ConfigurationTestUtils.defaults();
  }

  /**
   * Test for the {@link HadoopConfigurationUtils#mergeHadoopConfiguration} method for an empty
   * configuration.
   */
  @Test
  public void mergeEmptyHadoopConfiguration() {
    org.apache.hadoop.conf.Configuration hadoopConfig = new org.apache.hadoop.conf.Configuration();
    long beforeSize = mConf.toMap().size();
    mConf = HadoopConfigurationUtils.mergeHadoopConfiguration(hadoopConfig, mConf.copyProperties());
    long afterSize = mConf.toMap().size();
    Assert.assertEquals(beforeSize, afterSize);
    Assert.assertFalse(mConf.getBoolean(PropertyKey.ZOOKEEPER_ENABLED));
  }

  /**
   * Test for the {@link HadoopConfigurationUtils#mergeHadoopConfiguration} method.
   */
  @Test
  public void mergeHadoopConfiguration() {
    org.apache.hadoop.conf.Configuration hadoopConfig = new org.apache.hadoop.conf.Configuration();
    hadoopConfig.set(PropertyKey.S3A_ACCESS_KEY.toString(), TEST_S3_ACCCES_KEY);
    hadoopConfig.set(PropertyKey.S3A_SECRET_KEY.toString(), TEST_S3_SECRET_KEY);
    hadoopConfig.set(TEST_ALLUXIO_PROPERTY, TEST_ALLUXIO_VALUE);
    hadoopConfig.setBoolean(PropertyKey.ZOOKEEPER_ENABLED.getName(), true);
    hadoopConfig.set(PropertyKey.ZOOKEEPER_ADDRESS.getName(),
        "host1:port1,host2:port2;host3:port3");

    // This hadoop config will not be loaded into Alluxio configuration.
    hadoopConfig.set("hadoop.config.parameter", "hadoop config value");
    mConf = HadoopConfigurationUtils.mergeHadoopConfiguration(hadoopConfig, mConf.copyProperties());
    Assert.assertEquals(TEST_S3_ACCCES_KEY, mConf.get(PropertyKey.S3A_ACCESS_KEY));
    Assert.assertEquals(TEST_S3_SECRET_KEY, mConf.get(PropertyKey.S3A_SECRET_KEY));
    Assert.assertEquals(Source.RUNTIME, mConf.getSource(PropertyKey.S3A_ACCESS_KEY));
    Assert.assertEquals(Source.RUNTIME, mConf.getSource(PropertyKey.S3A_SECRET_KEY));
    Assert.assertTrue(mConf.getBoolean(PropertyKey.ZOOKEEPER_ENABLED));
    Assert.assertEquals("host1:port1,host2:port2;host3:port3",
        mConf.get(PropertyKey.ZOOKEEPER_ADDRESS));
  }
}

@@ -532,16 +532,149 @@
 adoop;%0A%0A
+import static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertFalse;%0Aimport static org.junit.Assert.assertTrue;%0A%0A
 import a
@@ -700,24 +700,24 @@
 nTestUtils;%0A
-
 import allux
@@ -838,33 +838,8 @@
 er;%0A
-import org.junit.Assert;%0A
 impo
@@ -1914,31 +1914,24 @@
 size();%0A    
-Assert.
 assertEquals
@@ -1955,31 +1955,24 @@
 rSize);%0A    
-Assert.
 assertFalse(
@@ -2929,39 +2929,32 @@
 perties());%0A    
-Assert.
 assertEquals(TES
@@ -3006,39 +3006,32 @@
 CESS_KEY));%0A    
-Assert.
 assertEquals(TES
@@ -3083,39 +3083,32 @@
 CRET_KEY));%0A    
-Assert.
 assertEquals(Sou
@@ -3162,39 +3162,32 @@
 CESS_KEY));%0A    
-Assert.
 assertEquals(Sou
@@ -3245,31 +3245,24 @@
 _KEY));%0A    
-Assert.
 assertTrue(m
@@ -3314,23 +3314,16 @@
 ));%0A    
-Assert.
 assertEq

Use static imports for standard test utilities