From 1343e0f541a9efc2ae9f6f6c5b03674ec42a8ae0 Mon Sep 17 00:00:00 2001
From: nitin-ebi <79518737+nitin-ebi@users.noreply.github.com>
Date: Wed, 9 Oct 2024 14:16:16 +0100
Subject: [PATCH] EVA-3664 Update test to throw exception in transaction when
saving new block (#462)
* update test to throw error in transaction when saving new block
---
...teSubsnpAccessionsStepConfigurationTest.java | 17 +++++++++++++++--
pom.xml | 2 +-
2 files changed, 16 insertions(+), 3 deletions(-)
diff --git a/eva-accession-pipeline/src/test/java/uk/ac/ebi/eva/accession/pipeline/configuration/batch/steps/CreateSubsnpAccessionsStepConfigurationTest.java b/eva-accession-pipeline/src/test/java/uk/ac/ebi/eva/accession/pipeline/configuration/batch/steps/CreateSubsnpAccessionsStepConfigurationTest.java
index f02bdc1c1..910133161 100644
--- a/eva-accession-pipeline/src/test/java/uk/ac/ebi/eva/accession/pipeline/configuration/batch/steps/CreateSubsnpAccessionsStepConfigurationTest.java
+++ b/eva-accession-pipeline/src/test/java/uk/ac/ebi/eva/accession/pipeline/configuration/batch/steps/CreateSubsnpAccessionsStepConfigurationTest.java
@@ -26,15 +26,16 @@
import org.springframework.batch.test.JobLauncherTestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
-
+import uk.ac.ebi.ampt2d.commons.accession.persistence.jpa.monotonic.service.ContiguousIdBlockService;
import uk.ac.ebi.eva.accession.core.configuration.nonhuman.SubmittedVariantAccessioningConfiguration;
-import uk.ac.ebi.eva.accession.core.repository.nonhuman.eva.SubmittedVariantAccessioningRepository;
import uk.ac.ebi.eva.accession.core.model.eva.SubmittedVariantEntity;
+import uk.ac.ebi.eva.accession.core.repository.nonhuman.eva.SubmittedVariantAccessioningRepository;
import uk.ac.ebi.eva.accession.pipeline.batch.io.AccessionReportWriter;
import uk.ac.ebi.eva.accession.pipeline.batch.io.AccessionWriter;
import uk.ac.ebi.eva.accession.pipeline.parameters.InputParameters;
@@ -47,6 +48,7 @@
import java.nio.file.Paths;
import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
import static uk.ac.ebi.eva.accession.pipeline.configuration.BeanNames.CREATE_SUBSNP_ACCESSION_STEP;
@RunWith(SpringRunner.class)
@@ -76,8 +78,19 @@ public class CreateSubsnpAccessionsStepConfigurationTest {
@Autowired
private MongoTemplate mongoTemplate;
+ @SpyBean
+ private ContiguousIdBlockService contiguousIdBlockService;
+
@Before
public void setUp() throws Exception {
+ // if a new transaction is not created it will fail
+ when(contiguousIdBlockService.getBlockParameters("test-pipeline-ss"))
+ .thenThrow(RuntimeException.class)
+ .thenThrow(RuntimeException.class)
+ .thenThrow(RuntimeException.class)
+ .thenThrow(RuntimeException.class)
+ .thenCallRealMethod();
+
Files.deleteIfExists(Paths.get(inputParameters.getOutputVcf()));
Files.deleteIfExists(Paths.get(inputParameters.getOutputVcf() + AccessionReportWriter.VARIANTS_FILE_SUFFIX));
Files.deleteIfExists(Paths.get(inputParameters.getOutputVcf() + AccessionReportWriter.CONTIGS_FILE_SUFFIX));
diff --git a/pom.xml b/pom.xml
index 8313f26c6..7d10c2d7c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
UTF-8
4.13
0.8.5
- 0.7.16
+ 0.7.17