Skip to content

Commit

Permalink
Fix tests by manually adding rows flyway would handle that HSQL doesn…
Browse files Browse the repository at this point in the history
…'t do
  • Loading branch information
mattwilshire committed Oct 25, 2024
1 parent fff8a9f commit fc8cdaf
Showing 1 changed file with 47 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import static org.junit.Assert.assertNotNull;

import com.box.l10n.mojito.entity.ScheduledJob;
import com.box.l10n.mojito.entity.ScheduledJobStatusEntity;
import com.box.l10n.mojito.entity.ScheduledJobTypeEntity;
import com.box.l10n.mojito.quartz.QuartzSchedulerManager;
import com.box.l10n.mojito.retry.DeadLockLoserExceptionRetryTemplate;
import com.box.l10n.mojito.service.assetExtraction.ServiceTestBase;
Expand All @@ -14,6 +16,7 @@
import com.box.l10n.mojito.service.thirdparty.ThirdPartySyncJobConfig;
import com.box.l10n.mojito.service.thirdparty.ThirdPartySyncJobsConfig;
import com.google.common.collect.ImmutableMap;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mockito;
Expand All @@ -22,6 +25,8 @@
import org.springframework.beans.factory.annotation.Autowired;

public class ScheduledJobManagerTest extends ServiceTestBase {

private static boolean initializedDB = false;
private ScheduledJobManager scheduledJobManager;
@Autowired RepositoryService repositoryService;
@Autowired QuartzSchedulerManager schedulerManager;
Expand All @@ -32,31 +37,66 @@ public class ScheduledJobManagerTest extends ServiceTestBase {
@Autowired DeadLockLoserExceptionRetryTemplate deadlockRetryTemplate;

@Before
public void before()
public void initialize()
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");

if (!initializedDB) {
// Flyway not used in HSQL, do the manually insertions flyway would do
for (int i = 1; i <= 4; i++) {
if (repositoryService
.findRepositoriesIsNotDeletedOrderByName("scheduled-job-" + i)
.isEmpty()) {
repositoryService.addRepositoryLocale(
repositoryService.createRepository("scheduled-job-" + i), "fr-FR");
}
}

ScheduledJobTypeEntity scheduledJobTypeEntity = new ScheduledJobTypeEntity();
scheduledJobTypeEntity.setEnum(ScheduledJobType.THIRD_PARTY_SYNC);
scheduledJobTypeRepository.save(scheduledJobTypeEntity);

List.of(
ScheduledJobStatus.SCHEDULED,
ScheduledJobStatus.IN_PROGRESS,
ScheduledJobStatus.FAILED,
ScheduledJobStatus.SUCCEEDED)
.forEach(
status -> {
ScheduledJobStatusEntity scheduledJobStatusEntity = new ScheduledJobStatusEntity();
scheduledJobStatusEntity.setJobStatus(status);
scheduledJobStatusRepository.save(scheduledJobStatusEntity);
});
initializedDB = true;
}

ThirdPartySyncJobConfig scheduledJobOne = new ThirdPartySyncJobConfig();
scheduledJobOne.setUuid("e4c72563-d8f0-4465-9eec-9ed96087665e");
scheduledJobOne.setCron("0/5 * * * * ?");
scheduledJobOne.setRepository("scheduled-job-1");
scheduledJobOne.setThirdPartyProjectId("123456");
scheduledJobOne.setActions(List.of());
scheduledJobOne.setPluralSeparator("_");
scheduledJobOne.setLocaleMapping("");
scheduledJobOne.setSkipTextUnitsWithPattern("");
scheduledJobOne.setSkipAssetsWithPathPattern("");
scheduledJobOne.setIncludeTextUnitsWithPattern("");
scheduledJobOne.setOptions(List.of());

ThirdPartySyncJobConfig scheduledJobTwo = new ThirdPartySyncJobConfig();
scheduledJobTwo.setUuid("e4c72563-d8f0-4465-9eec-aaa96087665e");
scheduledJobTwo.setCron("0/5 * * * * ?");
scheduledJobTwo.setRepository("scheduled-job-2");
scheduledJobTwo.setThirdPartyProjectId("123456");
scheduledJobTwo.setActions(List.of());
scheduledJobTwo.setPluralSeparator("_");
scheduledJobTwo.setLocaleMapping("");
scheduledJobTwo.setSkipTextUnitsWithPattern("");
scheduledJobTwo.setSkipAssetsWithPathPattern("");
scheduledJobTwo.setIncludeTextUnitsWithPattern("");
scheduledJobTwo.setOptions(List.of());

ThirdPartySyncJobsConfig thirdPartySyncJobsConfig = new ThirdPartySyncJobsConfig();
thirdPartySyncJobsConfig.setThirdPartySyncJobs(
Expand Down

0 comments on commit fc8cdaf

Please sign in to comment.