package com.filestack;

import static com.filestack.util.MockConstants.APP_SECRET;
import static com.filestack.util.MockConstants.POLICY;
import static org.junit.Assert.assertTrue;

import com.filestack.Security;
import org.junit.Test;

/**
 * Tests {@link Security Security} class to check encoding and signing.
 */
public class TestSecurity {
  private static final String CORRECT_POLICY = "eyJleHBpcnkiOjQ2NTM2NTE2MDB9";
  private static final String CORRECT_SIGNATURE =
      "d0dcacc68d00b7d2cd18c7f82aaf5bf172fdb423dc3cf0540d0da04912867e13";

  @Test
  public void testEncoding() {
    Security security = Security.createNew(POLICY, APP_SECRET);

    assertTrue("Incorrect policy ", CORRECT_POLICY.equals(security.getPolicy()));
  }

  @Test
  public void testSigning() {
    Security security = Security.createNew(POLICY, APP_SECRET);

    assertTrue("Incorrect signature", CORRECT_SIGNATURE.equals(security.getSignature()));
  }
}

@@ -28,188 +28,24 @@
 ort 
-static com.filestack.util.MockConstants.APP_SECRET;%0Aimport static com.filestack.util.MockConstants.POLICY;%0Aimport static org.junit.Assert.assertTrue;%0A%0Aimport com.filestack.Security
+org.junit.Assert
 ;%0Aim
@@ -178,143 +178,305 @@
 y %7B%0A
-  priva
+%0A  @Test%0A  public void 
 te
- 
 st
-atic final String CORRECT_POLICY = %22eyJleHBpcnkiOjQ2NTM2NTE2MDB9%22;%0A  private static final String CORRECT_SIGNATURE =%0A      
+CreateNew() %7B%0A    Policy policy = new Policy.Builder().expiry(4653651600L).build();%0A    Security security = Security.createNew(policy, %22N3XOC2GP2NFTDCM43DZ6F2L6N4%22);%0A%0A    Assert.assertEquals(%22eyJleHBpcnkiOjQ2NTM2NTE2MDB9%22, security.getPolicy());%0A    Assert.assertEquals(
 %22d0d
@@ -537,17 +537,55 @@
 2867e13%22
-;
+,%0A        security.getSignature());%0A  %7D
 %0A%0A  @Tes
@@ -608,13 +608,17 @@
 test
-Encod
+FromExist
 ing(
@@ -658,98 +658,86 @@
 ity.
-createNew(POLICY, APP_SECRET);%0A%0A    assertTrue(%22Incorrect 
+fromExisting(%22%3Cpolicy%3E%22, %22%3Csignature%3E%22);%0A%0A    Assert.assertEquals(%22%3C
 policy
- 
+%3E
 %22, 
-CORRECT_POLICY.equals(
 secu
@@ -757,145 +757,36 @@
 y())
-)
 ;%0A  
-%7D%0A%0A  @Test%0A  public void testSigning() %7B%0A    Security security = Security.createNew(POLICY, APP_SECRET);%0A%0A    assertTrue(%22Incorrect 
+  Assert.assertEquals(%22%3C
 sign
@@ -794,36 +794,12 @@
 ture
+%3E
 %22, 
-CORRECT_SIGNATURE.equals(
 secu
@@ -818,17 +818,16 @@
 ature())
-)
 ;%0A  %7D%0A%7D%0A

Update Security test