package com.baeldung.jobrunr; import org.jobrunr.jobs.states.StateName; import org.jobrunr.storage.StorageProvider; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.test.context.junit4.SpringRunner; import java.net.URI; import java.util.concurrent.TimeUnit; import static org.awaitility.Awaitility.await; import static org.junit.Assert.assertEquals; import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.DEFINED_PORT; @RunWith(SpringRunner.class) @SpringBootTest(webEnvironment = DEFINED_PORT, classes = JobRunrSpringBootApp.class) public class JobRunrLiveTest { @Autowired TestRestTemplate restTemplate; @Autowired StorageProvider storageProvider; @Test public void givenEndpoint_whenJobEnqueued_thenJobIsProcessedWithin30Seconds() { String response = enqueueJobViaRest("some-input"); assertEquals("job enqueued successfully", response); await().atMost(30, TimeUnit.SECONDS).until(() -> storageProvider.countJobs(StateName.SUCCEEDED) == 1); } private String enqueueJobViaRest(String input) { try { return restTemplate.getForObject(new URI("http://localhost:8080/jobrunr/enqueue/" + input), String.class); } catch (Exception ignored) { ignored.printStackTrace(); } return null; } }