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

import alluxio.security.authentication.AuthenticatedClientUser;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runners.model.Statement;

/**
 * Unit tests for {@link ConfigurationRule}.
 */
public final class AuthenticatedUserRuleTest {

  @Test
  public void changeConfiguration() throws Throwable {
    Statement statement = new Statement() {
      @Override
      public void evaluate() throws Throwable {
        Assert.assertEquals("testuser", AuthenticatedClientUser.get().getName());
        Assert.assertTrue(Configuration.containsKey(PropertyKey.SECURITY_LOGIN_USERNAME));
      }
    };
    Assert.assertNull(AuthenticatedClientUser.get());
    Assert.assertFalse(Configuration.containsKey(PropertyKey.SECURITY_LOGIN_USERNAME));
    new AuthenticatedUserRule("testuser").apply(statement, null).evaluate();
    Assert.assertNull(AuthenticatedClientUser.get());
    Assert.assertFalse(Configuration.containsKey(PropertyKey.SECURITY_LOGIN_USERNAME));
  }
}

@@ -590,16 +590,40 @@
 tUser;%0A%0A
+import org.junit.After;%0A
 import o
@@ -734,29 +734,33 @@
  %7B@link 
-Configuration
+AuthenticatedUser
 Rule%7D.%0A 
@@ -813,75 +813,213 @@
 t %7B%0A
-%0A  @Test%0A  public void changeConfiguration() throws Throwable %7B%0A   
+  private static final String TESTCASE_USER = %22testcase-user%22;%0A  private static final String RULE_USER = %22rule-user%22;%0A  private static final String OUTSIDE_RULE_USER = %22outside-rule-user%22;%0A%0A  private final
  Sta
@@ -1025,17 +1025,18 @@
 atement 
-s
+mS
 tatement
@@ -1060,18 +1060,16 @@
 ) %7B%0A    
-  
 @Overrid
@@ -1070,18 +1070,16 @@
 verride%0A
-  
     publ
@@ -1118,26 +1118,24 @@
 ble %7B%0A      
-  
 Assert.asser
@@ -1142,26 +1142,25 @@
 tEquals(
-%22testuser%22
+RULE_USER
 , Authen
@@ -1205,97 +1205,139 @@
     
-  Assert.assertTrue(Configuration.containsKey(PropertyKey.SECURITY_LOGIN_USERNAME
+AuthenticatedClientUser.set(TESTCASE_USER);%0A      Assert.assertEquals(TESTCASE_USER, AuthenticatedClientUser.get().getName(
 ));%0A    
   %7D%0A
@@ -1336,41 +1336,70 @@
     
- 
- 
 %7D%0A
-  
   %7D;%0A
+%0A
   
-  Assert.assertNull(
+@After%0A  public void after() throws Exception %7B%0A    
 Auth
@@ -1422,101 +1422,133 @@
 ser.
-get
+remove
 ()
-)
 ;%0A  
-  Assert.assertFalse(Configuration.containsKey(PropertyKey.SECURITY_LOGIN_USERNAME)
+%7D%0A%0A  @Test%0A  public void userSetBeforeRule() throws Throwable %7B%0A    AuthenticatedClientUser.set(OUTSIDE_RULE_USER
 );%0A 
@@ -1580,26 +1580,25 @@
 ule(
-%22testuser%22
+RULE_USER
 ).apply(
 stat
@@ -1593,17 +1593,18 @@
 ).apply(
-s
+mS
 tatement
@@ -1644,13 +1644,34 @@
 sert
-Null(
+Equals(OUTSIDE_RULE_USER, 
 Auth
@@ -1699,95 +1699,259 @@
 et()
-);%0A    Assert.assertFalse(Configuration.containsKey(PropertyKey.SECURITY_LOGIN_USERNAME
+.getName());%0A  %7D%0A%0A  @Test%0A  public void noUserBeforeRule() throws Throwable %7B%0A    AuthenticatedClientUser.remove();%0A    new AuthenticatedUserRule(RULE_USER).apply(mStatement, null).evaluate();%0A    Assert.assertEquals(null, AuthenticatedClientUser.get(
 ));%0A

Add unit test for AuthenticatedUserRule