forked from box/mojito
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tests by not using new application context
- Loading branch information
1 parent
94208dd
commit fff8a9f
Showing
6 changed files
with
187 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
webapp/src/test/java/com/box/l10n/mojito/service/scheduledjob/NoOpScheduledJobTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.box.l10n.mojito.service.scheduledjob; | ||
|
||
import org.quartz.JobExecutionContext; | ||
import org.quartz.JobExecutionException; | ||
|
||
public class NoOpScheduledJobTest implements IScheduledJob { | ||
@Override | ||
public void onSuccess(JobExecutionContext context) {} | ||
|
||
@Override | ||
public void onFailure(JobExecutionContext context, JobExecutionException jobException) {} | ||
|
||
@Override | ||
public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {} | ||
} |
209 changes: 121 additions & 88 deletions
209
webapp/src/test/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,88 +1,121 @@ | ||
// package com.box.l10n.mojito.service.scheduledjob; | ||
// | ||
// import static org.junit.Assert.assertEquals; | ||
// import static org.mockito.ArgumentMatchers.any; | ||
// import static org.mockito.Mockito.doNothing; | ||
// | ||
// import com.box.l10n.mojito.service.assetExtraction.ServiceTestBase; | ||
// import org.junit.Before; | ||
// import org.junit.Test; | ||
// import org.mockito.Mock; | ||
// import org.mockito.MockitoAnnotations; | ||
// import org.quartz.JobExecutionContext; | ||
// import org.quartz.JobExecutionException; | ||
// import org.quartz.impl.matchers.GroupMatcher; | ||
// import org.springframework.beans.factory.annotation.Autowired; | ||
// import org.springframework.test.context.ContextConfiguration; | ||
// import org.springframework.test.context.TestPropertySource; | ||
// | ||
// @TestPropertySource( | ||
// properties = { | ||
// "l10n.scheduledJobs.enabled=true", | ||
// "l10n.thirdPartySyncJobs.test1.uuid=e4c72563-d8f0-4465-9eec-9ed96087665e", | ||
// "l10n.thirdPartySyncJobs.test1.cron=0/2 * * * * ?", | ||
// "l10n.thirdPartySyncJobs.test1.repository=scheduled-job-1", | ||
// "l10n.thirdPartySyncJobs.test1.thirdPartyProjectId=123456", | ||
// "l10n.thirdPartySyncJobs.test1.actions=PUSH,PULL,MAP_TEXTUNIT,PUSH_SCREENSHOT", | ||
// "", | ||
// "l10n.thirdPartySyncJobs.test2.uuid=e4c72563-d8f0-4465-9eec-aaa96087665e", | ||
// "l10n.thirdPartySyncJobs.test2.cron=0 0/5 * * * ?", | ||
// "l10n.thirdPartySyncJobs.test2.repository=scheduled-job-2", | ||
// "l10n.thirdPartySyncJobs.test2.thirdPartyProjectId=123456", | ||
// "l10n.thirdPartySyncJobs.test2.actions=PUSH,PULL,MAP_TEXTUNIT,PUSH_SCREENSHOT", | ||
// "", | ||
// "l10n.thirdPartySyncJobs.test3.cron=0 0/5 * * * ?", | ||
// "l10n.thirdPartySyncJobs.test3.repository=scheduled-job-3", | ||
// "l10n.thirdPartySyncJobs.test3.thirdPartyProjectId=123456", | ||
// "l10n.thirdPartySyncJobs.test3.actions=PUSH,PULL,MAP_TEXTUNIT,PUSH_SCREENSHOT", | ||
// "", | ||
// "l10n.thirdPartySyncJobs.test4.uuid=e4c72563-d8f0-4465-9eec-aaa96087665e", | ||
// "l10n.thirdPartySyncJobs.test4.repository=scheduled-job-4", | ||
// "l10n.thirdPartySyncJobs.test4.thirdPartyProjectId=123456", | ||
// "l10n.thirdPartySyncJobs.test4.actions=PUSH,PULL,MAP_TEXTUNIT,PUSH_SCREENSHOT" | ||
// }) | ||
// @ContextConfiguration(classes = {ScheduledJobTestConfiguration.class}) | ||
// public class ScheduledJobManagerTest extends ServiceTestBase { | ||
// @Mock IScheduledJob scheduledThirdPartySync; | ||
// @Autowired ScheduledJobManager scheduledJobManager; | ||
// | ||
// @Before | ||
// public void setUp() throws JobExecutionException { | ||
// MockitoAnnotations.openMocks(this); | ||
// doNothing().when(scheduledThirdPartySync).execute(any(JobExecutionContext.class)); | ||
// } | ||
// | ||
// @Test | ||
// public void testListenersExists() throws Exception { | ||
// assertEquals( | ||
// 1, scheduledJobManager.getScheduler().getListenerManager().getJobListeners().size()); | ||
// | ||
// assertEquals( | ||
// 1, scheduledJobManager.getScheduler().getListenerManager().getTriggerListeners().size()); | ||
// } | ||
// | ||
// @Test | ||
// public void testQuartzScheduledJob() throws Exception { | ||
// assertEquals( | ||
// 2, | ||
// scheduledJobManager | ||
// .getScheduler() | ||
// .getJobKeys(GroupMatcher.groupEquals(ScheduledJobType.THIRD_PARTY_SYNC.toString())) | ||
// .size()); | ||
// | ||
// Thread.sleep(10000); | ||
// } | ||
// | ||
// // @Test | ||
// // public void testQuartzCleanup() throws Exception { | ||
// // scheduledJobManager.uuidPool = List.of("e4c72563-d8f0-4465-9eec-9ed96087665e"); | ||
// // scheduledJobManager.cleanQuartzJobs(); | ||
// // assertEquals( | ||
// // 1, | ||
// // scheduledJobManager | ||
// // .getScheduler() | ||
// // | ||
// .getJobKeys(GroupMatcher.groupEquals(ScheduledJobType.THIRD_PARTY_SYNC.toString())) | ||
// // .size()); | ||
// // } | ||
// } | ||
package com.box.l10n.mojito.service.scheduledjob; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
|
||
import com.box.l10n.mojito.entity.ScheduledJob; | ||
import com.box.l10n.mojito.quartz.QuartzSchedulerManager; | ||
import com.box.l10n.mojito.retry.DeadLockLoserExceptionRetryTemplate; | ||
import com.box.l10n.mojito.service.assetExtraction.ServiceTestBase; | ||
import com.box.l10n.mojito.service.repository.RepositoryLocaleCreationException; | ||
import com.box.l10n.mojito.service.repository.RepositoryNameAlreadyUsedException; | ||
import com.box.l10n.mojito.service.repository.RepositoryRepository; | ||
import com.box.l10n.mojito.service.repository.RepositoryService; | ||
import com.box.l10n.mojito.service.thirdparty.ThirdPartySyncJobConfig; | ||
import com.box.l10n.mojito.service.thirdparty.ThirdPartySyncJobsConfig; | ||
import com.google.common.collect.ImmutableMap; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
import org.quartz.SchedulerException; | ||
import org.quartz.impl.matchers.GroupMatcher; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class ScheduledJobManagerTest extends ServiceTestBase { | ||
private ScheduledJobManager scheduledJobManager; | ||
@Autowired RepositoryService repositoryService; | ||
@Autowired QuartzSchedulerManager schedulerManager; | ||
@Autowired ScheduledJobRepository scheduledJobRepository; | ||
@Autowired ScheduledJobStatusRepository scheduledJobStatusRepository; | ||
@Autowired ScheduledJobTypeRepository scheduledJobTypeRepository; | ||
@Autowired RepositoryRepository repositoryRepository; | ||
@Autowired DeadLockLoserExceptionRetryTemplate deadlockRetryTemplate; | ||
|
||
@Before | ||
public void before() | ||
throws RepositoryNameAlreadyUsedException, | ||
RepositoryLocaleCreationException, | ||
ClassNotFoundException, | ||
SchedulerException { | ||
for (int i = 1; i <= 4; i++) { | ||
if (repositoryService | ||
.findRepositoriesIsNotDeletedOrderByName("scheduled-job-" + i) | ||
.isEmpty()) { | ||
repositoryService.addRepositoryLocale( | ||
repositoryService.createRepository("scheduled-job-" + i), "fr-FR"); | ||
} | ||
} | ||
|
||
ThirdPartySyncJobConfig scheduledJobOne = new ThirdPartySyncJobConfig(); | ||
scheduledJobOne.setUuid("e4c72563-d8f0-4465-9eec-9ed96087665e"); | ||
scheduledJobOne.setCron("0/5 * * * * ?"); | ||
scheduledJobOne.setRepository("scheduled-job-1"); | ||
scheduledJobOne.setThirdPartyProjectId("123456"); | ||
|
||
ThirdPartySyncJobConfig scheduledJobTwo = new ThirdPartySyncJobConfig(); | ||
scheduledJobTwo.setUuid("e4c72563-d8f0-4465-9eec-aaa96087665e"); | ||
scheduledJobTwo.setCron("0/5 * * * * ?"); | ||
scheduledJobTwo.setRepository("scheduled-job-2"); | ||
scheduledJobTwo.setThirdPartyProjectId("123456"); | ||
|
||
ThirdPartySyncJobsConfig thirdPartySyncJobsConfig = new ThirdPartySyncJobsConfig(); | ||
thirdPartySyncJobsConfig.setThirdPartySyncJobs( | ||
ImmutableMap.of("scheduled-job-1", scheduledJobOne, "scheduled-job-2", scheduledJobTwo)); | ||
|
||
// Return a Spy with the Job always being a no-op job | ||
scheduledJobManager = | ||
Mockito.spy( | ||
new ScheduledJobManager( | ||
thirdPartySyncJobsConfig, | ||
schedulerManager, | ||
scheduledJobRepository, | ||
scheduledJobStatusRepository, | ||
scheduledJobTypeRepository, | ||
repositoryRepository, | ||
deadlockRetryTemplate)); | ||
|
||
Mockito.doReturn(NoOpScheduledJobTest.class) | ||
.when(scheduledJobManager) | ||
.loadJobClass(ScheduledJobType.THIRD_PARTY_SYNC.getJobClassName()); | ||
|
||
scheduledJobManager.init(); | ||
} | ||
|
||
@Test | ||
public void testListenersExists() throws Exception { | ||
assertEquals( | ||
1, scheduledJobManager.getScheduler().getListenerManager().getJobListeners().size()); | ||
|
||
assertEquals( | ||
1, scheduledJobManager.getScheduler().getListenerManager().getTriggerListeners().size()); | ||
} | ||
|
||
@Test | ||
public void testQuartzScheduledJob() throws Exception { | ||
assertEquals( | ||
2, | ||
scheduledJobManager | ||
.getScheduler() | ||
.getJobKeys(GroupMatcher.groupEquals(ScheduledJobType.THIRD_PARTY_SYNC.toString())) | ||
.size()); | ||
|
||
Thread.sleep(10000); | ||
|
||
ScheduledJob sj = scheduledJobRepository.findById("e4c72563-d8f0-4465-9eec-9ed96087665e").get(); | ||
assertEquals(sj.getJobStatus().getEnum(), ScheduledJobStatus.SUCCEEDED); | ||
assertNotNull(sj.getEndDate()); | ||
} | ||
|
||
// @Test | ||
// public void testQuartzCleanup() throws Exception { | ||
// scheduledJobManager.uuidPool = List.of("e4c72563-d8f0-4465-9eec-9ed96087665e"); | ||
// scheduledJobManager.cleanQuartzJobs(); | ||
// assertEquals( | ||
// 1, | ||
// scheduledJobManager | ||
// .getScheduler() | ||
// | ||
// .getJobKeys(GroupMatcher.groupEquals(ScheduledJobType.THIRD_PARTY_SYNC.toString())) | ||
// .size()); | ||
// } | ||
} |
29 changes: 0 additions & 29 deletions
29
...src/test/java/com/box/l10n/mojito/service/scheduledjob/ScheduledJobTestConfiguration.java
This file was deleted.
Oops, something went wrong.