Fix broken ITs.

Add error message for non-snapshot upload with current version = false combination.
This commit is contained in:
juan.marchionatto 2021-08-03 14:11:14 -04:00
parent 1ff1954cba
commit 45549d2bb9
4 changed files with 47 additions and 7 deletions

View File

@ -5,6 +5,7 @@ import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion;
import ca.uhn.fhir.jpa.entity.TermConcept; import ca.uhn.fhir.jpa.entity.TermConcept;
import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink; import ca.uhn.fhir.jpa.entity.TermConceptParentChildLink;
import ca.uhn.fhir.jpa.entity.TermConceptProperty; import ca.uhn.fhir.jpa.entity.TermConceptProperty;
import ca.uhn.fhir.jpa.model.util.JpaConstants;
import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc; import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc;
import ca.uhn.fhir.jpa.term.api.ITermDeferredStorageSvc; import ca.uhn.fhir.jpa.term.api.ITermDeferredStorageSvc;
import ca.uhn.fhir.jpa.term.api.ITermLoaderSvc; import ca.uhn.fhir.jpa.term.api.ITermLoaderSvc;
@ -228,13 +229,15 @@ public class TermLoaderSvcImpl implements ITermLoaderSvc {
if (StringUtils.isBlank(codeSystemVersionId) && ! isMakeCurrentVersion) { if (StringUtils.isBlank(codeSystemVersionId) && ! isMakeCurrentVersion) {
throw new InvalidRequestException("'" + LOINC_CODESYSTEM_VERSION.getCode() + throw new InvalidRequestException("'" + LOINC_CODESYSTEM_VERSION.getCode() +
"' property is required when 'current-version' property is 'false'"); "' property is required when '" + LOINC_CODESYSTEM_MAKE_CURRENT.getCode() + "' property is 'false'");
} }
//todo: is this the case?. Check with client if (! isMakeCurrentVersion
// if (! isMakeCurrentVersion && mode != ModeEnum.SNAPSHOT) { && theRequestDetails.getOperation() != null
// throw new ParseException("Delta operations must use (or default to) " + CURRENT_VERSION + "=true parameter"); && ! theRequestDetails.getOperation().equals(JpaConstants.OPERATION_UPLOAD_EXTERNAL_CODE_SYSTEM)) {
// } throw new InvalidRequestException("Delta operations require '" + LOINC_CODESYSTEM_MAKE_CURRENT.getCode() +
"' parameter set (or defaulted to) 'true'");
}
List<String> mandatoryFilenameFragments = Arrays.asList( List<String> mandatoryFilenameFragments = Arrays.asList(
uploadProperties.getProperty(LOINC_ANSWERLIST_FILE.getCode(), LOINC_ANSWERLIST_FILE_DEFAULT.getCode()), uploadProperties.getProperty(LOINC_ANSWERLIST_FILE.getCode(), LOINC_ANSWERLIST_FILE_DEFAULT.getCode()),

View File

@ -29,6 +29,7 @@ import org.hl7.fhir.r4.model.ValueSet;
import org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent; import org.hl7.fhir.r4.model.ValueSet.ConceptReferenceComponent;
import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers; import org.mockito.Answers;
@ -42,8 +43,10 @@ import org.springframework.transaction.PlatformTransactionManager;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc.MAKE_LOADING_VERSION_CURRENT;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.mockito.Mockito.when;
@ExtendWith(SpringExtension.class) @ExtendWith(SpringExtension.class)
@RequiresDocker @RequiresDocker
@ -83,6 +86,13 @@ public class FhirResourceDaoR4TerminologyElasticsearchIT extends BaseJpaTest {
@Autowired @Autowired
private IBulkDataExportSvc myBulkDataExportSvc; private IBulkDataExportSvc myBulkDataExportSvc;
@BeforeEach
public void beforeEach() {
when(mySrd.getUserData().getOrDefault(MAKE_LOADING_VERSION_CURRENT, Boolean.TRUE)).thenReturn(Boolean.TRUE);
}
@Test @Test
public void testExpandWithIncludeContainingDashesInInclude() { public void testExpandWithIncludeContainingDashesInInclude() {
CodeSystem codeSystem = new CodeSystem(); CodeSystem codeSystem = new CodeSystem();

View File

@ -6,6 +6,7 @@ import ca.uhn.fhir.jpa.entity.TermCodeSystemVersion;
import ca.uhn.fhir.jpa.entity.TermConcept; import ca.uhn.fhir.jpa.entity.TermConcept;
import ca.uhn.fhir.jpa.entity.TermConceptDesignation; import ca.uhn.fhir.jpa.entity.TermConceptDesignation;
import ca.uhn.fhir.jpa.entity.TermConceptProperty; import ca.uhn.fhir.jpa.entity.TermConceptProperty;
import ca.uhn.fhir.jpa.model.util.JpaConstants;
import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc; import ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc;
import ca.uhn.fhir.jpa.term.api.ITermDeferredStorageSvc; import ca.uhn.fhir.jpa.term.api.ITermDeferredStorageSvc;
import ca.uhn.fhir.jpa.term.api.ITermLoaderSvc; import ca.uhn.fhir.jpa.term.api.ITermLoaderSvc;
@ -85,6 +86,7 @@ import static org.mockito.Mockito.reset;
import static org.mockito.Mockito.spy; import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times; import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
public class TerminologyLoaderSvcLoincTest extends BaseLoaderTest { public class TerminologyLoaderSvcLoincTest extends BaseLoaderTest {
private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TerminologyLoaderSvcLoincTest.class); private static final org.slf4j.Logger ourLog = org.slf4j.LoggerFactory.getLogger(TerminologyLoaderSvcLoincTest.class);
@ -856,6 +858,7 @@ public class TerminologyLoaderSvcLoincTest extends BaseLoaderTest {
void beforeEach() { void beforeEach() {
testedSvc = spy(mySvc); testedSvc = spy(mySvc);
doReturn(testProps).when(testedSvc).getProperties(any(), eq(LOINC_UPLOAD_PROPERTIES_FILE.getCode())); doReturn(testProps).when(testedSvc).getProperties(any(), eq(LOINC_UPLOAD_PROPERTIES_FILE.getCode()));
requestDetails.setOperation(JpaConstants.OPERATION_UPLOAD_EXTERNAL_CODE_SYSTEM);
} }
@ -932,10 +935,25 @@ public class TerminologyLoaderSvcLoincTest extends BaseLoaderTest {
InvalidRequestException thrown = Assertions.assertThrows(InvalidRequestException.class, InvalidRequestException thrown = Assertions.assertThrows(InvalidRequestException.class,
() -> testedSvc.loadLoinc(mockFileDescriptorList, mySrd) ); () -> testedSvc.loadLoinc(mockFileDescriptorList, mySrd) );
assertEquals("'" + LOINC_CODESYSTEM_VERSION.getCode() + assertEquals("'" + LOINC_CODESYSTEM_VERSION.getCode() + "' property is required when '" +
"' property is required when 'current-version' property is 'false'", thrown.getMessage()); LOINC_CODESYSTEM_MAKE_CURRENT.getCode() + "' property is 'false'", thrown.getMessage());
} }
@Test
public void testNoSnapshotAndNoMakeCurrentThrows() {
testProps.put(LOINC_CODESYSTEM_MAKE_CURRENT.getCode(), "false");
testProps.put(LOINC_CODESYSTEM_VERSION.getCode(), "27.0");
when(mySrd.getOperation()).thenReturn(JpaConstants.OPERATION_APPLY_CODESYSTEM_DELTA_ADD);
doReturn(mockFileDescriptors).when(testedSvc).getLoadedFileDescriptors(mockFileDescriptorList);
InvalidRequestException thrown = Assertions.assertThrows(InvalidRequestException.class,
() -> testedSvc.loadLoinc(mockFileDescriptorList, mySrd) );
assertEquals("Delta operations require '" + LOINC_CODESYSTEM_MAKE_CURRENT.getCode() +
"' parameter set (or defaulted to) 'true'", thrown.getMessage());
}
} }

View File

@ -30,6 +30,7 @@ import org.hl7.fhir.r4.model.CodeableConcept;
import org.hl7.fhir.r4.model.Coding; import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.ValueSet; import org.hl7.fhir.r4.model.ValueSet;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers; import org.mockito.Answers;
@ -40,6 +41,7 @@ import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.transaction.PlatformTransactionManager; import org.springframework.transaction.PlatformTransactionManager;
import static ca.uhn.fhir.jpa.term.api.ITermCodeSystemStorageSvc.MAKE_LOADING_VERSION_CURRENT;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.anyCollection; import static org.mockito.ArgumentMatchers.anyCollection;
@ -90,6 +92,13 @@ public class ValueSetExpansionR4ElasticsearchIT extends BaseJpaTest {
@Mock @Mock
private IValueSetConceptAccumulator myValueSetCodeAccumulator; private IValueSetConceptAccumulator myValueSetCodeAccumulator;
@BeforeEach
public void beforeEach() {
when(mySrd.getUserData().getOrDefault(MAKE_LOADING_VERSION_CURRENT, Boolean.TRUE)).thenReturn(Boolean.TRUE);
}
@AfterEach @AfterEach
public void after() { public void after() {
myDaoConfig.setMaximumExpansionSize(DaoConfig.DEFAULT_MAX_EXPANSION_SIZE); myDaoConfig.setMaximumExpansionSize(DaoConfig.DEFAULT_MAX_EXPANSION_SIZE);