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

import alluxio.CommonTestUtils;
import alluxio.Configuration;
import alluxio.ConfigurationTestUtils;
import alluxio.PropertyKey;
import alluxio.Constants;
import alluxio.security.authorization.Mode;
import alluxio.util.CommonUtils;
import alluxio.wire.TtlAction;

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

import java.util.Random;

/**
 * Unit tests for {@link CreateDirectoryOptions}.
 */
public final class CreateDirectoryOptionsTest {
  /**
   * Tests the {@link CreateDirectoryOptions#defaults()} method.
   */
  @Test
  public void defaults() throws Exception {
    Configuration.set(PropertyKey.USER_BLOCK_SIZE_BYTES_DEFAULT, "64MB");

    CreateDirectoryOptions options = CreateDirectoryOptions.defaults();

    Assert.assertEquals(false, options.isAllowExists());
    Assert.assertEquals("", options.getOwner());
    Assert.assertEquals("", options.getGroup());
    Assert.assertEquals(Mode.defaults().applyDirectoryUMask(), options.getMode());
    Assert.assertFalse(options.isPersisted());
    Assert.assertFalse(options.isRecursive());
    Assert.assertEquals(Constants.NO_TTL, options.getTtl());
    Assert.assertEquals(TtlAction.DELETE, options.getTtlAction());
    ConfigurationTestUtils.resetConfiguration();
  }

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

    boolean persisted = random.nextBoolean();
    boolean recursive = random.nextBoolean();
    long ttl = random.nextLong();

    CreateDirectoryOptions options = CreateDirectoryOptions.defaults()
        .setAllowExists(allowExists)
        .setMountPoint(mountPoint)
        .setOperationTimeMs(operationTimeMs)
        .setPersisted(persisted)
        .setOwner(owner)
        .setGroup(group)
        .setMode(mode)
        .setRecursive(recursive)
        .setTtl(ttl)
        .setTtlAction(TtlAction.FREE);

    Assert.assertEquals(allowExists, options.isAllowExists());
    Assert.assertEquals(mountPoint, options.isMountPoint());
    Assert.assertEquals(operationTimeMs, options.getOperationTimeMs());
    Assert.assertEquals(persisted, options.isPersisted());
    Assert.assertEquals(owner, options.getOwner());
    Assert.assertEquals(group, options.getGroup());
    Assert.assertEquals(mode, options.getMode());
    Assert.assertEquals(recursive, options.isRecursive());
    Assert.assertEquals(ttl, options.getTtl());
    Assert.assertEquals(TtlAction.FREE, options.getTtlAction());
  }

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

@@ -545,16 +545,106 @@
 tions;%0A%0A
+import static org.junit.Assert.assertEquals;%0Aimport static org.junit.Assert.assertFalse;%0A%0A
 import a
@@ -659,32 +659,32 @@
 ommonTestUtils;%0A
-
 import alluxio.C
@@ -903,33 +903,8 @@
 n;%0A%0A
-import org.junit.Assert;%0A
 impo
@@ -1331,28 +1331,20 @@
 ults();%0A
-%0A
     
-Assert.
 assertEq
@@ -1377,39 +1377,32 @@
 wExists());%0A    
-Assert.
 assertEquals(%22%22,
@@ -1419,39 +1419,32 @@
 etOwner());%0A    
-Assert.
 assertEquals(%22%22,
@@ -1461,39 +1461,32 @@
 etGroup());%0A    
-Assert.
 assertEquals(Mod
@@ -1537,39 +1537,32 @@
 getMode());%0A    
-Assert.
 assertFalse(opti
@@ -1581,31 +1581,24 @@
 ted());%0A    
-Assert.
 assertFalse(
@@ -1617,39 +1617,32 @@
 cursive());%0A    
-Assert.
 assertEquals(Con
@@ -1671,39 +1671,32 @@
 .getTtl());%0A    
-Assert.
 assertEquals(Ttl
@@ -2747,31 +2747,24 @@
 FREE);%0A%0A    
-Assert.
 assertEquals
@@ -2799,39 +2799,32 @@
 wExists());%0A    
-Assert.
 assertEquals(mou
@@ -2853,39 +2853,32 @@
 ntPoint());%0A    
-Assert.
 assertEquals(ope
@@ -2918,39 +2918,32 @@
 nTimeMs());%0A    
-Assert.
 assertEquals(per
@@ -2970,39 +2970,32 @@
 rsisted());%0A    
-Assert.
 assertEquals(own
@@ -3015,39 +3015,32 @@
 etOwner());%0A    
-Assert.
 assertEquals(gro
@@ -3060,39 +3060,32 @@
 etGroup());%0A    
-Assert.
 assertEquals(mod
@@ -3103,39 +3103,32 @@
 getMode());%0A    
-Assert.
 assertEquals(rec
@@ -3155,39 +3155,32 @@
 cursive());%0A    
-Assert.
 assertEquals(ttl
@@ -3204,23 +3204,16 @@
 ));%0A    
-Assert.
 assertEq

add static import for another class