package com.collective.celos.servlet;

import com.collective.celos.*;
import com.collective.celos.api.ScheduledTime;
import org.junit.Assert;
import org.junit.Test;


public class RerunServletTest {

    @Test(expected = IllegalArgumentException.class)
    public void failsOnUndefinedSlot() throws Exception {
        StateDatabase db = new MemoryStateDatabase();
        new RerunServlet().updateSlotToRerun(new SlotID(new WorkflowID("foo"), new ScheduledTime("2014-02-08T20:00Z")), db);
    }
    
    @Test
    public void updatesSlotAsExpected() throws Exception {
        StateDatabase db = new MemoryStateDatabase();
        SlotID id = new SlotID(new WorkflowID("foo"), new ScheduledTime("2014-02-08T20:00Z"));
        SlotState state = new SlotState(id, SlotState.Status.SUCCESS);
        db.putSlotState(state);
        new RerunServlet().updateSlotToRerun(id, db);
        SlotState dbState = db.getSlotState(id);
        Assert.assertEquals(state.transitionToRerun(), dbState);
    }
    
}

@@ -63,16 +63,62 @@
 elos.*;%0A
+import com.collective.celos.SlotState.Status;%0A
 import c
@@ -205,17 +205,16 @@
 .Test;%0A%0A
-%0A
 public c
@@ -552,47 +552,1211 @@
 Test
-%0A    public void updatesSlotAsExpected(
+(expected = IllegalStateException.class)%0A    public void failsOnRunningSlot() throws Exception %7B%0A        failsOnWrongStatusTest(SlotState.Status.RUNNING);%0A    %7D%0A%0A    @Test(expected = IllegalStateException.class)%0A    public void failsOnReadySlot() throws Exception %7B%0A        failsOnWrongStatusTest(SlotState.Status.READY);%0A    %7D%0A%0A    @Test(expected = IllegalStateException.class)%0A    public void failsOnWaitingSlot() throws Exception %7B%0A        failsOnWrongStatusTest(SlotState.Status.WAITING);%0A    %7D%0A%0A    private void failsOnWrongStatusTest(Status status) throws Exception %7B%0A        StateDatabase db = new MemoryStateDatabase();%0A        SlotID id = new SlotID(new WorkflowID(%22foo%22), new ScheduledTime(%222014-02-08T20:00Z%22));%0A        SlotState state = new SlotState(id, status);%0A        db.putSlotState(state);%0A        new RerunServlet().updateSlotToRerun(id, db);%0A    %7D%0A    %0A    @Test%0A    public void succeedsOnSuccessSlot() throws Exception %7B%0A        succeedsOnRightStatusTest(SlotState.Status.SUCCESS);%0A    %7D%0A%0A    @Test%0A    public void succeedsOnFailureSlot() throws Exception %7B%0A        succeedsOnRightStatusTest(SlotState.Status.FAILURE);%0A    %7D%0A%0A    private void succeedsOnRightStatusTest(Status status
 ) th
@@ -1969,32 +1969,14 @@
 id, 
-SlotState.Status.SUCCESS
+status
 );%0A 

Add a bunch of tests to RerunServletTest.