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

import alluxio.CommonTestUtils;
import alluxio.Configuration;
import alluxio.Constants;
import alluxio.PropertyKey;
import alluxio.client.WriteType;
import alluxio.security.authorization.Mode;
import alluxio.thrift.CreateDirectoryTOptions;
import alluxio.wire.TtlAction;

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

import java.util.Random;

/**
 * Tests for the {@link CreateDirectoryOptions} class.
 */
public final class CreateDirectoryOptionsTest {
  private final WriteType mDefaultWriteType =
      Configuration.getEnum(PropertyKey.USER_FILE_WRITE_TYPE_DEFAULT, WriteType.class);

  @Test
  public void defaults() {
    CreateDirectoryOptions options = CreateDirectoryOptions.defaults();
    Assert.assertFalse(options.isAllowExists());
    Assert.assertFalse(options.isRecursive());
    Assert.assertEquals(Constants.NO_TTL, options.getTtl());
    Assert.assertEquals(TtlAction.DELETE, options.getTtlAction());
    Assert.assertEquals(mDefaultWriteType, options.getWriteType());
    Assert.assertEquals(Mode.defaults().applyDirectoryUMask(), options.getMode());
  }

  /**
   * Tests getting and setting fields.
   */
  @Test
  public void fields() {
    Random random = new Random();
    boolean allowExists = random.nextBoolean();
    boolean recursive = random.nextBoolean();
    Mode mode = new Mode((short) random.nextInt());
    long ttl = random.nextLong();
    WriteType writeType = WriteType.NONE;

    CreateDirectoryOptions options = CreateDirectoryOptions.defaults();
    options.setAllowExists(allowExists);
    options.setMode(mode);
    options.setTtl(ttl);
    options.setTtlAction(TtlAction.FREE);
    options.setRecursive(recursive);
    options.setWriteType(writeType);

    Assert.assertEquals(allowExists, options.isAllowExists());
    Assert.assertEquals(mode, options.getMode());
    Assert.assertEquals(recursive, options.isRecursive());
    Assert.assertEquals(ttl, options.getTtl());
    Assert.assertEquals(TtlAction.FREE, options.getTtlAction());
    Assert.assertEquals(writeType, options.getWriteType());
  }

  /**
   * Tests conversion to thrift representation.
   */
  @Test
  public void toThrift() {
    Random random = new Random();
    boolean allowExists = random.nextBoolean();
    boolean recursive = random.nextBoolean();
    Mode mode = new Mode((short) random.nextInt());
    long ttl = random.nextLong();
    WriteType writeType = WriteType.NONE;

    CreateDirectoryOptions options = CreateDirectoryOptions.defaults();
    options.setAllowExists(allowExists);
    options.setMode(mode);
    options.setTtl(ttl);
    options.setTtlAction(TtlAction.FREE);
    options.setRecursive(recursive);
    options.setWriteType(writeType);

    CreateDirectoryTOptions thriftOptions = options.toThrift();
    Assert.assertEquals(allowExists, thriftOptions.isAllowExists());
    Assert.assertEquals(recursive, thriftOptions.isRecursive());
    Assert.assertEquals(writeType.isThrough(), thriftOptions.isPersisted());
    Assert.assertEquals(ttl, thriftOptions.getTtl());
    Assert.assertEquals(alluxio.thrift.TTtlAction.Free, thriftOptions.getTtlAction());
    Assert.assertEquals(mode.toShort(), thriftOptions.getMode());
  }

  @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
@@ -663,24 +663,24 @@
 nTestUtils;%0A
-
 import allux
@@ -911,33 +911,8 @@
 n;%0A%0A
-import org.junit.Assert;%0A
 impo
@@ -1310,31 +1310,24 @@
 ults();%0A    
-Assert.
 assertFalse(
@@ -1352,31 +1352,24 @@
 sts());%0A    
-Assert.
 assertFalse(
@@ -1388,39 +1388,32 @@
 cursive());%0A    
-Assert.
 assertEquals(Con
@@ -1442,39 +1442,32 @@
 .getTtl());%0A    
-Assert.
 assertEquals(Ttl
@@ -1502,39 +1502,32 @@
 lAction());%0A    
-Assert.
 assertEquals(mDe
@@ -1563,39 +1563,32 @@
 iteType());%0A    
-Assert.
 assertEquals(Mod
@@ -2271,31 +2271,24 @@
 Type);%0A%0A    
-Assert.
 assertEquals
@@ -2323,39 +2323,32 @@
 wExists());%0A    
-Assert.
 assertEquals(mod
@@ -2366,39 +2366,32 @@
 getMode());%0A    
-Assert.
 assertEquals(rec
@@ -2418,39 +2418,32 @@
 cursive());%0A    
-Assert.
 assertEquals(ttl
@@ -2459,39 +2459,32 @@
 .getTtl());%0A    
-Assert.
 assertEquals(Ttl
@@ -2517,39 +2517,32 @@
 lAction());%0A    
-Assert.
 assertEquals(wri
@@ -3277,31 +3277,24 @@
 rift();%0A    
-Assert.
 assertEquals
@@ -3335,39 +3335,32 @@
 wExists());%0A    
-Assert.
 assertEquals(rec
@@ -3393,39 +3393,32 @@
 cursive());%0A    
-Assert.
 assertEquals(wri
@@ -3463,39 +3463,32 @@
 rsisted());%0A    
-Assert.
 assertEquals(ttl
@@ -3510,39 +3510,32 @@
 .getTtl());%0A    
-Assert.
 assertEquals(all
@@ -3598,23 +3598,16 @@
 ));%0A    
-Assert.
 assertEq

Use static imports for standard test utilities in CreateDirectoryOptionsTest.java