<commit_before>package net.nemerosa.ontrack.service.job

import net.nemerosa.ontrack.model.job.JobQueueAccessService
import net.nemerosa.ontrack.model.security.SecurityService
import net.nemerosa.ontrack.model.support.ApplicationLogService
import net.nemerosa.ontrack.service.security.SecurityServiceTestUtils
import org.junit.Before
import org.junit.Test
import org.springframework.context.ApplicationContext

import static org.mockito.Mockito.mock

class JobServiceImplTest {

    JobServiceImpl service

    @Before
    void before() {
        ApplicationContext applicationContext = mock(ApplicationContext)

        SecurityService securityService = SecurityServiceTestUtils.securityService()

        ApplicationLogService applicationLogService = mock(ApplicationLogService)
        JobQueueAccessService jobQueueAccessService = mock(JobQueueAccessService)
        service = new JobServiceImpl(
                applicationContext,
                securityService,
                applicationLogService,
                jobQueueAccessService
        )
    }

    @Test
    void 'Running job: disabled'() {
        TestJob job = TestJob.create(1, true)
        RegisteredJob rj = service.registerJob(0, job)
        assert !service.runJob(rj, false)
        assert job.count == 0
    }

    @Test
    void 'Group run: no'() {<commit_msg>#41 Unit tests for jobs<commit_after>package net.nemerosa.ontrack.service.job

import net.nemerosa.ontrack.model.job.JobQueueAccessService
import net.nemerosa.ontrack.model.security.SecurityService
import net.nemerosa.ontrack.model.support.ApplicationLogService
import net.nemerosa.ontrack.service.security.SecurityServiceTestUtils
import org.junit.Before
import org.junit.Test
import org.springframework.context.ApplicationContext

import static org.mockito.Mockito.mock

class JobServiceImplTest {

    JobServiceImpl service

    @Before
    void before() {
        ApplicationContext applicationContext = mock(ApplicationContext)

        SecurityService securityService = SecurityServiceTestUtils.securityService()

        ApplicationLogService applicationLogService = mock(ApplicationLogService)
        JobQueueAccessService jobQueueAccessService = mock(JobQueueAccessService)
        service = new JobServiceImpl(
                applicationContext,
                securityService,
                applicationLogService,
                jobQueueAccessService
        )
    }

    @Test
    void 'Running job: disabled'() {
        TestJob job = TestJob.create(1, true)
        RegisteredJob rj = service.registerJob(0, job)
        assert !service.runJob(rj, false)
        assert job.count == 0
    }

    @Test
    void 'Running job: group running'() {
        TestJob job = TestJob.create(1)
        TestJob jobLong = TestJob.create(2).longRunning()
        RegisteredJob rj = service.registerJob(0, job)
        RegisteredJob rjLong = service.registerJob(0, jobLong)
        assert service.runJob(rjLong, true)
        Thread.sleep 500
        assert !service.runJob(rj, true)
    }

    @Test
    void 'Running job: already running'() {
        TestJob jobLong = TestJob.create(2).longRunning()
        RegisteredJob rjLong = service.registerJob(0, jobLong)
        assert service.runJob(rjLong, true)
        Thread.sleep 500
        assert !service.runJob(rjLong, true)
    }

    @Test
    void 'Group run: no'() {
{'fraction_non_alphanumeric': 0.07708271568336793, 'fraction_numerical': 0.005929439667951379, 'mean_word_length': 3.104622871046229, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2020495', 'n_tokens_mistral': 926, 'n_tokens_neox': 894, 'n_words': 191}