Skip to content

Commit e6e04ba

Browse files
Add tests for package installation with partitioning and null partition ID handling
1 parent 834c438 commit e6e04ba

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

hapi-fhir-base/src/test/java/ca/uhn/fhir/interceptor/model/RequestPartitionIdTest.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,50 @@ public void testIsDefaultPartition_withPartitionAsParameter() {
5757
assertThat(defaultPartition().isPartition(null)).isTrue();
5858
assertThat(fromPartitionIds(ourDefaultPartitionId).isPartition(ourDefaultPartitionId)).isTrue();
5959

60-
assertThat(defaultPartition().isPartition(ourDefaultPartitionId)).isFalse();
60+
// Since null partition ID is now treated as 0, defaultPartition() (null) matches ourDefaultPartitionId (0)
61+
assertThat(defaultPartition().isPartition(ourDefaultPartitionId)).isTrue();
6162
assertThat(allPartitions().isPartition(ourDefaultPartitionId)).isFalse();
6263
assertThat(fromPartitionIds(ourDefaultPartitionId, 2).isPartition(ourDefaultPartitionId)).isFalse();
6364
}
6465

66+
@Test
67+
public void testIsPartition_NullPartitionIdTreatedAsZero() {
68+
// Test that null partition ID in the RequestPartitionId is treated as 0
69+
RequestPartitionId partitionWithNull = fromPartitionIds((Integer) null);
70+
assertThat(partitionWithNull.isPartition(0)).as("Null partition ID should be treated as 0").isTrue();
71+
assertThat(partitionWithNull.isPartition(null)).as("Null should match null").isTrue();
72+
assertThat(partitionWithNull.isPartition(1)).as("Null partition ID should not match 1").isFalse();
73+
74+
// Test that partition ID 0 matches null parameter
75+
RequestPartitionId partitionWithZero = fromPartitionIds(0);
76+
assertThat(partitionWithZero.isPartition(null)).as("Partition ID 0 should match null parameter").isTrue();
77+
assertThat(partitionWithZero.isPartition(0)).as("Partition ID 0 should match 0").isTrue();
78+
assertThat(partitionWithZero.isPartition(1)).as("Partition ID 0 should not match 1").isFalse();
79+
}
80+
81+
@Test
82+
public void testIsPartition_WithNonNullPartitionIds() {
83+
// Test normal partition ID matching
84+
RequestPartitionId partition1 = fromPartitionIds(1);
85+
assertThat(partition1.isPartition(1)).isTrue();
86+
assertThat(partition1.isPartition(0)).isFalse();
87+
assertThat(partition1.isPartition(null)).isFalse();
88+
assertThat(partition1.isPartition(2)).isFalse();
89+
90+
// Test with multiple partition IDs (should return false)
91+
RequestPartitionId multiPartition = fromPartitionIds(1, 2);
92+
assertThat(multiPartition.isPartition(1)).isFalse();
93+
assertThat(multiPartition.isPartition(2)).isFalse();
94+
}
95+
96+
@Test
97+
public void testIsPartition_WithAllPartitions() {
98+
RequestPartitionId allParts = allPartitions();
99+
assertThat(allParts.isPartition(0)).isFalse();
100+
assertThat(allParts.isPartition(1)).isFalse();
101+
assertThat(allParts.isPartition(null)).isFalse();
102+
}
103+
65104
@Test
66105
public void testHasDefaultPartition_withDefaultPartitionAsParameter() {
67106

hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/packages/PackageInstallerSvcR4Test.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,5 +1031,29 @@ public void testInstallR4PackageCircularDependency() throws Exception {
10311031
assertThat(snapshotMessages).hasSize(5);
10321032
}
10331033

1034+
@Test
1035+
public void testInstallPackageWithPartitioningEnabled() throws Exception {
1036+
// Enable partitioning
1037+
myPartitionSettings.setPartitioningEnabled(true);
1038+
myPartitionSettings.setDefaultPartitionId(0);
1039+
1040+
// Install a package containing CodeSystem resources
1041+
byte[] bytes = ClasspathUtil.loadResourceAsByteArray("/packages/hl7.fhir.uv.shorthand-0.12.0.tgz");
1042+
myFakeNpmServlet.responses.put("/hl7.fhir.uv.shorthand/0.12.0", bytes);
1043+
1044+
PackageInstallationSpec spec = new PackageInstallationSpec()
1045+
.setName("hl7.fhir.uv.shorthand")
1046+
.setVersion("0.12.0")
1047+
.setInstallMode(PackageInstallationSpec.InstallModeEnum.STORE_AND_INSTALL);
1048+
1049+
// This should not throw an exception about non-partitionable resources
1050+
myPackageInstallerSvc.install(spec);
1051+
1052+
// Verify the package was installed successfully
1053+
runInTransaction(() -> {
1054+
assertTrue(myPackageVersionDao.findByPackageIdAndVersion("hl7.fhir.uv.shorthand", "0.12.0").isPresent());
1055+
});
1056+
}
1057+
10341058

10351059
}

0 commit comments

Comments
 (0)