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

import alluxio.CommonTestUtils;
import alluxio.Configuration;
import alluxio.PropertyKey;
import alluxio.security.authentication.AuthType;
import alluxio.security.authorization.Mode;
import alluxio.security.group.provider.IdentityUserGroupsMapping;
import alluxio.util.CommonUtils;

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

import java.io.IOException;
import java.util.Random;

/**
 * Tests for the {@link MkdirsOptions} class.
 */
public final class MkdirsOptionsTest {
  /**
   * Tests for default {@link MkdirsOptions}.
   */
  @Test
  public void defaults() throws IOException {
    MkdirsOptions options = MkdirsOptions.defaults();

    // Verify the default createParent is true.
    Assert.assertTrue(options.getCreateParent());
    // Verify that the owner and group are not set.
    Assert.assertEquals("", options.getOwner());
    Assert.assertEquals("", options.getGroup());
    Assert.assertEquals(Mode.defaults().applyDirectoryUMask(), options.getMode());
  }

  /**
   * Tests for building an {@link MkdirsOptions} with a security enabled
   * configuration.
   */
  @Test
  public void securityEnabled() throws IOException {
    Configuration.set(PropertyKey.SECURITY_AUTHENTICATION_TYPE, AuthType.SIMPLE.getAuthName());
    Configuration.set(PropertyKey.SECURITY_LOGIN_USERNAME, "foo");
    // Use IdentityUserGroupMapping to map user "foo" to group "foo".
    Configuration.set(PropertyKey.SECURITY_GROUP_MAPPING_CLASS,
        IdentityUserGroupsMapping.class.getName());

    MkdirsOptions options = MkdirsOptions.defaults();

    // Verify the default createParent is true.
    Assert.assertTrue(options.getCreateParent());
    // Verify that the owner and group are not set.
    Assert.assertEquals("", options.getOwner());
    Assert.assertEquals("", options.getGroup());
    Assert.assertEquals(Mode.defaults().applyDirectoryUMask(), options.getMode());
  }

  /**
   * Tests getting and setting fields.
   */
  @Test
  public void fields() {
    Random random = new Random();
    boolean createParent = random.nextBoolean();
    String owner = CommonUtils.randomAlphaNumString(10);
    String group = CommonUtils.randomAlphaNumString(10);
    Mode mode = new Mode((short) random.nextInt());

    MkdirsOptions options = MkdirsOptions.defaults();
    options.setCreateParent(createParent);
    options.setOwner(owner);
    options.setGroup(group);
    options.setMode(mode);

    Assert.assertEquals(createParent, options.getCreateParent());
    Assert.assertEquals(owner, options.getOwner());
    Assert.assertEquals(group, options.getGroup());
    Assert.assertEquals(mode, options.getMode());
  }

  @Test
  public void equalsTest() throws Exception {
    CommonTestUtils.testEquals(MkdirsOptions.class);
  }
}

@@ -537,24 +537,158 @@
 s.options;%0A%0A
+import static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertTrue;%0Aimport static org.junit.Assert.assertEquals;%0A%0A
 import allux
@@ -703,24 +703,24 @@
 nTestUtils;%0A
-
 import allux
@@ -1365,39 +1365,32 @@
 nt is true.%0A    
-Assert.
 assertTrue(optio
@@ -1460,39 +1460,32 @@
 re not set.%0A    
-Assert.
 assertEquals(%22%22,
@@ -1502,39 +1502,32 @@
 etOwner());%0A    
-Assert.
 assertEquals(%22%22,
@@ -1544,39 +1544,32 @@
 etGroup());%0A    
-Assert.
 assertEquals(Mod
@@ -2248,31 +2248,24 @@
 s true.%0A    
-Assert.
 assertTrue(o
@@ -2343,31 +2343,24 @@
 ot set.%0A    
-Assert.
 assertEquals
@@ -2381,39 +2381,32 @@
 etOwner());%0A    
-Assert.
 assertEquals(%22%22,
@@ -2423,39 +2423,32 @@
 etGroup());%0A    
-Assert.
 assertEquals(Mod
@@ -3025,31 +3025,24 @@
 mode);%0A%0A    
-Assert.
 assertEquals
@@ -3080,39 +3080,32 @@
 eParent());%0A    
-Assert.
 assertEquals(own
@@ -3125,39 +3125,32 @@
 etOwner());%0A    
-Assert.
 assertEquals(gro
@@ -3178,23 +3178,16 @@
 ));%0A    
-Assert.
 assertEq

use static imports in MkdirsOptionsTest.java