-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
leif stawnyczy
committed
Feb 12, 2025
1 parent
1edfaec
commit 6bb2b78
Showing
3 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
hapi-fhir-jpaserver-mdm/src/test/java/ca/uhn/fhir/jpa/mdm/interceptor/MdmPartitionIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
package ca.uhn.fhir.jpa.mdm.interceptor; | ||
|
||
import ca.uhn.fhir.interceptor.api.Hook; | ||
import ca.uhn.fhir.interceptor.api.IInterceptorService; | ||
import ca.uhn.fhir.interceptor.api.Pointcut; | ||
import ca.uhn.fhir.interceptor.model.RequestPartitionId; | ||
import ca.uhn.fhir.jpa.entity.PartitionEntity; | ||
import ca.uhn.fhir.jpa.mdm.BaseMdmR4Test; | ||
import ca.uhn.fhir.jpa.mdm.helper.MdmHelperConfig; | ||
import ca.uhn.fhir.jpa.mdm.helper.MdmHelperR4; | ||
import ca.uhn.fhir.jpa.model.config.PartitionSettings; | ||
import ca.uhn.fhir.jpa.partition.IPartitionLookupSvc; | ||
import ca.uhn.fhir.jpa.subscription.model.ResourceModifiedMessage; | ||
import ca.uhn.fhir.rest.api.server.RequestDetails; | ||
import jakarta.annotation.PostConstruct; | ||
import org.hl7.fhir.r4.model.Patient; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.slf4j.Logger; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.test.context.ContextConfiguration; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
import static org.slf4j.LoggerFactory.getLogger; | ||
|
||
@ContextConfiguration(classes = {MdmHelperConfig.class, MdmPartitionIT.PartitionConfiguration.class}) | ||
public class MdmPartitionIT extends BaseMdmR4Test { | ||
private static final Logger ourLog = getLogger(MdmPartitionIT.class); | ||
|
||
@Configuration | ||
public static class PartitionConfiguration { | ||
@Autowired | ||
private PartitionSettings myPartitionSettings; | ||
|
||
@Autowired | ||
private IPartitionLookupSvc myPartitionLookupSvc; | ||
|
||
@Autowired | ||
private IInterceptorService myInterceptorService; | ||
|
||
// a bean so we can access it here and in the test suite | ||
@Bean | ||
MyTestInterceptor testInterceptor() { | ||
return new MyTestInterceptor(); | ||
} | ||
|
||
@PostConstruct | ||
public void init() { | ||
myPartitionSettings.setPartitioningEnabled(true); | ||
myPartitionSettings.setDefaultPartitionId(10); | ||
myPartitionSettings.setUnnamedPartitionMode(false); | ||
myPartitionLookupSvc.createPartition(new PartitionEntity().setId(1).setName(PARTITION_1), null); | ||
myPartitionLookupSvc.createPartition(new PartitionEntity().setId(2).setName(PARTITION_2), null); | ||
|
||
myInterceptorService.registerInterceptor(testInterceptor()); | ||
} | ||
} | ||
|
||
private static class MyTestInterceptor { | ||
|
||
private RequestPartitionId myPartitionIdToSpoof; | ||
|
||
public void setPartitionIdToSpoof(RequestPartitionId theRequestPartitionId) { | ||
myPartitionIdToSpoof = theRequestPartitionId; | ||
} | ||
|
||
@Hook(Pointcut.STORAGE_PARTITION_IDENTIFY_ANY) | ||
public RequestPartitionId hook(RequestDetails theRequestDetails) { | ||
if (myPartitionIdToSpoof != null) { | ||
return myPartitionIdToSpoof; | ||
} | ||
return RequestPartitionId.fromPartitionId(10); | ||
} | ||
|
||
@Hook(Pointcut.SUBSCRIPTION_RESOURCE_DID_NOT_MATCH_ANY_SUBSCRIPTIONS) | ||
public void didNotFind(ResourceModifiedMessage theMsg) { | ||
ourLog.info(theMsg.toString()); | ||
} | ||
} | ||
|
||
@RegisterExtension | ||
@Autowired | ||
public MdmHelperR4 myMdmHelper; | ||
|
||
@Autowired | ||
private MyTestInterceptor myInterceptor; | ||
|
||
@Override | ||
public void beforeUnregisterAllSubscriptions() { | ||
// noop | ||
} | ||
|
||
@Test | ||
public void createResource_withNonDefaultIdPartition_shouldCreate() throws InterruptedException { | ||
// setup | ||
Patient patient = buildFrankPatient(); | ||
|
||
long initialCount = myMdmLinkDao.count(); | ||
|
||
// test | ||
myMdmHelper.createWithLatch(patient, true); | ||
|
||
// verify | ||
assertEquals(initialCount + 1, myMdmLinkDao.count()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters