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

import alluxio.AlluxioURI;
import alluxio.Configuration;
import alluxio.ConfigurationTestUtils;
import alluxio.PropertyKey;
import alluxio.client.lineage.options.DeleteLineageOptions;
import alluxio.client.util.ClientTestUtils;
import alluxio.job.CommandLineJob;
import alluxio.job.JobConf;

import com.google.common.collect.Lists;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import java.util.List;

/**
 * Tests {@link AlluxioLineage}.
 */
@RunWith(PowerMockRunner.class)
@PrepareForTest({LineageContext.class, LineageMasterClient.class})
public final class AlluxioLineageTest {
  private LineageContext mLineageContext;
  private LineageMasterClient mLineageMasterClient;
  private AlluxioLineage mAlluxioLineage;

  @Before
  public void before() throws Exception {
    Configuration.set(PropertyKey.USER_LINEAGE_ENABLED, "true");
    mLineageMasterClient = PowerMockito.mock(LineageMasterClient.class);
    mLineageContext = PowerMockito.mock(LineageContext.class);
    Mockito.when(mLineageContext.acquireMasterClient()).thenReturn(mLineageMasterClient);
    mAlluxioLineage = AlluxioLineage.get(mLineageContext);
  }

  @After
  public void after() {
    ConfigurationTestUtils.resetConfiguration();
    ClientTestUtils.resetClient();
  }

  @Test
  public void createLineage() throws Exception {
    List<AlluxioURI> inputFiles = Lists.newArrayList(new AlluxioURI("input"));
    List<AlluxioURI> outputFiles = Lists.newArrayList(new AlluxioURI("output"));
    CommandLineJob job = new CommandLineJob("cmd", new JobConf("out"));
    mAlluxioLineage.createLineage(inputFiles, outputFiles, job);
    Mockito.verify(mLineageMasterClient).createLineage(Lists.newArrayList("input"),
        Lists.newArrayList("output"), job);
    // verify client is released
    Mockito.verify(mLineageContext).releaseMasterClient(mLineageMasterClient);
  }

  @Test
  public void deleteLineage() throws Exception {
    DeleteLineageOptions options = DeleteLineageOptions.defaults().setCascade(true);
    mAlluxioLineage.deleteLineage(0, options);
    Mockito.verify(mLineageMasterClient).deleteLineage(0, true);
    // verify client is released
    Mockito.verify(mLineageContext).releaseMasterClient(mLineageMasterClient);
  }

  @Test
  public void getLineageInfoList() throws Exception {
    mAlluxioLineage.getLineageInfoList();
    Mockito.verify(mLineageMasterClient).getLineageInfoList();
    // verify client is released
    Mockito.verify(mLineageContext).releaseMasterClient(mLineageMasterClient);
  }
}

@@ -555,26 +555,17 @@
 alluxio.
-AlluxioURI
+*
 ;%0Aimport
@@ -573,29 +573,32 @@
 alluxio.
-Configuration
+client.WriteType
 ;%0Aimport
@@ -610,58 +610,48 @@
 xio.
-ConfigurationTestUtils;%0Aimport alluxio.PropertyKey
+client.file.options.OutStreamOptionsTest
 ;%0Aim
@@ -816,16 +816,63 @@
 bConf;%0A%0A
+import com.google.common.collect.ImmutableMap;%0A
 import c
@@ -952,16 +952,39 @@
 Before;%0A
+import org.junit.Rule;%0A
 import o
@@ -1226,16 +1226,42 @@
 unner;%0A%0A
+import java.util.HashMap;%0A
 import j
@@ -1596,21 +1596,19 @@
 ge;%0A%0A  @
-Befor
+Rul
 e%0A  publ
@@ -1614,44 +1614,60 @@
 lic 
-void before() throws Exception %7B%0A   
+ConfigurationRule mConfigurationRule =%0A          new
  Con
@@ -1676,20 +1676,20 @@
 guration
-.set
+Rule
 (Propert
@@ -1723,16 +1723,69 @@
 %22true%22);
+%0A%0A  @Before%0A  public void before() throws Exception %7B
 %0A    mLi
@@ -2104,57 +2104,8 @@
 ) %7B%0A
-    ConfigurationTestUtils.resetConfiguration();%0A
     

Use ConfigurationRule to avoid manually setting and resetting Configuration:Refactor configuration usage in AlluxioLineageTest