package com.mdsol.mauth;

import static org.junit.Assert.fail;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.io.IOException;
import java.lang.SecurityException;
import java.util.UUID;


/**
 * Tests for {@link com.mdsol.mauth.MAuthRequestSigner}
 *
 * @author Jonathan Price <jprice@mdsol.com>
 */
public class MAuthRequestSignerTest {

  @Rule
  public ExpectedException thrown = ExpectedException.none();

  @Test
  public final void constructorWithInvalidKeyStringThrowsException() throws IOException {
    UUID appUUID = UUID.randomUUID();
    String privateKeyString = "This is not a valid key";
    thrown.expect(SecurityException.class);
    thrown.expectMessage("Unable to process private key string");
    new MAuthRequestSigner(appUUID, privateKeyString);
    fail(); // Shouldn't get here - exception will have been thrown
  }

}

@@ -54,14 +54,152 @@
 ert.
-fail;%0A
+assertEquals;%0Aimport static org.junit.Assert.fail;%0A%0Aimport org.apache.commons.io.IOUtils;%0Aimport org.junit.Before;%0Aimport org.junit.BeforeClass;
 %0Aimp
@@ -300,58 +300,16 @@
 ava.
-io.IOException;%0Aimport java.lang.SecurityException
+util.Map
 ;%0Aim
@@ -488,75 +488,753 @@
 %0A%0A  
-@Rule%0A  public ExpectedException thrown = ExpectedException.none();
+private static final long TEST_EPOCH_TIME = 1424697700L;%0A  private static String privateKeyString;%0A  private final UUID testUUID = UUID.fromString(%222a6790ab-f6c6-45be-86fc-9e9be76ec12a%22);%0A%0A  private MAuthRequestSigner mAuthRequestSigner;%0A%0A  @Rule%0A  public ExpectedException thrown = ExpectedException.none();%0A%0A  @BeforeClass%0A  public static void setUpClass() throws Exception %7B%0A    privateKeyString = IOUtils.toString(MAuthRequestSigner.class.getResourceAsStream(%22privatekey.pem%22), %22UTF-8%22);%0A  %7D%0A%0A  @Before%0A  public void setUp() throws Exception %7B%0A    mAuthRequestSigner = new MAuthRequestSigner(testUUID,privateKeyString);%0A    EpochTime testEpochTime = new TestEpochTime(TEST_EPOCH_TIME);%0A    MAuthRequestSigner.setEpochTime(testEpochTime);%0A  %7D
 %0A%0A  
@@ -1315,18 +1315,16 @@
  throws 
-IO
 Exceptio
@@ -1331,46 +1331,8 @@
 n %7B%0A
-    UUID appUUID = UUID.randomUUID();%0A
     
@@ -1525,11 +1525,12 @@
 ner(
-app
+test
 UUID
@@ -1623,10 +1623,277 @@
 wn%0A  %7D%0A%0A
+  @Test%0A  public final void generateHeadersIncludesTimeHeaderWithCorrectTime() throws Exception %7B%0A    Map%3CString, String%3E headers = mAuthRequestSigner.generateHeaders(%22GET%22, %22/%22, %22%22);%0A    assertEquals(String.valueOf(TEST_EPOCH_TIME), headers.get(%22x-mws-time%22));%0A  %7D%0A%0A
 %7D%0A

Add time test and use fixed UUID and key