package com.s24.redjob.queue;

import static com.s24.redjob.queue.JobTypeScannerTest.scanForJsonSubtypes;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.junit.Before;
import org.junit.Test;

import com.s24.redjob.TestRedis;
import com.s24.redjob.worker.Execution;
import com.s24.redjob.worker.ExecutionRedisSerializer;

/**
 * Integration test for {@link QueueDaoImpl}.
 */
public class QueueDaoImplIT {
   /**
    * DAO under test.
    */
   private QueueDaoImpl dao = new QueueDaoImpl();

   @Before
   public void setUp() throws Exception {
      ExecutionRedisSerializer executions = new ExecutionRedisSerializer();
      scanForJsonSubtypes(executions, TestJob.class);

      dao.setConnectionFactory(TestRedis.connectionFactory());
      dao.setNamespace("namespace");
      dao.setExecutions(executions);
      dao.afterPropertiesSet();
   }

   @Test
   public void enqueue() {
      String queue = "test";

      long id = dao.enqueue(queue, new TestJob("value"), false).getId();
      assertTrue(id > 0);

      Execution execution = dao.pop(queue, "worker");
      assertNotNull(execution);
      assertEquals(id, execution.getId());
      TestJob job = (TestJob) execution.getJob();
      assertNotNull(job);
      assertEquals("value", job.getValue());
   }
}

@@ -973,16 +973,23 @@
  enqueue
+_normal
 () %7B%0A   
@@ -1015,16 +1015,52 @@
 test%22;%0A%0A
+      TestJob job1 = new TestJob();%0A
       lo
@@ -1064,16 +1064,17 @@
  long id
+1
  = dao.e
@@ -1091,28 +1091,133 @@
 ue, 
-new TestJob(%22value%22)
+job1, false).getId();%0A      assertTrue(id1 %3E 0);%0A      TestJob job2 = new TestJob();%0A      long id2 = dao.enqueue(queue, job2
 , fa
@@ -1249,16 +1249,17 @@
 tTrue(id
+2
  %3E 0);%0A%0A
@@ -1283,16 +1283,17 @@
 xecution
+1
  = dao.p
@@ -1342,16 +1342,17 @@
 xecution
+1
 );%0A     
@@ -1367,16 +1367,17 @@
 quals(id
+1
 , execut
@@ -1375,24 +1375,25 @@
 1, execution
+1
 .getId());%0A 
@@ -1401,49 +1401,969 @@
     
-TestJob job = (TestJob) execution.getJob(
+assertEquals(job1, execution1.getJob());%0A%0A      Execution execution2 = dao.pop(queue, %22worker%22);%0A      assertNotNull(execution2);%0A      assertEquals(id2, execution2.getId());%0A      assertEquals(job2, execution2.getJob());%0A   %7D%0A%0A   @Test%0A   public void enqueue_priority() %7B%0A      String queue = %22test%22;%0A%0A      TestJob jobNormal = new TestJob();%0A      long idNormal = dao.enqueue(queue, jobNormal, false).getId();%0A      assertTrue(idNormal %3E 0);%0A      TestJob jobPriority = new TestJob();%0A      long idPriority = dao.enqueue(queue, jobPriority, true).getId();%0A      assertTrue(idPriority %3E 0);%0A%0A      // Check that due to the priority flag set to true, the priority job gets executed first, even if scheduled later.%0A      Execution execution1 = dao.pop(queue, %22worker%22);%0A      assertNotNull(execution1);%0A      assertEquals(idPriority, execution1.getId());%0A      assertEquals(jobPriority, execution1.getJob());%0A%0A      Execution execution2 = dao.pop(queue, %22worker%22
 );%0A 
@@ -2381,19 +2381,26 @@
 NotNull(
-job
+execution2
 );%0A     
@@ -2417,29 +2417,86 @@
 als(
-%22value%22, job.getValue
+idNormal, execution2.getId());%0A      assertEquals(jobNormal, execution2.getJob
 ());

Add test for priority enqueue