From 7c7f70d7f94644d8ca86d48d434b1e16a980fec9 Mon Sep 17 00:00:00 2001 From: David McManamon Date: Mon, 23 May 2022 08:01:59 -0400 Subject: [PATCH 1/5] remove CMOSampleID tests --- .../GetCorrectedSampleCmoIdTest.java | 33 -- .../IgoNewRequestMetaDbPublisherTest.java | 16 + ...atientSamplesWithCmoInfoRetrieverTest.java | 50 --- .../limsrest/service/PromoteBankedTest.java | 1 - .../service/cmoinfo/CmoSampleIdTest.java | 37 --- ...IncrementalSampleCounterRetrieverTest.java | 186 ----------- .../PatientAwareCmoSampleIdFormatterTest.java | 40 --- .../PatientAwareCmoSampleIdResolverTest.java | 309 ------------------ ...TypeCorrectedCmoSampleIdGeneratorTest.java | 33 -- ...peCorrectedCmoSampleViewGeneratorTest.java | 200 ------------ .../CellLineCmoSampleIdFormatterTest.java | 25 -- .../cellline/CellLineCmoSampleIdTest.java | 37 --- ...leToCorrectedCmoSampleIdConverterTest.java | 54 --- ...areCorrectedCmoIdConverterFactoryTest.java | 64 ---- ...CspaceSampleAbbreviationRetrieverTest.java | 157 --------- ...tientAwareCorrectedCmoIdConverterTest.java | 84 ----- .../OldCorrectedCmoIdConverterTest.java | 65 ---- .../CellLineCmoSampleIdResolverTest.java | 49 --- .../FormattedCmoSampleIdRetrieverTest.java | 49 --- .../util/StatusTrackerConfigTest.java | 2 +- .../org/mskcc/limsrest/util/UtilsTest.java | 3 +- 21 files changed, 19 insertions(+), 1475 deletions(-) delete mode 100644 src/test/java/org/mskcc/limsrest/controller/GetCorrectedSampleCmoIdTest.java create mode 100644 src/test/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisherTest.java delete mode 100644 src/test/java/org/mskcc/limsrest/service/PatientSamplesWithCmoInfoRetrieverTest.java delete mode 100644 src/test/java/org/mskcc/limsrest/service/cmoinfo/CmoSampleIdTest.java delete mode 100644 src/test/java/org/mskcc/limsrest/service/cmoinfo/IncrementalSampleCounterRetrieverTest.java delete mode 100644 src/test/java/org/mskcc/limsrest/service/cmoinfo/PatientAwareCmoSampleIdFormatterTest.java delete mode 100644 src/test/java/org/mskcc/limsrest/service/cmoinfo/PatientAwareCmoSampleIdResolverTest.java delete mode 100644 src/test/java/org/mskcc/limsrest/service/cmoinfo/SampleTypeCorrectedCmoSampleIdGeneratorTest.java delete mode 100644 src/test/java/org/mskcc/limsrest/service/cmoinfo/SampleTypeCorrectedCmoSampleViewGeneratorTest.java delete mode 100644 src/test/java/org/mskcc/limsrest/service/cmoinfo/cellline/CellLineCmoSampleIdFormatterTest.java delete mode 100644 src/test/java/org/mskcc/limsrest/service/cmoinfo/cellline/CellLineCmoSampleIdTest.java delete mode 100644 src/test/java/org/mskcc/limsrest/service/cmoinfo/converter/BankedSampleToCorrectedCmoSampleIdConverterTest.java delete mode 100644 src/test/java/org/mskcc/limsrest/service/cmoinfo/converter/FormatAwareCorrectedCmoIdConverterFactoryTest.java delete mode 100644 src/test/java/org/mskcc/limsrest/service/cmoinfo/cspace/CspaceSampleAbbreviationRetrieverTest.java delete mode 100644 src/test/java/org/mskcc/limsrest/service/cmoinfo/cspace/PatientAwareCorrectedCmoIdConverterTest.java delete mode 100644 src/test/java/org/mskcc/limsrest/service/cmoinfo/oldformat/OldCorrectedCmoIdConverterTest.java delete mode 100644 src/test/java/org/mskcc/limsrest/service/cmoinfo/retriever/CellLineCmoSampleIdResolverTest.java delete mode 100644 src/test/java/org/mskcc/limsrest/service/cmoinfo/retriever/FormattedCmoSampleIdRetrieverTest.java diff --git a/src/test/java/org/mskcc/limsrest/controller/GetCorrectedSampleCmoIdTest.java b/src/test/java/org/mskcc/limsrest/controller/GetCorrectedSampleCmoIdTest.java deleted file mode 100644 index 72bf4340..00000000 --- a/src/test/java/org/mskcc/limsrest/controller/GetCorrectedSampleCmoIdTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.mskcc.limsrest.controller; - -import org.junit.Before; -import org.junit.Test; -import org.mskcc.limsrest.ConnectionPoolLIMS; -import org.mskcc.limsrest.service.GenerateSampleCmoIdTask; -import org.mskcc.limsrest.util.Constants; -import org.springframework.http.ResponseEntity; - -import java.util.List; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.core.Is.is; -import static org.mockito.Mockito.mock; - -public class GetCorrectedSampleCmoIdTest { - private GetCorrectedSampleCmoId getCorrectedSampleCmoId; - - @Before - public void setUp() throws Exception { - getCorrectedSampleCmoId = new GetCorrectedSampleCmoId(mock(ConnectionPoolLIMS.class)); - } - - @Test - public void whenSampleIgoIdIsInIncorrectFormat_shouldThrowAnException() throws Exception { - ResponseEntity responseEntity = getCorrectedSampleCmoId.getSampleCmoIdByIgoId("I will crash your " + - "system. BUAHAHAHAHA"); - - List strings = responseEntity.getHeaders().get(Constants.ERRORS); - assertThat(strings.size(), is(1)); - assertThat(strings.get(0).contains("IncorrectSampleIgoIdFormatException"), is(true)); - } -} \ No newline at end of file diff --git a/src/test/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisherTest.java b/src/test/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisherTest.java new file mode 100644 index 00000000..96a54bc8 --- /dev/null +++ b/src/test/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisherTest.java @@ -0,0 +1,16 @@ +package org.mskcc.limsrest.controller; + +import org.junit.jupiter.api.Test; + +import java.util.Date; + +import static org.junit.jupiter.api.Assertions.*; + +class IgoNewRequestMetaDbPublisherTest { + + @Test + static void formatDeliverPipelineJSON() { + Date now = new Date(); + IgoNewRequestMetaDbPublisher.formatDeliverPipelineJSON("12345","Curie","WGS", now); + } +} \ No newline at end of file diff --git a/src/test/java/org/mskcc/limsrest/service/PatientSamplesWithCmoInfoRetrieverTest.java b/src/test/java/org/mskcc/limsrest/service/PatientSamplesWithCmoInfoRetrieverTest.java deleted file mode 100644 index 8aff1d90..00000000 --- a/src/test/java/org/mskcc/limsrest/service/PatientSamplesWithCmoInfoRetrieverTest.java +++ /dev/null @@ -1,50 +0,0 @@ -package org.mskcc.limsrest.service; - -import com.velox.api.datarecord.DataRecordManager; -import com.velox.api.user.User; -import org.hamcrest.object.IsCompatibleType; -import org.junit.Assert; -import org.junit.Test; -import org.mskcc.limsrest.service.cmoinfo.converter.CorrectedCmoIdConverter; -import org.mskcc.limsrest.service.converter.SampleRecordToSampleConverter; -import org.mskcc.util.CommonUtils; -import org.mskcc.util.TestUtils; - -import java.util.Optional; - -import static org.hamcrest.CoreMatchers.is; -import static org.mockito.Mockito.mock; - -public class PatientSamplesWithCmoInfoRetrieverTest { - private PatientSamplesWithCmoInfoRetriever patientSamplesWithCmoInfoRetriever = new - PatientSamplesWithCmoInfoRetriever(mock(CorrectedCmoIdConverter.class), mock - (SampleRecordToSampleConverter.class)); - - private DataRecordManager dataRecordManager = mock(DataRecordManager.class); - private User user = mock(User.class); - - @Test - public void whenPatientIdIsNull_shouldThrowAnException() throws Exception { - assertExceptionThrownForPatientId(null); - } - - @Test - public void whenPatientIdIsEmpty_shouldThrowAnException() throws Exception { - assertExceptionThrownForPatientId(""); - } - - private void assertExceptionThrownForPatientId(String patientId) { - Optional exception = TestUtils.assertThrown(() -> { - try { - patientSamplesWithCmoInfoRetriever.retrieve - (patientId, dataRecordManager, user); - } catch (LimsException e) { - e.printStackTrace(); - } - }); - - Assert.assertThat(exception.isPresent(), is(true)); - Assert.assertThat(exception.get().getClass(), IsCompatibleType.typeCompatibleWith(CommonUtils - .NullOrEmptyException.class)); - } -} \ No newline at end of file diff --git a/src/test/java/org/mskcc/limsrest/service/PromoteBankedTest.java b/src/test/java/org/mskcc/limsrest/service/PromoteBankedTest.java index 84277559..6842f87c 100644 --- a/src/test/java/org/mskcc/limsrest/service/PromoteBankedTest.java +++ b/src/test/java/org/mskcc/limsrest/service/PromoteBankedTest.java @@ -17,7 +17,6 @@ import org.mskcc.domain.sample.BankedSample; import org.mskcc.domain.sample.CmoSampleInfo; import org.mskcc.limsrest.ConnectionLIMS; -import org.mskcc.limsrest.service.cmoinfo.CorrectedCmoSampleIdGenerator; import java.rmi.RemoteException; import java.util.*; diff --git a/src/test/java/org/mskcc/limsrest/service/cmoinfo/CmoSampleIdTest.java b/src/test/java/org/mskcc/limsrest/service/cmoinfo/CmoSampleIdTest.java deleted file mode 100644 index 575cd9a1..00000000 --- a/src/test/java/org/mskcc/limsrest/service/cmoinfo/CmoSampleIdTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.mskcc.limsrest.service.cmoinfo; - -import org.hamcrest.object.IsCompatibleType; -import org.junit.Test; -import org.mskcc.limsrest.service.cmoinfo.patientsample.PatientAwareCmoSampleId; -import org.mskcc.util.TestUtils; - -import java.util.Optional; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - -public class CmoSampleIdTest { - @Test - public void whenSampleCountExceedsRange_shouldThrowAnException() throws Exception { - assertExceptionThrownOnCountRangeExceeded(1000); - assertExceptionThrownOnCountRangeExceeded(543342); - - assertExceptionNotThrownOnCountRangeExceeded(999); - assertExceptionNotThrownOnCountRangeExceeded(1); - } - - private void assertExceptionNotThrownOnCountRangeExceeded(int sampleCount) { - Optional exception = TestUtils.assertThrown(() -> new PatientAwareCmoSampleId("P1", "L", - sampleCount, "r")); - - assertThat(exception.isPresent(), is(false)); - } - - private void assertExceptionThrownOnCountRangeExceeded(int sampleCount) { - Optional exception = TestUtils.assertThrown(() -> new PatientAwareCmoSampleId("P1", "L", - sampleCount, "r")); - - assertThat(exception.isPresent(), is(true)); - assertThat(exception.get().getClass(), IsCompatibleType.typeCompatibleWith(IllegalArgumentException.class)); - } -} \ No newline at end of file diff --git a/src/test/java/org/mskcc/limsrest/service/cmoinfo/IncrementalSampleCounterRetrieverTest.java b/src/test/java/org/mskcc/limsrest/service/cmoinfo/IncrementalSampleCounterRetrieverTest.java deleted file mode 100644 index 765e8d58..00000000 --- a/src/test/java/org/mskcc/limsrest/service/cmoinfo/IncrementalSampleCounterRetrieverTest.java +++ /dev/null @@ -1,186 +0,0 @@ -package org.mskcc.limsrest.service.cmoinfo; - -import org.junit.Test; -import org.mskcc.domain.sample.CorrectedCmoSampleView; -import org.mskcc.limsrest.service.cmoinfo.converter.CorrectedCmoIdConverterFactory; -import org.mskcc.limsrest.service.cmoinfo.converter.CorrectedCmoSampleViewToSampleCmoIdConverter; -import org.mskcc.limsrest.service.cmoinfo.cspace.PatientAwareCorrectedCmoIdConverter; -import org.mskcc.limsrest.service.cmoinfo.retriever.IncrementalSampleCounterRetriever; -import org.mskcc.util.TestUtils; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Optional; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.typeCompatibleWith; - -public class IncrementalSampleCounterRetrieverTest { - private CorrectedCmoSampleView correctedCmoSampleView = getCorrectedCmoSampleView(); - - private CorrectedCmoIdConverterFactory converterFactory = new ConverterFactoryMock(); - - private IncrementalSampleCounterRetriever incrementalSampleCounterRetriever = new - IncrementalSampleCounterRetriever(converterFactory); - @Test - public void whenSampleCmoIdListIsEmpty_shouldReturnOne() throws Exception { - List sampleCmoIds = Collections.emptyList(); - - int sampleCount = incrementalSampleCounterRetriever.retrieve(correctedCmoSampleView, sampleCmoIds, "X"); - - assertThat(sampleCount, is(1)); - } - - @Test - public void whenSampleCmoIdListContainsOneElementWithOtherClass_shouldReturnOne() throws Exception { - List sampleCmoIds = Arrays.asList(getSample("C-123456-L001-d")); - String sampleClassAbbr = "X"; - - int sampleCount = incrementalSampleCounterRetriever.retrieve(correctedCmoSampleView, sampleCmoIds, sampleClassAbbr); - - assertThat(sampleCount, is(1)); - } - - private CorrectedCmoSampleView getSample(String correctedCmoId) { - CorrectedCmoSampleView sample = new CorrectedCmoSampleView("sampleId"); - sample.setCorrectedCmoId(correctedCmoId); - return sample; - } - - @Test - public void whenSampleCmoIdListContainsMultipleElementsWithOtherClasses_shouldReturnOne() throws Exception { - List sampleCmoIds = Arrays.asList(getSample("C-123456-L001-d"), getSample - ("C-123456-L002-d"), getSample("C-123456-T001-d"), getSample("C-123456-N001-d")); - String sampleClassAbbr = "X"; - - int sampleCount = incrementalSampleCounterRetriever.retrieve(correctedCmoSampleView, sampleCmoIds, sampleClassAbbr); - - assertThat(sampleCount, is(1)); - } - - @Test - public void whenSampleCmoIdListContainsSampleWithSameClassAndOthers_shouldReturnIncrementedSameClassCounter() - throws Exception { - List sampleCmoIds = Arrays.asList(getSample("C-123456-X003-d"), getSample - ("C-123456-L001-d"), getSample("C-123456-L002-d"), getSample("C-123456-T001-d"), getSample - ("C-123456-N001-d")); - String sampleClassAbbr = "X"; - - int sampleCount = incrementalSampleCounterRetriever.retrieve(correctedCmoSampleView, sampleCmoIds, sampleClassAbbr); - - assertThat(sampleCount, is(4)); - } - - @Test - public void whenSampleCmoIdListContainsOneElementWithGivenClass_shouldReturnTwo() throws Exception { - List sampleCmoIds = Arrays.asList(getSample("C-123456-N001-d")); - String sampleClassAbbr = "N"; - - int sampleCount = incrementalSampleCounterRetriever.retrieve(correctedCmoSampleView, sampleCmoIds, sampleClassAbbr); - - assertThat(sampleCount, is(2)); - } - - @Test - public void whenSampleCmoIdListContainsElementWithSampleCountSix_shouldReturnSeven() throws Exception { - List sampleCmoIds = Arrays.asList(getSample("C-123456-N006-d")); - String sampleClassAbbr = "N"; - - int sampleCount = incrementalSampleCounterRetriever.retrieve(correctedCmoSampleView, sampleCmoIds, sampleClassAbbr); - - assertThat(sampleCount, is(7)); - } - - @Test - public void whenSampleCmoIdListContainsElementWithTwoDigitSampleCount_shouldReturnThisCountPlusOne() throws - Exception { - List sampleCmoIds = Arrays.asList(getSample("C-123456-N010-d")); - String sampleClassAbbr = "N"; - - int sampleCount = incrementalSampleCounterRetriever.retrieve(correctedCmoSampleView, sampleCmoIds, sampleClassAbbr); - - assertThat(sampleCount, is(11)); - } - - @Test - public void whenSampleCmoIdListContainsElementWithThreeDigitSampleCount_shouldReturnThisCountPlusOne() throws - Exception { - List sampleCmoIds = Arrays.asList(getSample("C-123456-N654-d")); - String sampleClassAbbr = "N"; - - int sampleCount = incrementalSampleCounterRetriever.retrieve(correctedCmoSampleView, sampleCmoIds, sampleClassAbbr); - - assertThat(sampleCount, is(655)); - } - - @Test - public void whenSampleCmoIdListContainsElementWithMaxCountValue_shouldThrowException() throws Exception { - List sampleCmoIds = Arrays.asList(getSample("C-123456-N999-d")); - String sampleClassAbbr = "N"; - - Optional exception = TestUtils.assertThrown(() -> incrementalSampleCounterRetriever.retrieve - (correctedCmoSampleView, sampleCmoIds, sampleClassAbbr)); - - assertThat(exception.isPresent(), is(true)); - assertThat(exception.get().getClass(), typeCompatibleWith(IncrementalSampleCounterRetriever - .SampleCounterOverflowException.class)); - } - - @Test - public void whenSampleCmoIdListContainsOneElementWithEmptyCmoId_shouldReturnOne() throws Exception { - List sampleCmoIds = Arrays.asList(getSample("")); - String sampleClassAbbr = "N"; - - int sampleCount = incrementalSampleCounterRetriever.retrieve(correctedCmoSampleView, sampleCmoIds, sampleClassAbbr); - - assertThat(sampleCount, is(1)); - } - - @Test - public void whenSampleCmoIdListContainsOneElementWithNullCmoId_shouldReturnOne() throws Exception { - List sampleCmoIds = Arrays.asList(getSample(null)); - String sampleClassAbbr = "N"; - - int sampleCount = incrementalSampleCounterRetriever.retrieve(correctedCmoSampleView, sampleCmoIds, sampleClassAbbr); - - assertThat(sampleCount, is(1)); - } - - @Test - public void whenCounterIsAlreadySet_shouldUseThatOne() throws Exception { - //given - List sampleCmoIds = Arrays.asList(getSample("C-123456-N123-d")); - String sampleClassAbbr = "N"; - - //when - int counter = 3; - int sampleCount = incrementalSampleCounterRetriever.retrieve(getSampleViewWithCounter(counter), sampleCmoIds, sampleClassAbbr); - - //then - assertThat(sampleCount, is(counter)); - } - - private CorrectedCmoSampleView getSampleViewWithCounter(int counter) { - CorrectedCmoSampleView correctedCmoSampleView = new CorrectedCmoSampleView("id3"); - correctedCmoSampleView.setCounter(counter); - - return correctedCmoSampleView; - } - - private CorrectedCmoSampleView getCorrectedCmoSampleView() { - CorrectedCmoSampleView correctedCmoSampleView = new CorrectedCmoSampleView("id"); - - - return correctedCmoSampleView; - } - - private class ConverterFactoryMock implements CorrectedCmoIdConverterFactory { - - @Override - public CorrectedCmoSampleViewToSampleCmoIdConverter getConverter(String correctedCmoSampleId) { - return new PatientAwareCorrectedCmoIdConverter(); - } - } -} diff --git a/src/test/java/org/mskcc/limsrest/service/cmoinfo/PatientAwareCmoSampleIdFormatterTest.java b/src/test/java/org/mskcc/limsrest/service/cmoinfo/PatientAwareCmoSampleIdFormatterTest.java deleted file mode 100644 index 3d2cdb48..00000000 --- a/src/test/java/org/mskcc/limsrest/service/cmoinfo/PatientAwareCmoSampleIdFormatterTest.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.mskcc.limsrest.service.cmoinfo; - -import org.junit.Test; -import org.mskcc.limsrest.service.cmoinfo.patientsample.PatientAwareCmoSampleId; -import org.mskcc.limsrest.service.cmoinfo.patientsample.PatientCmoSampleIdFormatter; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - -public class PatientAwareCmoSampleIdFormatterTest { - private PatientCmoSampleIdFormatter patientCmoSampleIdFormatter = new PatientCmoSampleIdFormatter(); - - @Test - public void whenAllCmoIdPropertiesArePresent_shouldReturnFormattedSampleCmoId() throws Exception { - assertFormatterCmoSampleId("C-1234", "T", 1, "d", "C-1234-T001-d"); - assertFormatterCmoSampleId("C-123456", "N", 2, "d", "C-123456-N002-d"); - assertFormatterCmoSampleId("C-6565", "T", 34, "d", "C-6565-T034-d"); - assertFormatterCmoSampleId("C-76", "T", 682, "d", "C-76-T682-d"); - - assertFormatterCmoSampleId("C-543", "T", 5, "r", "C-543-T005-r"); - assertFormatterCmoSampleId("C-54354", "T", 5, "r", "C-54354-T005-r"); - assertFormatterCmoSampleId("C-6543", "T", 5, "r", "C-6543-T005-r"); - - assertFormatterCmoSampleId("C-5443", "T", 5, "r", "C-5443-T005-r"); - assertFormatterCmoSampleId("C-54534", "T", 5, "r", "C-54534-T005-r"); - } - - - private void assertFormatterCmoSampleId(String patientId, String sampleClass, int sampleCount, String nucleicAcid, String expected) { - //given - PatientAwareCmoSampleId patientAwareCmoSampleId = new PatientAwareCmoSampleId(patientId, sampleClass, - sampleCount, nucleicAcid); - - //when - String formattedCmoSampleId = patientCmoSampleIdFormatter.format(patientAwareCmoSampleId); - - //then - assertThat(formattedCmoSampleId, is(expected)); - } -} \ No newline at end of file diff --git a/src/test/java/org/mskcc/limsrest/service/cmoinfo/PatientAwareCmoSampleIdResolverTest.java b/src/test/java/org/mskcc/limsrest/service/cmoinfo/PatientAwareCmoSampleIdResolverTest.java deleted file mode 100644 index 94886ddd..00000000 --- a/src/test/java/org/mskcc/limsrest/service/cmoinfo/PatientAwareCmoSampleIdResolverTest.java +++ /dev/null @@ -1,309 +0,0 @@ -package org.mskcc.limsrest.service.cmoinfo; - -import org.junit.Before; -import org.junit.Test; -import org.mskcc.domain.Recipe; -import org.mskcc.domain.sample.*; -import org.mskcc.limsrest.service.cmoinfo.cspace.CfDnaSampleAbbreviationResolver; -import org.mskcc.limsrest.service.cmoinfo.cspace.ClassSampleAbbreviationResolver; -import org.mskcc.limsrest.service.cmoinfo.cspace.CspaceSampleTypeAbbreviationRetriever; -import org.mskcc.limsrest.service.cmoinfo.cspace.SpecimenTypeSampleAbbreviationResolver; -import org.mskcc.limsrest.service.cmoinfo.patientsample.PatientAwareCmoSampleId; -import org.mskcc.limsrest.service.cmoinfo.patientsample.PatientCmoSampleIdResolver; -import org.mskcc.limsrest.service.cmoinfo.retriever.IncrementalSampleCounterRetriever; -import org.mskcc.limsrest.service.cmoinfo.retriever.SampleTypeAbbreviationRetriever; -import org.mskcc.util.Constants; -import org.mskcc.util.TestUtils; - -import java.util.Collections; -import java.util.Optional; -import java.util.UUID; - -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import static org.mskcc.util.TestUtils.assertThrown; - -public class PatientAwareCmoSampleIdResolverTest { - private PatientCmoSampleIdResolver patientCmoSampleIdResolver; - private CorrectedCmoSampleView sample; - private IncrementalSampleCounterRetriever countRetriever = mock(IncrementalSampleCounterRetriever.class); - private String requestId = "6543w2_O"; - private String sampleId = "s43222"; - private SampleTypeAbbreviationRetriever sampleTypeAbbreviationRetriever = new - CspaceSampleTypeAbbreviationRetriever(); - - @Before - public void setUp() throws Exception { - patientCmoSampleIdResolver = new PatientCmoSampleIdResolver(countRetriever, sampleTypeAbbreviationRetriever); - sample = new CorrectedCmoSampleView(sampleId); - when(countRetriever.retrieve(any(), any(), any())).thenReturn(1); - } - - @Test - public void whenPatientIdIsNull_shouldThrowAnException() throws Exception { - //given - sample.setSampleClass(SampleClass.UNKNOWN_TUMOR); - sample.setNucleidAcid(NucleicAcid.DNA); - - //when - Optional exception = assertThrown(() -> patientCmoSampleIdResolver.resolve(sample, Collections - .emptyList(), requestId)); - - //then - assertThat(exception.isPresent(), is(true)); - } - - @Test - public void whenPatientIdIsEmpty_shouldThrowAnException() throws Exception { - //given - sample.setPatientId(""); - sample.setSampleClass(SampleClass.UNKNOWN_TUMOR); - sample.setNucleidAcid(NucleicAcid.DNA); - - //when - Optional exception = assertThrown(() -> patientCmoSampleIdResolver.resolve(sample, Collections - .emptyList(), requestId)); - - //then - assertThat(exception.isPresent(), is(true)); - } - - @Test - public void whenSampleClassIsNull_shouldThrowAnException() throws Exception { - //given - sample.setPatientId(getRandomPatientId()); - sample.setNucleidAcid(NucleicAcid.DNA); - - //when - Optional exception = assertThrown(() -> patientCmoSampleIdResolver.resolve(sample, Collections.emptyList(), requestId)); - - //then - assertThat(exception.isPresent(), is(true)); - } - - @Test - public void whenSampleClassIsEmpty_shouldThrowAnException() throws Exception { - //given - sample.setPatientId(getRandomPatientId()); - sample.setSampleClass(null); - sample.setNucleidAcid(NucleicAcid.DNA); - - //when - Optional exception = assertThrown(() -> patientCmoSampleIdResolver.resolve(sample, Collections.emptyList(), requestId)); - - //then - assertThat(exception.isPresent(), is(true)); - } - - @Test - public void whenNucleicAcidIsNull_shouldThrowAnException() throws Exception { - //given - sample.setPatientId(getRandomPatientId()); - sample.setSampleClass(SampleClass.ADJACENT_TISSUE); - - //when - Optional exception = assertThrown(() -> patientCmoSampleIdResolver.resolve(sample, Collections.emptyList(), requestId)); - - //then - assertThat(exception.isPresent(), is(true)); - } - - @Test - public void whenNucleicAcidIsEmpty_shouldThrowAnException() throws Exception { - //given - sample.setPatientId(getRandomPatientId()); - sample.setSampleClass(SampleClass.ADJACENT_TISSUE); - sample.setNucleidAcid(null); - - //when - Optional exception = assertThrown(() -> patientCmoSampleIdResolver.resolve(sample, Collections.emptyList(), requestId)); - - //then - assertThat(exception.isPresent(), is(true)); - } - - private String getRandomPatientId() { - return UUID.randomUUID().toString(); - } - - @Test - public void whenSpecimenTypeIsXenograft_shouldCreateCmoSampleIdWithX() throws Exception { - assertCmoSampleIdBySpecimen(getRandomPatientId(), NucleicAcid.DNA, SpecimenType.XENOGRAFT); - assertCmoSampleIdBySpecimen(getRandomPatientId(), NucleicAcid.DNA, SpecimenType.PDX); - assertCmoSampleIdBySpecimen(getRandomPatientId(), NucleicAcid.DNA, SpecimenType.XENOGRAFTDERIVEDCELLLINE); - } - - @Test - public void whenSpecimenTypeIsOrganoid_shouldCreateCmoSampleIdWithG() throws Exception { - assertCmoSampleIdBySpecimen(getRandomPatientId(), NucleicAcid.DNA, SpecimenType.ORGANOID); - } - - @Test - public void whenSpecimenTypeIsCfdna_shouldCreateCmoSampleIdBySampleOrigin() throws Exception { - assertCmoSampleIdBySpecimenByOrigin(getRandomPatientId(), NucleicAcid.DNA, SpecimenType.CFDNA, SampleOrigin.URINE); - assertCmoSampleIdBySpecimenByOrigin(getRandomPatientId(), NucleicAcid.DNA, SpecimenType.CFDNA, SampleOrigin.CEREBROSPINAL_FLUID); - assertCmoSampleIdBySpecimenByOrigin(getRandomPatientId(), NucleicAcid.DNA, SpecimenType.CFDNA, SampleOrigin.PLASMA); - assertCmoSampleIdBySpecimenByOrigin(getRandomPatientId(), NucleicAcid.DNA, SpecimenType.CFDNA, SampleOrigin.WHOLE_BLOOD); - } - - private void assertCmoSampleIdBySpecimenByOrigin(String patientId, NucleicAcid nucleicAcid, SpecimenType specimenType, SampleOrigin sampleOrigin) { - //given - CorrectedCmoSampleView sample = new CorrectedCmoSampleView("sampleId"); - sample.setPatientId(patientId); - sample.setSpecimenType(specimenType); - sample.setNucleidAcid(nucleicAcid); - sample.setSampleOrigin(sampleOrigin); - - //when - PatientAwareCmoSampleId cmoSampleId = patientCmoSampleIdResolver.resolve(sample, Collections.emptyList(), - requestId); - - //then - assertThat(cmoSampleId.getPatientId(), is(patientId)); - assertThat(cmoSampleId.getSampleTypeAbbr(), is(CfDnaSampleAbbreviationResolver - .getSampleOriginToAbbreviation().get(sampleOrigin))); - assertThat(cmoSampleId.getSampleCount(), is(1)); - assertThat(cmoSampleId.getNucleicAcid(), is(CspaceSampleTypeAbbreviationRetriever.getNucleicAcid2Abbreviation - ().get(nucleicAcid))); - } - - @Test - public void whenSpecimenTypeIsNotCelllineNorXenograftNorOrganoidNorCfDna_shouldCreateCmoSampleIdBySampleClass() throws Exception { - assertCmoSampleIdBySampleClass(getRandomPatientId(), NucleicAcid.DNA, SpecimenType.BIOPSY, SampleClass.UNKNOWN_TUMOR); - assertCmoSampleIdBySampleClass(getRandomPatientId(), NucleicAcid.DNA, SpecimenType.BLOOD, SampleClass.LOCAL_RECURRENCE); - assertCmoSampleIdBySampleClass(getRandomPatientId(), NucleicAcid.DNA, SpecimenType.FINGERNAILS, SampleClass.PRIMARY); - assertCmoSampleIdBySampleClass(getRandomPatientId(), NucleicAcid.DNA, SpecimenType.RAPIDAUTOPSY, SampleClass.METASTASIS); - assertCmoSampleIdBySampleClass(getRandomPatientId(), NucleicAcid.DNA, SpecimenType.OTHER, SampleClass.NORMAL); - assertCmoSampleIdBySampleClass(getRandomPatientId(), NucleicAcid.DNA, SpecimenType.RESECTION, SampleClass.ADJACENT_NORMAL); - assertCmoSampleIdBySampleClass(getRandomPatientId(), NucleicAcid.DNA, SpecimenType.SALIVA, SampleClass.ADJACENT_TISSUE); - } - - private void assertCmoSampleIdBySampleClass(String patientId, NucleicAcid nucleicAcid, SpecimenType specimenType, - SampleClass sampleClass) { - //given - CorrectedCmoSampleView sample = new CorrectedCmoSampleView("sampleId"); - sample.setPatientId(patientId); - sample.setSpecimenType(specimenType); - sample.setNucleidAcid(nucleicAcid); - sample.setSampleClass(sampleClass); - - //when - PatientAwareCmoSampleId cmoSampleId = patientCmoSampleIdResolver.resolve(sample, Collections.emptyList(), - requestId); - - //then - assertThat(cmoSampleId.getPatientId(), is(patientId)); - assertThat(cmoSampleId.getSampleTypeAbbr(), is(ClassSampleAbbreviationResolver.getSampleClassToAbbreviation - ().get(sampleClass))); - assertThat(cmoSampleId.getSampleCount(), is(1)); - assertThat(cmoSampleId.getNucleicAcid(), is(CspaceSampleTypeAbbreviationRetriever.getNucleicAcid2Abbreviation().get(nucleicAcid))); - } - - private void assertCmoSampleIdBySpecimen(String patientId, NucleicAcid nucleicAcid, SpecimenType specimenType) { - //given - CorrectedCmoSampleView sample = new CorrectedCmoSampleView("sampleId"); - sample.setPatientId(patientId); - sample.setSpecimenType(specimenType); - sample.setNucleidAcid(nucleicAcid); - - //when - PatientAwareCmoSampleId cmoSampleId = patientCmoSampleIdResolver.resolve(sample, Collections.emptyList(), requestId); - - //then - assertThat(cmoSampleId.getPatientId(), is(patientId)); - assertThat(cmoSampleId.getSampleTypeAbbr(), is(SpecimenTypeSampleAbbreviationResolver - .getSpecimenTypeToAbbreviation().get(specimenType))); - assertThat(cmoSampleId.getSampleCount(), is(1)); - assertThat(cmoSampleId.getNucleicAcid(), is(CspaceSampleTypeAbbreviationRetriever.getNucleicAcid2Abbreviation().get(nucleicAcid))); - } - - @Test - public void whenSampleTypeIsPooledLibraryAndRecipeRNASeq_shouldSetRNA() throws Exception { - //given - CorrectedCmoSampleView sample = new CorrectedCmoSampleView("sampleId"); - String patientId = getRandomPatientId(); - SpecimenType specimenType = SpecimenType.XENOGRAFT; - - sample.setPatientId(patientId); - sample.setSpecimenType(specimenType); - sample.setSampleType(SampleType.POOLED_LIBRARY); - sample.setRecipe(Recipe.RNA_SEQ); - - //when - PatientAwareCmoSampleId cmoSampleId = patientCmoSampleIdResolver.resolve(sample, Collections.emptyList(), - requestId); - - //then - assertThat(cmoSampleId.getPatientId(), is(patientId)); - assertThat(cmoSampleId.getSampleTypeAbbr(), is(SpecimenTypeSampleAbbreviationResolver - .getSpecimenTypeToAbbreviation().get(specimenType))); - assertThat(cmoSampleId.getSampleCount(), is(1)); - assertThat(cmoSampleId.getNucleicAcid(), is(Constants.RNA_ABBREV)); - - } - - @Test - public void whenSampleClassIsCellFreeAndSampleOriginIsNull_shouldThrowAnException() throws Exception { - //given - String patientId = getRandomPatientId(); - SampleClass cellFreeSampleClass = SampleClass.CELL_FREE; - NucleicAcid nucleicAcid = NucleicAcid.DNA; - - sample.setPatientId(patientId); - sample.setSampleClass(cellFreeSampleClass); - sample.setNucleidAcid(nucleicAcid); - - //when - Optional exception = assertThrown(() -> patientCmoSampleIdResolver.resolve(sample, Collections.emptyList(), requestId)); - - //then - assertThat(exception.isPresent(), is(true)); - } - - @Test - public void whenSampleClassIsCellFreeAndSampleOriginIsEmpty_shouldThrowAnException() throws Exception { - //given - String patientId = getRandomPatientId(); - SampleClass cellFreeSampleClass = SampleClass.CELL_FREE; - NucleicAcid nucleicAcid = NucleicAcid.DNA; - - sample.setPatientId(patientId); - sample.setSampleClass(cellFreeSampleClass); - sample.setNucleidAcid(nucleicAcid); - sample.setSampleOrigin(null); - - //when - Optional exception = assertThrown(() -> patientCmoSampleIdResolver.resolve(sample, Collections.emptyList(), requestId)); - - //then - assertThat(exception.isPresent(), is(true)); - } - - @Test - public void whenSampleIsCellFree_shouldThrowAnException() throws Exception { - //given - String patientId = getRandomPatientId(); - SampleClass sampleClass = SampleClass.CELL_FREE; - SampleOrigin sampleOrigin = SampleOrigin.CEREBROSPINAL_FLUID; - NucleicAcid nucleicAcid = NucleicAcid.DNA; - - sample.setPatientId(patientId); - sample.setSampleClass(sampleClass); - sample.setNucleidAcid(nucleicAcid); - sample.setSampleOrigin(sampleOrigin); - sample.setSpecimenType(SpecimenType.BIOPSY); - - //when - Optional exception = TestUtils.assertThrown(() -> patientCmoSampleIdResolver.resolve(sample, - Collections.emptyList(), requestId)); - - //then - assertTrue(exception.isPresent()); - } - -} - diff --git a/src/test/java/org/mskcc/limsrest/service/cmoinfo/SampleTypeCorrectedCmoSampleIdGeneratorTest.java b/src/test/java/org/mskcc/limsrest/service/cmoinfo/SampleTypeCorrectedCmoSampleIdGeneratorTest.java deleted file mode 100644 index 84eb2cec..00000000 --- a/src/test/java/org/mskcc/limsrest/service/cmoinfo/SampleTypeCorrectedCmoSampleIdGeneratorTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.mskcc.limsrest.service.cmoinfo; - -import org.junit.Test; -import org.mskcc.domain.sample.CorrectedCmoSampleView; -import org.mskcc.limsrest.service.cmoinfo.retriever.CmoSampleIdRetrieverFactory; -import org.springframework.context.annotation.PropertySource; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; - -@PropertySource("classpath:application-test.properties") -public class SampleTypeCorrectedCmoSampleIdGeneratorTest { - private CmoSampleIdRetrieverFactory factory = mock(CmoSampleIdRetrieverFactory.class); - - @Test - public void whenCmoSampleIdIsSameAsBefore_shouldNotOverrideIt() throws Exception { - CorrectedCmoSampleView correctedCmoSampleView = new CorrectedCmoSampleView("sampleId"); - String currentId = "C-123456-X001-d"; - correctedCmoSampleView.setCorrectedCmoId(currentId); - - assertFalse(SampleTypeCorrectedCmoSampleIdGenerator.shouldOverrideCmoId(correctedCmoSampleView, "C-123456-X002-d")); - } - - @Test - public void whenCmoSampleIdIsOldFormat() throws Exception { - CorrectedCmoSampleView correctedCmoSampleView = new CorrectedCmoSampleView("sampleId"); - String currentId = "RL-IDH1-011-T9"; - correctedCmoSampleView.setCorrectedCmoId(currentId); - - assertTrue(SampleTypeCorrectedCmoSampleIdGenerator.shouldOverrideCmoId(correctedCmoSampleView, "C-123456-X002-d")); - } -} \ No newline at end of file diff --git a/src/test/java/org/mskcc/limsrest/service/cmoinfo/SampleTypeCorrectedCmoSampleViewGeneratorTest.java b/src/test/java/org/mskcc/limsrest/service/cmoinfo/SampleTypeCorrectedCmoSampleViewGeneratorTest.java deleted file mode 100644 index 2be80f2a..00000000 --- a/src/test/java/org/mskcc/limsrest/service/cmoinfo/SampleTypeCorrectedCmoSampleViewGeneratorTest.java +++ /dev/null @@ -1,200 +0,0 @@ -package org.mskcc.limsrest.service.cmoinfo; - -import com.velox.api.datarecord.DataRecordManager; -import com.velox.api.user.User; -import org.junit.Before; -import org.junit.Test; -import org.mskcc.domain.sample.CorrectedCmoSampleView; -import org.mskcc.domain.sample.NucleicAcid; -import org.mskcc.domain.sample.SpecimenType; -import org.mskcc.limsrest.service.PatientSamplesWithCmoInfoRetriever; -import org.mskcc.limsrest.service.cmoinfo.cellline.CellLineCmoSampleIdFormatter; -import org.mskcc.limsrest.service.cmoinfo.cellline.CellLineCmoSampleIdResolver; -import org.mskcc.limsrest.service.cmoinfo.converter.CorrectedCmoIdConverterFactory; -import org.mskcc.limsrest.service.cmoinfo.converter.FormatAwareCorrectedCmoIdConverterFactory; -import org.mskcc.limsrest.service.cmoinfo.cspace.CspaceSampleTypeAbbreviationRetriever; -import org.mskcc.limsrest.service.cmoinfo.formatter.CmoSampleIdFormatter; -import org.mskcc.limsrest.service.cmoinfo.patientsample.PatientCmoSampleIdFormatter; -import org.mskcc.limsrest.service.cmoinfo.patientsample.PatientCmoSampleIdResolver; -import org.mskcc.limsrest.service.cmoinfo.retriever.*; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class SampleTypeCorrectedCmoSampleViewGeneratorTest { - private final PatientSamplesWithCmoInfoRetriever samplesRetriever = mock(PatientSamplesWithCmoInfoRetriever.class); - - private SampleTypeCorrectedCmoSampleIdGenerator sampleTypeCorrectedCmoSampleIdGenerator; - private DataRecordManager drm = mock(DataRecordManager.class); - private User user = mock(User.class); - private CmoSampleIdRetrieverFactory retrieverFactory; - private SampleTypeAbbreviationRetriever abbrRetriever = new CspaceSampleTypeAbbreviationRetriever(); - private CorrectedCmoIdConverterFactory convFactory = new FormatAwareCorrectedCmoIdConverterFactory(abbrRetriever); - - @Before - public void setUp() throws Exception { - SampleCounterRetriever counterRetriever = new IncrementalSampleCounterRetriever(convFactory); - CmoSampleIdResolver patientResolver = new PatientCmoSampleIdResolver(counterRetriever, abbrRetriever); - CmoSampleIdFormatter patientFormatter = new PatientCmoSampleIdFormatter(); - CmoSampleIdRetriever patientRetriever = new FormattedCmoSampleIdRetriever(patientResolver, patientFormatter); - CmoSampleIdResolver cellLineResolver = new CellLineCmoSampleIdResolver(); - CmoSampleIdFormatter cellLineFormatter = new CellLineCmoSampleIdFormatter(); - CmoSampleIdRetriever cellLineRetriever = new FormattedCmoSampleIdRetriever(cellLineResolver, cellLineFormatter); - retrieverFactory = new CmoSampleIdRetrieverFactory(patientRetriever, cellLineRetriever); - - sampleTypeCorrectedCmoSampleIdGenerator = new SampleTypeCorrectedCmoSampleIdGenerator(); - } - - @Test - public void whenThereAreNoPatientSamples_shouldReturnCmoIdWithNumber1() throws Exception { - when(samplesRetriever.retrieve(any(), any(), any())).thenReturn(Collections.emptyList()); - CorrectedCmoSampleView sample = getSample("4324", "C-1235", SpecimenType.XENOGRAFT, NucleicAcid.DNA); - - String cmoId = sampleTypeCorrectedCmoSampleIdGenerator.generate(sample, "5432_P", drm, user); - - assertThat(cmoId, is("C-1235-X001-d")); - } - - @Test - public void whenThereIsOnePatientSampleFromSameRequestWithCount1_shouldReturnCmoIdWithNumber2() throws Exception { - String requestId = "5432_P"; - when(samplesRetriever.retrieve(any(), any(), any())).thenReturn(Arrays.asList(getSample("C-1235-X001-d", requestId))); - sampleTypeCorrectedCmoSampleIdGenerator.patientSamplesRetriever = samplesRetriever; - - CorrectedCmoSampleView sample = getSample("4324", "C-1235", SpecimenType.XENOGRAFT, NucleicAcid.DNA); - - String cmoId = sampleTypeCorrectedCmoSampleIdGenerator.generate(sample, requestId, drm, user); - - assertThat(cmoId, is("C-1235-X002-d")); - } - - @Test - public void whenThereIsOnePatientSampleFromSameRequestWithSomeCount_shouldReturnCmoIdWithThisCountPlusOne() - throws Exception { - String requestId = "5432_P"; - when(samplesRetriever.retrieve(any(), any(), any())).thenReturn(Arrays.asList(getSample("C-1235-X012-d", requestId))); - sampleTypeCorrectedCmoSampleIdGenerator.patientSamplesRetriever = samplesRetriever; - CorrectedCmoSampleView sample = getSample("4324", "C-1235", SpecimenType.XENOGRAFT, NucleicAcid.DNA); - - - String cmoId = sampleTypeCorrectedCmoSampleIdGenerator.generate(sample, requestId, drm, user); - - //then - assertThat(cmoId, is("C-1235-X013-d")); - } - - @Test - public void whenThereIsOnePatientSampleFromDifferentRequest_shouldReturnCmoIdWithNumber2() throws Exception { - when(samplesRetriever.retrieve(any(), any(), any())).thenReturn(Arrays.asList(getSample("C-1235-X001-d", - "1234_A"))); - sampleTypeCorrectedCmoSampleIdGenerator.patientSamplesRetriever = samplesRetriever; - CorrectedCmoSampleView sample = getSample("4324", "C-1235", SpecimenType.PDX, NucleicAcid.RNA); - - //when - String cmoId = sampleTypeCorrectedCmoSampleIdGenerator.generate(sample, "5432_P", drm, user); - - //then - assertThat(cmoId, is("C-1235-X002-r")); - } - - @Test - public void - whenThereAreNoPatientSamplesButOneWasAlreadyCreatedFromSameRequestSameSpecimenSampleNucl_shouldReturnCmoIdWithNumber2() throws Exception { - //given - when(samplesRetriever.retrieve(any(), any(), any())).thenReturn(new ArrayList<>()); - String patientId = "C-1235"; - String requestId = "5432_P"; - CorrectedCmoSampleView sample1 = getSample("4324_1", patientId, SpecimenType.XENOGRAFT, NucleicAcid.DNA); - CorrectedCmoSampleView sample2 = getSample("4324_2", patientId, SpecimenType.XENOGRAFT, NucleicAcid.DNA); - - String cmoId1 = sampleTypeCorrectedCmoSampleIdGenerator.generate(sample1, requestId, drm, user); - - //when - String cmoId2 = sampleTypeCorrectedCmoSampleIdGenerator.generate(sample2, requestId, drm, user); - - //then - assertThat(cmoId1, is("C-1235-X001-d")); - assertThat(cmoId2, is("C-1235-X002-d")); - } - - @Test - public void - whenThereAreNoPatientSamplesButOneWasAlreadyCreatedFromSameRequestSameSpecimenDifferentNucl_shouldReturnCmoIdWithNumber2() throws Exception { - //given - when(samplesRetriever.retrieve(any(), any(), any())).thenReturn(new ArrayList<>()); - String patientId = "C-1235"; - String requestId = "5432_P"; - CorrectedCmoSampleView sample1 = getSample("4324_1", patientId, SpecimenType.XENOGRAFT, NucleicAcid.DNA); - CorrectedCmoSampleView sample2 = getSample("4324_2", patientId, SpecimenType.XENOGRAFT, NucleicAcid.RNA); - - String cmoId1 = sampleTypeCorrectedCmoSampleIdGenerator.generate(sample1, requestId, drm, user); - - //when - String cmoId2 = sampleTypeCorrectedCmoSampleIdGenerator.generate(sample2, requestId, drm, user); - - //then - assertThat(cmoId1, is("C-1235-X001-d")); - assertThat(cmoId2, is("C-1235-X002-r")); - } - - @Test - public void - whenThereAreNoPatientSamplesButOneWasAlreadyCreatedFromSameRequestSameSampleType_shouldReturnCmoIdWithNumber2() - throws Exception { - //given - when(samplesRetriever.retrieve(any(), any(), any())).thenReturn(new ArrayList<>()); - String patientId = "C-1235"; - String requestId = "5432_P"; - CorrectedCmoSampleView sample1 = getSample("4324_1", patientId, SpecimenType.XENOGRAFT, NucleicAcid.DNA); - CorrectedCmoSampleView sample2 = getSample("4324_2", patientId, SpecimenType.PDX, NucleicAcid.DNA); - - String cmoId1 = sampleTypeCorrectedCmoSampleIdGenerator.generate(sample1, requestId, drm, user); - - //when - String cmoId2 = sampleTypeCorrectedCmoSampleIdGenerator.generate(sample2, requestId, drm, user); - - //then - assertThat(cmoId1, is("C-1235-X001-d")); - assertThat(cmoId2, is("C-1235-X002-d")); - } - - @Test - public void - whenThereAreNoPatientSamplesButOneWasAlreadyCreatedFromDifferentRequestsSampleSpecimen_shouldReturnCmoIdWithNumber2() throws Exception { - when(samplesRetriever.retrieve(any(), any(), any())).thenReturn(new ArrayList<>()); - String patientId = "C-1235"; - CorrectedCmoSampleView sample1 = getSample("4324_1", patientId, SpecimenType.ORGANOID, NucleicAcid.DNA); - CorrectedCmoSampleView sample2 = getSample("4324_2", patientId, SpecimenType.ORGANOID, NucleicAcid.DNA); - - String cmoId1 = sampleTypeCorrectedCmoSampleIdGenerator.generate(sample1, "5432_P", drm, user); - String cmoId2 = sampleTypeCorrectedCmoSampleIdGenerator.generate(sample2, "0789_R", drm, user); - - assertThat(cmoId1, is("C-1235-G001-d")); - assertThat(cmoId2, is("C-1235-G002-d")); - } - - private CorrectedCmoSampleView getSample(String correctedId, String reqId) { - CorrectedCmoSampleView sample = new CorrectedCmoSampleView("5656"); - sample.setCorrectedCmoId(correctedId); - sample.setRequestId(reqId); - sample.setSpecimenType(SpecimenType.XENOGRAFT); - - return sample; - } - - private CorrectedCmoSampleView getSample(String sampleId, String patientId, SpecimenType specimenType, - NucleicAcid nAtoExtract) { - CorrectedCmoSampleView sample = new CorrectedCmoSampleView(sampleId); - sample.setPatientId(patientId); - sample.setSpecimenType(specimenType); - sample.setNucleidAcid(nAtoExtract); - return sample; - } -} \ No newline at end of file diff --git a/src/test/java/org/mskcc/limsrest/service/cmoinfo/cellline/CellLineCmoSampleIdFormatterTest.java b/src/test/java/org/mskcc/limsrest/service/cmoinfo/cellline/CellLineCmoSampleIdFormatterTest.java deleted file mode 100644 index 19f26116..00000000 --- a/src/test/java/org/mskcc/limsrest/service/cmoinfo/cellline/CellLineCmoSampleIdFormatterTest.java +++ /dev/null @@ -1,25 +0,0 @@ -package org.mskcc.limsrest.service.cmoinfo.cellline; - -import org.junit.Test; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -public class CellLineCmoSampleIdFormatterTest { - private CellLineCmoSampleIdFormatter cellLineCmoSampleIdFormatter = new CellLineCmoSampleIdFormatter(); - - @Test - public void whenSampleIdAndRequestIdAreNotNullNorEmpty_shouldReturnFormattedCmoId() throws Exception { - assertCmoSampleId("2144_T_1", "43432_U", "2144_T_1-43432_U"); - assertCmoSampleId("a", "b", "a-b"); - assertCmoSampleId("abd_5_T", "123_U", "abd_5_T-123_U"); - } - - private void assertCmoSampleId(String sampleId, String requestId, String expected) { - CellLineCmoSampleId cmoSampleId = new CellLineCmoSampleId(sampleId, requestId); - - String formattedId = cellLineCmoSampleIdFormatter.format(cmoSampleId); - - assertThat(formattedId, is(expected)); - } -} \ No newline at end of file diff --git a/src/test/java/org/mskcc/limsrest/service/cmoinfo/cellline/CellLineCmoSampleIdTest.java b/src/test/java/org/mskcc/limsrest/service/cmoinfo/cellline/CellLineCmoSampleIdTest.java deleted file mode 100644 index b8ed2380..00000000 --- a/src/test/java/org/mskcc/limsrest/service/cmoinfo/cellline/CellLineCmoSampleIdTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.mskcc.limsrest.service.cmoinfo.cellline; - -import org.hamcrest.object.IsCompatibleType; -import org.junit.Test; -import org.mskcc.util.CommonUtils; -import org.mskcc.util.TestUtils; - -import java.util.Optional; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -public class CellLineCmoSampleIdTest { - - @Test - public void whenSampleIdOrRequestIsInvalidNull_shouldThrowException() throws Exception { - assertExceptionThrown(null, null); - assertExceptionThrown("", ""); - - assertExceptionThrown(null, ""); - assertExceptionThrown("", null); - - assertExceptionThrown(null, "12345_P"); - assertExceptionThrown("12344_P_4", null); - - assertExceptionThrown("", "1234_P"); - assertExceptionThrown("12344_P_4", ""); - } - - private void assertExceptionThrown(String sampleId, String requestId) { - Optional exception = TestUtils.assertThrown(() -> new CellLineCmoSampleId(sampleId, requestId)); - - assertThat(exception.isPresent(), is(true)); - assertThat(exception.get().getClass(), IsCompatibleType.typeCompatibleWith(CommonUtils.NullOrEmptyException - .class)); - } -} \ No newline at end of file diff --git a/src/test/java/org/mskcc/limsrest/service/cmoinfo/converter/BankedSampleToCorrectedCmoSampleIdConverterTest.java b/src/test/java/org/mskcc/limsrest/service/cmoinfo/converter/BankedSampleToCorrectedCmoSampleIdConverterTest.java deleted file mode 100644 index d40d94a8..00000000 --- a/src/test/java/org/mskcc/limsrest/service/cmoinfo/converter/BankedSampleToCorrectedCmoSampleIdConverterTest.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.mskcc.limsrest.service.cmoinfo.converter; - -import org.junit.Test; -import org.mskcc.domain.Recipe; -import org.mskcc.domain.sample.*; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; - -public class BankedSampleToCorrectedCmoSampleIdConverterTest { - private BankedSampleToCorrectedCmoSampleIdConverter bankedSampleToCorrectedCmoSampleIdConverter = new - BankedSampleToCorrectedCmoSampleIdConverter(); - - @Test - public void whenBankedSampleFieldsAreFilledIn_shouldBeWrittenInCorrectedCmoSampleView() throws Exception { - //given - String id = "id"; - String userSampleId = "userSampId"; - String cmoPatId = "cmoPatId"; - String reqId = "reqId"; - NucleicAcid naToExtract = NucleicAcid.CFDNA; - Recipe recipe = Recipe.AMPLI_SEQ; - SampleType sampleType = SampleType.RNA; - SpecimenType specimenType = SpecimenType.BLOOD; - SampleClass sampleClass = SampleClass.ADJACENT_TISSUE; - SampleOrigin sampleOrigin = SampleOrigin.PLASMA; - - BankedSample bankedSample = new BankedSample(id); - bankedSample.setUserSampleID(userSampleId); - bankedSample.setCMOPatientId(cmoPatId); - bankedSample.setRequestId(reqId); - bankedSample.setNAtoExtract(naToExtract.getValue()); - bankedSample.setRecipe(recipe.getValue()); - bankedSample.setSampleType(sampleType.toString()); - bankedSample.setSpecimenType(specimenType.getValue()); - bankedSample.setSampleClass(sampleClass.getValue()); - bankedSample.setSampleOrigin(sampleOrigin.getValue()); - - //when - CorrectedCmoSampleView correctedCmoSampleView = bankedSampleToCorrectedCmoSampleIdConverter.convert - (bankedSample); - - //then - assertThat(correctedCmoSampleView.getId(), is(userSampleId)); - assertThat(correctedCmoSampleView.getSampleId(), is(userSampleId)); - assertThat(correctedCmoSampleView.getPatientId(), is(cmoPatId)); - assertThat(correctedCmoSampleView.getRequestId(), is(reqId)); - assertThat(correctedCmoSampleView.getNucleidAcid(), is(naToExtract)); - assertThat(correctedCmoSampleView.getSampleType(), is(sampleType)); - assertThat(correctedCmoSampleView.getSpecimenType(), is(specimenType)); - assertThat(correctedCmoSampleView.getSampleClass(), is(sampleClass)); - assertThat(correctedCmoSampleView.getSampleOrigin(), is(sampleOrigin)); - } -} \ No newline at end of file diff --git a/src/test/java/org/mskcc/limsrest/service/cmoinfo/converter/FormatAwareCorrectedCmoIdConverterFactoryTest.java b/src/test/java/org/mskcc/limsrest/service/cmoinfo/converter/FormatAwareCorrectedCmoIdConverterFactoryTest.java deleted file mode 100644 index 00287bf3..00000000 --- a/src/test/java/org/mskcc/limsrest/service/cmoinfo/converter/FormatAwareCorrectedCmoIdConverterFactoryTest.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.mskcc.limsrest.service.cmoinfo.converter; - -import org.hamcrest.object.IsCompatibleType; -import org.junit.Test; -import org.mskcc.limsrest.service.cmoinfo.cspace.PatientAwareCorrectedCmoIdConverter; -import org.mskcc.limsrest.service.cmoinfo.oldformat.OldCorrectedCmoIdConverter; -import org.mskcc.limsrest.service.cmoinfo.retriever.SampleTypeAbbreviationRetriever; -import org.mskcc.util.TestUtils; - -import java.util.Optional; - -import static org.junit.Assert.assertThat; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; - -public class FormatAwareCorrectedCmoIdConverterFactoryTest { - private SampleTypeAbbreviationRetriever abbrRetriever = mock(SampleTypeAbbreviationRetriever.class); - private FormatAwareCorrectedCmoIdConverterFactory formatAwareCorrectedCmoIdConverterFactory = new - FormatAwareCorrectedCmoIdConverterFactory(abbrRetriever); - - @Test - public void whenCorrectedCmoIdIsInCspace_shouldReturnCspaceConverter() throws Exception { - assertConverterType("C-AS456H-G001-d", PatientAwareCorrectedCmoIdConverter.class); - assertConverterType("C-12345-X341-d", PatientAwareCorrectedCmoIdConverter.class); - assertConverterType("C-fjnFNJDSN-N045-r", PatientAwareCorrectedCmoIdConverter.class); - assertConverterType("C-fds324-R666-d", PatientAwareCorrectedCmoIdConverter.class); - } - - @Test - public void whenCorrectedCmoIdIsInOldFormat_shouldReturnOldFormatConverter() throws Exception { - assertConverterType("432d-gd543-gdgfd-12", OldCorrectedCmoIdConverter.class); - assertConverterType("gsg-gd543-gdgfd-a12s", OldCorrectedCmoIdConverter.class); - assertConverterType("gsg-gd543-gdgfd-A12s", OldCorrectedCmoIdConverter.class); - assertConverterType("321TG-gd543-gdgfd-as9fdfd", OldCorrectedCmoIdConverter.class); - assertConverterType("gsg-gd543-gdgfd-02", OldCorrectedCmoIdConverter.class); - } - - @Test - public void whenCorrectedCmoIdIsInNoSpecifiedFormat_shouldThrowAnException() throws Exception { - assertExceptionThrown("gsg-gd543-12"); - assertExceptionThrown("a12s"); - assertExceptionThrown("12345"); - assertExceptionThrown("gdgfd-02"); - } - - private void assertConverterType(String correctedCmoId, Class - converterClass) { - CorrectedCmoSampleViewToSampleCmoIdConverter converter = formatAwareCorrectedCmoIdConverterFactory - .getConverter(correctedCmoId); - - assertThat(converter.getClass(), IsCompatibleType.typeCompatibleWith(converterClass)); - } - - private void assertExceptionThrown(String correctedCmoId) { - Optional exception = TestUtils.assertThrown(() -> formatAwareCorrectedCmoIdConverterFactory - .getConverter(correctedCmoId)); - - assertTrue(exception.isPresent()); - assertThat(exception.get().getClass(), IsCompatibleType.typeCompatibleWith - (FormatAwareCorrectedCmoIdConverterFactory.UnsupportedCmoIdFormatException.class)); - } - -} \ No newline at end of file diff --git a/src/test/java/org/mskcc/limsrest/service/cmoinfo/cspace/CspaceSampleAbbreviationRetrieverTest.java b/src/test/java/org/mskcc/limsrest/service/cmoinfo/cspace/CspaceSampleAbbreviationRetrieverTest.java deleted file mode 100644 index fdba9edc..00000000 --- a/src/test/java/org/mskcc/limsrest/service/cmoinfo/cspace/CspaceSampleAbbreviationRetrieverTest.java +++ /dev/null @@ -1,157 +0,0 @@ -package org.mskcc.limsrest.service.cmoinfo.cspace; - -import org.junit.Test; -import org.mskcc.domain.Recipe; -import org.mskcc.domain.sample.*; -import org.mskcc.util.Constants; -import org.mskcc.util.TestUtils; - -import java.util.Optional; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; -import static org.mskcc.domain.sample.SampleOrigin.TISSUE; -import static org.mskcc.domain.sample.SpecimenType.CFDNA; - -public class CspaceSampleAbbreviationRetrieverTest { - private CspaceSampleTypeAbbreviationRetriever cspaceSampleAbbreviationRetriever = new - CspaceSampleTypeAbbreviationRetriever(); - - @Test - public void whenSampleTypeIsPooledLibrary_shouldResolveNucleicAcidByRecipe() throws Exception { - assertNucleicAcidAbbrev(SampleType.POOLED_LIBRARY, Recipe.RNA_SEQ, Constants.RNA_ABBREV); - - assertNucleicAcidAbbrev(SampleType.POOLED_LIBRARY, Recipe.WHOLE_EXOME_SEQUENCING, Constants.DNA_ABBREV); - assertNucleicAcidAbbrev(SampleType.POOLED_LIBRARY, Recipe.SMARTER_AMP_SEQ, Constants.DNA_ABBREV); - assertNucleicAcidAbbrev(SampleType.POOLED_LIBRARY, Recipe.RNA_SEQ_POLY_A, Constants.DNA_ABBREV); - assertNucleicAcidAbbrev(SampleType.POOLED_LIBRARY, Recipe.RNA_SEQ_RIBO_DEPLETE, Constants.DNA_ABBREV); - assertNucleicAcidAbbrev(SampleType.POOLED_LIBRARY, Recipe.TEN_X_Genomics_RNA, Constants.DNA_ABBREV); - assertNucleicAcidAbbrev(SampleType.POOLED_LIBRARY, Recipe.SH_RNA_SEQ, Constants.DNA_ABBREV); - } - - private void assertNucleicAcidAbbrev(SampleType sampleType, Recipe recipe, String nucleicAcidAbbrev) { - assertNucleicAcidAbbrev(sampleType, recipe, Optional.empty(), nucleicAcidAbbrev); - } - - - private void assertNucleicAcidAbbrev(SampleType sampleType, Recipe recipe, Optional nucleicAcid, - String nucleicAcidAbbrev) { - //given - CorrectedCmoSampleView correctedCmoSampleView = new CorrectedCmoSampleView("id"); - correctedCmoSampleView.setSampleType(sampleType); - correctedCmoSampleView.setRecipe(recipe); - - if (nucleicAcid.isPresent()) - correctedCmoSampleView.setNucleidAcid(nucleicAcid.get()); - - //when - String nucleicAcidAbbr = cspaceSampleAbbreviationRetriever.getNucleicAcidAbbr(correctedCmoSampleView); - - //then - assertThat(nucleicAcidAbbr, is(nucleicAcidAbbrev)); - } - - @Test - public void whenSampleTypeIsNotPooledLibraryAndRecipeIsRNASeq_shouldResolveNucleicAcidByNaToExtract() throws - Exception { - assertNucleicAcidAbbrev(SampleType.BLOCKS_SLIDES, Recipe.RNA_SEQ, Optional.of(NucleicAcid.DNA), Constants - .DNA_ABBREV); - assertNucleicAcidAbbrev(SampleType.DNA_LIBRARY, Recipe.RNA_SEQ, Optional.of(NucleicAcid.DNA), Constants - .DNA_ABBREV); - assertNucleicAcidAbbrev(SampleType.TISSUE, Recipe.RNA_SEQ, Optional.of(NucleicAcid.DNA), Constants.DNA_ABBREV); - assertNucleicAcidAbbrev(SampleType.DNA, Recipe.RNA_SEQ, Optional.of(NucleicAcid.DNA), Constants.DNA_ABBREV); - assertNucleicAcidAbbrev(SampleType.CFDNA, Recipe.RNA_SEQ, Optional.of(NucleicAcid.DNA), Constants.DNA_ABBREV); - assertNucleicAcidAbbrev(SampleType.CELLS, Recipe.RNA_SEQ, Optional.of(NucleicAcid.DNA), Constants.DNA_ABBREV); - assertNucleicAcidAbbrev(SampleType.BLOOD, Recipe.RNA_SEQ, Optional.of(NucleicAcid.DNA), Constants.DNA_ABBREV); - - assertNucleicAcidAbbrev(SampleType.BLOOD, Recipe.RNA_SEQ, Optional.of(NucleicAcid.RNA), Constants.RNA_ABBREV); - assertNucleicAcidAbbrev(SampleType.BUFFY_COAT, Recipe.RNA_SEQ, Optional.of(NucleicAcid.RNA), Constants - .RNA_ABBREV); - assertNucleicAcidAbbrev(SampleType.BLOCKS_SLIDES, Recipe.RNA_SEQ, Optional.of(NucleicAcid.RNA), Constants - .RNA_ABBREV); - } - - @Test - public void whenPropertiesAreCorrectlySet_shouldReturnSampleTypeAbbrev() throws Exception { - assertSampleTypeAbbrev(SpecimenType.XENOGRAFT, "X"); - assertSampleTypeAbbrev(SpecimenType.XENOGRAFTDERIVEDCELLLINE, "X"); - assertSampleTypeAbbrev(SpecimenType.PDX, "X"); - assertSampleTypeAbbrev(SpecimenType.PDX, SampleOrigin.TISSUE, "X"); - assertSampleTypeAbbrev(SpecimenType.PDX, SampleOrigin.CEREBROSPINAL_FLUID, SampleClass.METASTASIS, "X"); - - assertSampleTypeAbbrev(SpecimenType.ORGANOID, "G"); - assertSampleTypeAbbrev(SpecimenType.ORGANOID, SampleOrigin.WHOLE_BLOOD, "G"); - assertSampleTypeAbbrev(SpecimenType.ORGANOID, SampleOrigin.PLASMA, "G"); - assertSampleTypeAbbrev(SpecimenType.ORGANOID, SampleOrigin.WHOLE_BLOOD, SampleClass.LOCAL_RECURRENCE, "G"); - assertSampleTypeAbbrev(SpecimenType.ORGANOID, SampleOrigin.WHOLE_BLOOD, SampleClass.ADJACENT_TISSUE, "G"); - - assertSampleTypeAbbrev(SpecimenType.CFDNA, SampleOrigin.URINE, "U"); - assertSampleTypeAbbrev(SpecimenType.CFDNA, SampleOrigin.URINE, SampleClass.CELL_FREE, "U"); - assertSampleTypeAbbrev(SpecimenType.CFDNA, SampleOrigin.CEREBROSPINAL_FLUID, "S"); - assertSampleTypeAbbrev(SpecimenType.CFDNA, SampleOrigin.CEREBROSPINAL_FLUID, SampleClass.PRIMARY, "S"); - assertSampleTypeAbbrev(SpecimenType.CFDNA, SampleOrigin.PLASMA, "L"); - assertSampleTypeAbbrev(SpecimenType.CFDNA, SampleOrigin.PLASMA, SampleClass.LOCAL_RECURRENCE, "L"); - assertSampleTypeAbbrev(SpecimenType.CFDNA, SampleOrigin.WHOLE_BLOOD, "L"); - assertSampleTypeAbbrev(SpecimenType.CFDNA, SampleOrigin.WHOLE_BLOOD, SampleClass.ADJACENT_TISSUE, "L"); - - assertSampleTypeAbbrev(SpecimenType.RAPIDAUTOPSY, SampleOrigin.WHOLE_BLOOD, SampleClass.UNKNOWN_TUMOR, "T"); - assertSampleTypeAbbrev(SpecimenType.BLOOD, SampleOrigin.WHOLE_BLOOD, SampleClass.LOCAL_RECURRENCE, "R"); - assertSampleTypeAbbrev(SpecimenType.SALIVA, SampleOrigin.WHOLE_BLOOD, SampleClass.PRIMARY, "P"); - assertSampleTypeAbbrev(SpecimenType.RESECTION, SampleOrigin.WHOLE_BLOOD, SampleClass.RECURRENCE, "R"); - assertSampleTypeAbbrev(SpecimenType.FINGERNAILS, SampleOrigin.WHOLE_BLOOD, SampleClass.METASTASIS, "M"); - assertSampleTypeAbbrev(SpecimenType.BLOOD, SampleOrigin.WHOLE_BLOOD, SampleClass.NORMAL, "N"); - assertSampleTypeAbbrev(SpecimenType.BIOPSY, SampleOrigin.WHOLE_BLOOD, SampleClass.ADJACENT_NORMAL, "N"); - assertSampleTypeAbbrev(SpecimenType.BLOOD, SampleOrigin.WHOLE_BLOOD, SampleClass.ADJACENT_TISSUE, "T"); - } - - @Test - public void whenSampleisCellFree_shouldThrowAnException() throws Exception { - Optional exception = TestUtils.assertThrown(() -> assertSampleTypeAbbrev(SpecimenType.RAPIDAUTOPSY, - SampleOrigin.URINE, SampleClass.CELL_FREE, "U")); - - assertThat(exception.isPresent(), is(true)); - } - - private void assertSampleTypeAbbrev(SpecimenType specimenType, SampleOrigin sampleOrigin, SampleClass sampleClass, - String expected) { - - assertSampleTypeAbbrev(specimenType, Optional.of(sampleOrigin), Optional.of(sampleClass), expected); - } - - private void assertSampleTypeAbbrev(SpecimenType specimenType, SampleOrigin sampleOrigin, String expected) { - assertSampleTypeAbbrev(specimenType, Optional.of(sampleOrigin), Optional.empty(), expected); - } - - private void assertSampleTypeAbbrev(SpecimenType specimenType, String expected) { - assertSampleTypeAbbrev(specimenType, Optional.empty(), Optional.empty(), expected); - } - - private void assertSampleTypeAbbrev(SpecimenType specimenType, Optional sampleOrigin, - Optional sampleClass, String abbrev) { - CorrectedCmoSampleView correctedCmoSampleView = new CorrectedCmoSampleView("s"); - - sampleClass.ifPresent((sampleClass1) -> correctedCmoSampleView.setSampleClass(sampleClass1)); - sampleOrigin.ifPresent((sampleOrigin1) -> correctedCmoSampleView.setSampleOrigin(sampleOrigin1)); - correctedCmoSampleView.setSpecimenType(specimenType); - - String typeAbbrev = cspaceSampleAbbreviationRetriever.getSampleTypeAbbr(correctedCmoSampleView); - - assertThat(typeAbbrev, is(abbrev)); - } - - @Test - public void whenSpeciemnIsCfdnaAndOriginIsTissueAndClassIsCellFree_shouldThrowAnException() throws Exception { - CorrectedCmoSampleView view = new CorrectedCmoSampleView("sampleId"); - String patientId = "12345"; - view.setPatientId(patientId); - view.setSpecimenType(CFDNA); - view.setSampleOrigin(TISSUE); - view.setSampleClass(SampleClass.CELL_FREE); - view.setNucleidAcid(NucleicAcid.DNA); - - Optional exception = TestUtils.assertThrown(() -> cspaceSampleAbbreviationRetriever - .getSampleTypeAbbr(view)); - - assertThat(exception.isPresent(), is(true)); - } -} \ No newline at end of file diff --git a/src/test/java/org/mskcc/limsrest/service/cmoinfo/cspace/PatientAwareCorrectedCmoIdConverterTest.java b/src/test/java/org/mskcc/limsrest/service/cmoinfo/cspace/PatientAwareCorrectedCmoIdConverterTest.java deleted file mode 100644 index cd4cebd5..00000000 --- a/src/test/java/org/mskcc/limsrest/service/cmoinfo/cspace/PatientAwareCorrectedCmoIdConverterTest.java +++ /dev/null @@ -1,84 +0,0 @@ -package org.mskcc.limsrest.service.cmoinfo.cspace; - -import org.hamcrest.object.IsCompatibleType; -import org.junit.Test; -import org.mskcc.domain.sample.CorrectedCmoSampleView; -import org.mskcc.util.TestUtils; - -import java.util.Optional; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - -public class PatientAwareCorrectedCmoIdConverterTest { - private PatientAwareCorrectedCmoIdConverter patientAwareCorrectedCmoIdConverter = new - PatientAwareCorrectedCmoIdConverter(); - - @Test - public void whenCmoIdStringIsEmpty_shouldThrowAnException() throws Exception { - CorrectedCmoSampleView sample = getSample("sampleId"); - Optional exception = TestUtils.assertThrown(() -> { - patientAwareCorrectedCmoIdConverter.convert(sample); - }); - - assertThat(exception.isPresent(), is(true)); - assertThat(exception.get().getClass(), IsCompatibleType.typeCompatibleWith(IllegalArgumentException.class)); - } - - @Test - public void whenCmoIdStringIsNotCorrect_shouldThrowAnException() throws Exception { - assertExceptionThrown("D-12345-N001-d"); - assertExceptionThrown("-12345-N001-d"); - - assertExceptionThrown("C-N001-d"); - assertExceptionThrown("C-12345-d"); - assertExceptionThrown("C-12345-N001"); - - assertExceptionThrown("C12345-N001-d"); - assertExceptionThrown("C12345N001d"); - - assertExceptionThrown("C_12345-N001-d"); - assertExceptionThrown("C-12345_N001-d"); - assertExceptionThrown("C-12345-N001_d"); - assertExceptionThrown("C_12345_N001_d"); - - assertExceptionThrown("C-12345-001-d"); - assertExceptionThrown("C-12345-N-d"); - assertExceptionThrown("C-12345-N2-d"); - assertExceptionThrown("C-12345-N34-d"); - assertExceptionThrown("C-12345-1134-d"); - - assertExceptionThrown("C-12345-N034-w"); - assertExceptionThrown("C-12345-N034-e"); - assertExceptionThrown("C-12345-N034-d1"); - assertExceptionThrown("C-12345-N034-r1"); - assertExceptionThrown("C-12345-N034-r2"); - } - - private void assertExceptionThrown(String incorrectCmoId) { - Optional exception = TestUtils.assertThrown(() -> { - CorrectedCmoSampleView sample = getSample(incorrectCmoId); - patientAwareCorrectedCmoIdConverter.convert(sample); - }); - - assertThat(exception.isPresent(), is(true)); - assertThat(exception.get().getClass(), IsCompatibleType.typeCompatibleWith(IllegalArgumentException.class)); - } - - private CorrectedCmoSampleView getSample(String incorrectCmoId) { - CorrectedCmoSampleView sample = new CorrectedCmoSampleView("sampleId"); - sample.setCorrectedCmoId(incorrectCmoId); - return sample; - } - - @Test - public void whenCmoIdStringDoesntStartWithPrefix_shouldThrowAnException() throws Exception { - Optional exception = TestUtils.assertThrown(() -> patientAwareCorrectedCmoIdConverter.convert - (getSample - ("D-12345-X001-d1"))); - - assertThat(exception.isPresent(), is(true)); - assertThat(exception.get().getClass(), IsCompatibleType.typeCompatibleWith(IllegalArgumentException.class)); - } - -} \ No newline at end of file diff --git a/src/test/java/org/mskcc/limsrest/service/cmoinfo/oldformat/OldCorrectedCmoIdConverterTest.java b/src/test/java/org/mskcc/limsrest/service/cmoinfo/oldformat/OldCorrectedCmoIdConverterTest.java deleted file mode 100644 index 43dd45ba..00000000 --- a/src/test/java/org/mskcc/limsrest/service/cmoinfo/oldformat/OldCorrectedCmoIdConverterTest.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.mskcc.limsrest.service.cmoinfo.oldformat; - -import org.junit.Test; -import org.mskcc.domain.sample.CorrectedCmoSampleView; -import org.mskcc.domain.sample.NucleicAcid; -import org.mskcc.domain.sample.SpecimenType; -import org.mskcc.limsrest.service.cmoinfo.cspace.CspaceSampleTypeAbbreviationRetriever; -import org.mskcc.limsrest.service.cmoinfo.cspace.SpecimenTypeSampleAbbreviationResolver; -import org.mskcc.limsrest.service.cmoinfo.patientsample.PatientAwareCmoSampleId; -import org.mskcc.limsrest.service.cmoinfo.retriever.SampleTypeAbbreviationRetriever; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -public class OldCorrectedCmoIdConverterTest { - private SampleTypeAbbreviationRetriever sampleTypeAbbreviationRetriever = new - CspaceSampleTypeAbbreviationRetriever(); - private final OldCorrectedCmoIdConverter oldCorrectedCmoIdConverter = new OldCorrectedCmoIdConverter - (sampleTypeAbbreviationRetriever); - - @Test - public void whenCountIsAtTheEndOfId_shouldReturnCorrectedCmoIdWithThisCount() throws Exception { - //given - String patientId = "34324_P"; - NucleicAcid nucleidAcid = NucleicAcid.DNA; - String count = "1"; - String correctedCmoId = "123d-fds32-gf43-" + count; - SpecimenType specimenType = SpecimenType.PDX; - - assertPatientCmoSampleId(patientId, nucleidAcid, Integer.parseInt(count), correctedCmoId, specimenType); - } - - @Test - public void whenCountIsSurroundedByOtherChars_shouldReturnCorrectedCmoIdWithThisCount() throws Exception { - //given - String patientId = "098439NJNJ"; - NucleicAcid nucleidAcid = NucleicAcid.RNA; - String count = "012"; - String correctedCmoId = "123d-fds32-gf43-wq" + count + "ds"; - SpecimenType specimenType = SpecimenType.XENOGRAFT; - - assertPatientCmoSampleId(patientId, nucleidAcid, Integer.parseInt(count), correctedCmoId, specimenType); - } - - private void assertPatientCmoSampleId(String patientId, NucleicAcid nucleidAcid, int count, String - correctedCmoId, SpecimenType specimenType) { - CorrectedCmoSampleView sample = new CorrectedCmoSampleView("1234"); - sample.setPatientId(patientId); - sample.setNucleidAcid(nucleidAcid); - sample.setSpecimenType(specimenType); - sample.setCorrectedCmoId(correctedCmoId); - - //when - PatientAwareCmoSampleId patientAwareCmoSampleId = oldCorrectedCmoIdConverter.convert(sample); - - //then - assertThat(patientAwareCmoSampleId.getNucleicAcid(), is(sampleTypeAbbreviationRetriever.getNucleicAcidAbbr - (sample))); - assertThat(patientAwareCmoSampleId.getPatientId(), is(sample.getPatientId())); - assertThat(patientAwareCmoSampleId.getSampleCount(), is(count)); - assertThat(patientAwareCmoSampleId.getSampleTypeAbbr(), is(SpecimenTypeSampleAbbreviationResolver - .getSpecimenTypeToAbbreviation().get(specimenType))); - } - -} \ No newline at end of file diff --git a/src/test/java/org/mskcc/limsrest/service/cmoinfo/retriever/CellLineCmoSampleIdResolverTest.java b/src/test/java/org/mskcc/limsrest/service/cmoinfo/retriever/CellLineCmoSampleIdResolverTest.java deleted file mode 100644 index e17a8c94..00000000 --- a/src/test/java/org/mskcc/limsrest/service/cmoinfo/retriever/CellLineCmoSampleIdResolverTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.mskcc.limsrest.service.cmoinfo.retriever; - -import org.junit.Before; -import org.junit.Test; -import org.mskcc.domain.sample.CorrectedCmoSampleView; -import org.mskcc.domain.sample.BankedSample; -import org.mskcc.limsrest.service.cmoinfo.cellline.CellLineCmoSampleId; -import org.mskcc.limsrest.service.cmoinfo.cellline.CellLineCmoSampleIdResolver; - -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; - - -public class CellLineCmoSampleIdResolverTest { - private CellLineCmoSampleIdResolver cellLineCmoSampleIdResolver = new CellLineCmoSampleIdResolver(); - private CorrectedCmoSampleView sample; - - @Before - public void setUp() throws Exception { - Map fields = new HashMap<>(); - fields.put(BankedSample.RECORD_ID, 3434l); - } - - @Test - public void whenUserSampleIdIsNotEmpty_shouldReturnCellLineCmoIdWithRequestIdProvided() throws Exception { - assertCellLineSampleId("gun48o5", "65432_P", "65432P"); - assertCellLineSampleId("1234_P_1", "65432_P", "65432P"); - assertCellLineSampleId("1234_P_1", "65432", "65432"); - assertCellLineSampleId("1234_P_1", "1234_P_A", "1234PA"); - } - - private void assertCellLineSampleId(String sampleId, String requestId, String expectedRequestId) { - String bankedSampleRequestId = "fewf3322"; - - sample = new CorrectedCmoSampleView(sampleId); - sample.setRequestId(bankedSampleRequestId); - sample.setSampleId(sampleId); - - CellLineCmoSampleId cmoSampleId = cellLineCmoSampleIdResolver.resolve(sample, Collections.emptyList(), - requestId); - - assertThat(cmoSampleId.getSampleId(), is(sampleId)); - assertThat(cmoSampleId.getRequestId(), is(expectedRequestId)); - } -} \ No newline at end of file diff --git a/src/test/java/org/mskcc/limsrest/service/cmoinfo/retriever/FormattedCmoSampleIdRetrieverTest.java b/src/test/java/org/mskcc/limsrest/service/cmoinfo/retriever/FormattedCmoSampleIdRetrieverTest.java deleted file mode 100644 index 695aa12d..00000000 --- a/src/test/java/org/mskcc/limsrest/service/cmoinfo/retriever/FormattedCmoSampleIdRetrieverTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package org.mskcc.limsrest.service.cmoinfo.retriever; - -import org.junit.Before; -import org.junit.Test; -import org.mskcc.domain.sample.CorrectedCmoSampleView; -import org.mskcc.limsrest.service.cmoinfo.cellline.CellLineCmoSampleId; -import org.mskcc.limsrest.service.cmoinfo.formatter.CmoSampleIdFormatter; - -import java.util.ArrayList; -import java.util.List; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class FormattedCmoSampleIdRetrieverTest { - private FormattedCmoSampleIdRetriever formattedCmoSampleIdRetriever; - private CmoSampleIdResolver resolver; - private CmoSampleIdFormatter formatter; - - @Before - public void setUp() throws Exception { - resolver = mock(CmoSampleIdResolver.class); - formatter = mock(CmoSampleIdFormatter.class); - - formattedCmoSampleIdRetriever = new FormattedCmoSampleIdRetriever(resolver, formatter); - } - - @Test - public void whenRetrieverIsInvoked_shouldReturnCmoSampleId() throws Exception { - //given - CorrectedCmoSampleView sample = new CorrectedCmoSampleView("sampleId"); - List patientSamples = new ArrayList<>(); - - CellLineCmoSampleId cmoSampleId = new CellLineCmoSampleId("dds", "ffefe"); - when(resolver.resolve(any(), any(), any())).thenReturn(cmoSampleId); - - String cmoSampleIdString = "bdjewbdewi"; - when(formatter.format(cmoSampleId)).thenReturn(cmoSampleIdString); - - //when - String cmoId = formattedCmoSampleIdRetriever.retrieve(sample, patientSamples, "12345"); - - //then - assertThat(cmoId, is(cmoSampleIdString)); - } -} \ No newline at end of file diff --git a/src/test/java/org/mskcc/limsrest/util/StatusTrackerConfigTest.java b/src/test/java/org/mskcc/limsrest/util/StatusTrackerConfigTest.java index e9cc6676..434a1d5c 100644 --- a/src/test/java/org/mskcc/limsrest/util/StatusTrackerConfigTest.java +++ b/src/test/java/org/mskcc/limsrest/util/StatusTrackerConfigTest.java @@ -23,7 +23,7 @@ public class StatusTrackerConfigTest { @Before public void setup() { - this.conn = new ConnectionLIMS("igo-lims03.mskcc.org", 1088, "fe74d8e1-c94b-4002-a04c-eb5c492704ba", "test-runner", "password1"); + this.conn = new ConnectionLIMS("igo-lims04.mskcc.org", 1088, "fe74d8e1-c94b-4002-a04c-eb5c492704ba", "test-runner", "password1"); } @After diff --git a/src/test/java/org/mskcc/limsrest/util/UtilsTest.java b/src/test/java/org/mskcc/limsrest/util/UtilsTest.java index dbde46f5..4a10a226 100644 --- a/src/test/java/org/mskcc/limsrest/util/UtilsTest.java +++ b/src/test/java/org/mskcc/limsrest/util/UtilsTest.java @@ -10,7 +10,8 @@ public class UtilsTest { @Test public void getOncotreeTumorType(){ assertEquals("Thyroid Cancer", Utils.getOncotreeTumorType("THAP")); - assertEquals("Breast Cancer, NOS", Utils.getOncotreeTumorType("Breast")); + String onco = Utils.getOncotreeTumorType("Breast"); + assertEquals("Breast Cancer", onco); } @Test From 87ec70e170d8c1f4a84643aaf154de66795a8157 Mon Sep 17 00:00:00 2001 From: David McManamon Date: Mon, 23 May 2022 08:16:59 -0400 Subject: [PATCH 2/5] updated Airflow exec date format --- .../IgoNewRequestMetaDbPublisher.java | 27 ++++++++++++------- .../IgoNewRequestMetaDbPublisherTest.java | 5 ++-- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisher.java b/src/main/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisher.java index dbf82fea..8a4fef12 100644 --- a/src/main/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisher.java +++ b/src/main/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisher.java @@ -103,16 +103,11 @@ private void callAirflowDeliverPipeline(String requestId) { String pi = GetRequestPermissionsTask.labHeadEmailToLabName(piEmail); String recipe = requestDataRecord.getStringVal("RequestName", user); - //2021-01-01T15:00:00Z - airflow format - DateFormat airflowFormat = new SimpleDateFormat( "yyyy-MM-ddTHH:mm:ssZ"); - String exec_date = airflowFormat.format(new Date(System.currentTimeMillis() + 10000)); - // create json body like: - // {"execution_date": "2022-05-19", "conf": {"project":"13097","pi":"abdelwao","recipe":"RNASeq-TruSeqPolyA"}} - String conf = "\"conf\":{\"project\":\""+requestId+"\",\"pi\":\""+pi+"\",\"recipe\":\""+recipe+"\"}"; - String body ="{\"execution_date\":\""+exec_date+"\",\""+conf+"}"; - + Date execDate = new Date(System.currentTimeMillis() + 10000); + String body = formatDeliverPipelineJSON(requestId, pi, recipe, execDate); log.info("Calling airflow pipeline with json body: " + body); String cmd = "curl -X POST -d '" + body + "' 'http://igo-ln01:8080/api/v1/dags/deliver_pipeline/dagRuns' -H 'content-type: application/json' --user \"airflow-api:"+airflow_pass+"\""; + Runtime.getRuntime().exec(cmd); } catch (IoError | NotFound | IOException ex) { log.error(ex); @@ -120,6 +115,18 @@ private void callAirflowDeliverPipeline(String requestId) { } } + protected static String formatDeliverPipelineJSON(String requestId, String pi, String recipe, Date execDate) { + //2021-01-01T15:00:00Z - airflow format + DateFormat airflowFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ssZ"); + String dateStr = airflowFormat.format(execDate); + dateStr = dateStr.replace(' ', 'T'); + // create json body like: + // {"execution_date": "2022-05-19", "conf": {"project":"13097","pi":"abdelwao","recipe":"RNASeq-TruSeqPolyA"}} + String conf = "\"conf\":{\"project\":\""+requestId+"\",\"pi\":\""+pi+"\",\"recipe\":\""+recipe+"\"}"; + String body ="{\"execution_date\":\""+dateStr+"\","+conf+"}"; + return body; + } + /** * Returns request metadata given a request id. * @param requestId @@ -143,7 +150,7 @@ private RequestSampleList getRequestSampleListDetails(String requestId) { /** * Returns list of sample manifest instances given a request id. - * @param requestId + * @param sl * @return */ private List> getSampleManifestListByRequestId(RequestSampleList sl) { @@ -185,7 +192,7 @@ private List> getSampleManifestListByRequestId(RequestSample /** * Packages message for CMO MetaDB and publishes to MetaDB NATS server. * @param projectId - * @param requestId + * @param requestDetails * @param sampleManifestList */ private void publishIgoNewRequestToMetaDb(String projectId, RequestSampleList requestDetails, List> sampleManifestList) { diff --git a/src/test/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisherTest.java b/src/test/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisherTest.java index 96a54bc8..57b46627 100644 --- a/src/test/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisherTest.java +++ b/src/test/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisherTest.java @@ -9,8 +9,9 @@ class IgoNewRequestMetaDbPublisherTest { @Test - static void formatDeliverPipelineJSON() { + void formatDeliverPipelineJSON() { Date now = new Date(); - IgoNewRequestMetaDbPublisher.formatDeliverPipelineJSON("12345","Curie","WGS", now); + String result = IgoNewRequestMetaDbPublisher.formatDeliverPipelineJSON("12345","Curie","WGS", now); + System.out.println(result); } } \ No newline at end of file From 980904ed0345780badad2dde2549ad07c5677938 Mon Sep 17 00:00:00 2001 From: David McManamon Date: Mon, 23 May 2022 09:25:02 -0400 Subject: [PATCH 3/5] set Airflow timestamp UTC timezone --- .../limsrest/controller/IgoNewRequestMetaDbPublisher.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisher.java b/src/main/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisher.java index 8a4fef12..bef13ddf 100644 --- a/src/main/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisher.java +++ b/src/main/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisher.java @@ -117,9 +117,10 @@ private void callAirflowDeliverPipeline(String requestId) { protected static String formatDeliverPipelineJSON(String requestId, String pi, String recipe, Date execDate) { //2021-01-01T15:00:00Z - airflow format - DateFormat airflowFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ssZ"); + DateFormat airflowFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); + airflowFormat.setTimeZone(TimeZone.getTimeZone("UTC")); String dateStr = airflowFormat.format(execDate); - dateStr = dateStr.replace(' ', 'T'); + dateStr = dateStr.replace(' ', 'T') + "Z"; // create json body like: // {"execution_date": "2022-05-19", "conf": {"project":"13097","pi":"abdelwao","recipe":"RNASeq-TruSeqPolyA"}} String conf = "\"conf\":{\"project\":\""+requestId+"\",\"pi\":\""+pi+"\",\"recipe\":\""+recipe+"\"}"; From 2f00967a5b17fa5ca30df7921acaf253eda36666 Mon Sep 17 00:00:00 2001 From: David McManamon Date: Mon, 23 May 2022 10:42:38 -0400 Subject: [PATCH 4/5] capture error stream from exec --- .../IgoNewRequestMetaDbPublisher.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisher.java b/src/main/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisher.java index bef13ddf..bbb50752 100644 --- a/src/main/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisher.java +++ b/src/main/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisher.java @@ -2,7 +2,9 @@ import com.google.gson.Gson; +import java.io.BufferedReader; import java.io.IOException; +import java.io.InputStreamReader; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.*; @@ -106,15 +108,26 @@ private void callAirflowDeliverPipeline(String requestId) { Date execDate = new Date(System.currentTimeMillis() + 10000); String body = formatDeliverPipelineJSON(requestId, pi, recipe, execDate); log.info("Calling airflow pipeline with json body: " + body); - String cmd = "curl -X POST -d '" + body + "' 'http://igo-ln01:8080/api/v1/dags/deliver_pipeline/dagRuns' -H 'content-type: application/json' --user \"airflow-api:"+airflow_pass+"\""; - - Runtime.getRuntime().exec(cmd); + String cmd = "/bin/curl -X POST -d '" + body + "' \"http://igo-ln01:8080/api/v1/dags/deliver_pipeline/dagRuns\" -H \"content-type:application/json\" --user \"airflow-api:"+airflow_pass+"\""; + System.out.println("CMD:" + cmd); + Process process = Runtime.getRuntime().exec(cmd); + logResults(process, log); } catch (IoError | NotFound | IOException ex) { log.error(ex); ex.printStackTrace(); } } + public static void logResults(Process process, Log log) throws IOException { + BufferedReader reader = new BufferedReader(new InputStreamReader(process.getErrorStream())); + String line = ""; + log.info("Airflow exec pipeline error results:"); + while ((line = reader.readLine()) != null) { + log.info(line); + } + reader.close(); + } + protected static String formatDeliverPipelineJSON(String requestId, String pi, String recipe, Date execDate) { //2021-01-01T15:00:00Z - airflow format DateFormat airflowFormat = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss"); From 63ffc78aabf016b38ef4e1f4f6c8ec510b513faa Mon Sep 17 00:00:00 2001 From: David McManamon Date: Mon, 23 May 2022 11:15:39 -0400 Subject: [PATCH 5/5] Changed to ProcessBuilder for exec --- .../limsrest/controller/IgoNewRequestMetaDbPublisher.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisher.java b/src/main/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisher.java index bbb50752..4821c54e 100644 --- a/src/main/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisher.java +++ b/src/main/java/org/mskcc/limsrest/controller/IgoNewRequestMetaDbPublisher.java @@ -3,6 +3,7 @@ import com.google.gson.Gson; import java.io.BufferedReader; +import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.text.DateFormat; @@ -108,9 +109,11 @@ private void callAirflowDeliverPipeline(String requestId) { Date execDate = new Date(System.currentTimeMillis() + 10000); String body = formatDeliverPipelineJSON(requestId, pi, recipe, execDate); log.info("Calling airflow pipeline with json body: " + body); - String cmd = "/bin/curl -X POST -d '" + body + "' \"http://igo-ln01:8080/api/v1/dags/deliver_pipeline/dagRuns\" -H \"content-type:application/json\" --user \"airflow-api:"+airflow_pass+"\""; + String cmd = "curl -X POST -d '" + body + "' \"http://igo-ln01:8080/api/v1/dags/deliver_pipeline/dagRuns\" -H \"content-type:application/json\" --user \"airflow-api:"+airflow_pass+"\""; System.out.println("CMD:" + cmd); - Process process = Runtime.getRuntime().exec(cmd); + // instead of separating each command argument for processBuilder just use "sh" + ProcessBuilder builder = new ProcessBuilder("sh", "-c", cmd); + Process process = builder.start(); logResults(process, log); } catch (IoError | NotFound | IOException ex) { log.error(ex);