Replace assert with Validate (#6558)

* Replace assert with Validate

* Test cleanup
This commit is contained in:
James Agnew 2024-12-16 15:06:15 -05:00 committed by GitHub
parent 79fa8b16e2
commit 0964710fd3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 33 additions and 7 deletions

View File

@ -633,5 +633,9 @@ public class TermConcept implements Serializable {
public String toString() {
return String.valueOf(myId);
}
public Long getId() {
return myId;
}
}
}

View File

@ -478,8 +478,11 @@ public class TermCodeSystemStorageSvcImpl implements ITermCodeSystemStorageSvc {
Collection<TermConcept> conceptsToSave = theCodeSystemVersion.getConcepts();
for (TermConcept next : conceptsToSave) {
totalCodeCount += validateConceptForStorage(next, codeSystemToStore, conceptsStack, allConcepts);
assert next.getId() == null;
assert codeSystemToStore.getPid() != null;
Validate.isTrue(next.getPid().getId() == null);
Validate.isTrue(codeSystemToStore.getPid() != null);
// Make sure to initialize the PK object so that hibernate doesn't choke on creation
next.setId(null);
next.setCodeSystemVersion(codeSystemToStore);
next.setUpdated(updated);

View File

@ -61,6 +61,7 @@ import org.hl7.fhir.r4.model.Bundle.BundleEntryResponseComponent;
import org.hl7.fhir.r4.model.Bundle.BundleType;
import org.hl7.fhir.r4.model.Bundle.HTTPVerb;
import org.hl7.fhir.r4.model.CanonicalType;
import org.hl7.fhir.r4.model.CodeSystem;
import org.hl7.fhir.r4.model.Coding;
import org.hl7.fhir.r4.model.Communication;
import org.hl7.fhir.r4.model.Condition;
@ -1358,6 +1359,25 @@ public class FhirSystemDaoR4Test extends BaseJpaR4SystemTest {
}
}
@Test
public void testTransactionCreateCodeSystem() {
BundleBuilder bb = new BundleBuilder(myFhirContext);
CodeSystem cs = new CodeSystem();
cs.setId("CodeSystem/A");
cs.setUrl("http://example.com/codesystem");
cs.setContent(CodeSystem.CodeSystemContentMode.COMPLETE);
cs.addConcept().setCode("1").setDisplay("1");
bb.addTransactionUpdateEntry(cs);
Bundle outcome = mySystemDao.transaction(mySrd, bb.getBundleTyped());
assertThat(outcome.getEntry()).hasSize(1);
assertThat(outcome.getEntry().get(0).getResponse().getLocation()).endsWith("/_history/1");
}
@Test
public void testTransactionCreateInlineMatchUrlWithOneMatch2() {
String methodName = "testTransactionCreateInlineMatchUrlWithOneMatch2";

View File

@ -1,8 +1,5 @@
package ca.uhn.fhir.jpa.provider.r4;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertNull;
import ca.uhn.fhir.batch2.jobs.expunge.DeleteExpungeProvider;
import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.i18n.Msg;
@ -59,9 +56,9 @@ import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.ee10.servlet.ServletContextHandler;
import org.eclipse.jetty.ee10.servlet.ServletHolder;
import org.eclipse.jetty.server.Server;
import org.hl7.fhir.common.hapi.validation.validator.FhirInstanceValidator;
import org.hl7.fhir.instance.model.api.IBaseBundle;
import org.hl7.fhir.instance.model.api.IIdType;
@ -101,7 +98,9 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;