|
7 | 7 | import ca.uhn.fhir.interceptor.api.Pointcut;
|
8 | 8 | import ca.uhn.fhir.jpa.api.config.JpaStorageSettings;
|
9 | 9 | import ca.uhn.fhir.jpa.api.dao.IFhirResourceDao;
|
| 10 | +import ca.uhn.fhir.jpa.api.model.DaoMethodOutcome; |
10 | 11 | import ca.uhn.fhir.jpa.dao.data.ISearchDao;
|
11 | 12 | import ca.uhn.fhir.jpa.entity.Search;
|
12 | 13 | import ca.uhn.fhir.jpa.model.dao.JpaPidFk;
|
|
19 | 20 | import ca.uhn.fhir.jpa.provider.BaseResourceProviderR4Test;
|
20 | 21 | import ca.uhn.fhir.jpa.search.SearchCoordinatorSvcImpl;
|
21 | 22 | import ca.uhn.fhir.jpa.searchparam.SearchParameterMap;
|
| 23 | +import ca.uhn.fhir.jpa.searchparam.submit.interceptor.SearchParamValidatingInterceptor; |
22 | 24 | import ca.uhn.fhir.jpa.term.ZipCollectionBuilder;
|
23 | 25 | import ca.uhn.fhir.jpa.test.config.TestR4Config;
|
24 | 26 | import ca.uhn.fhir.jpa.util.MemoryCacheService;
|
|
62 | 64 | import ca.uhn.fhir.util.StopWatch;
|
63 | 65 | import ca.uhn.fhir.util.TestUtil;
|
64 | 66 | import ca.uhn.fhir.util.UrlUtil;
|
| 67 | +import ca.uhn.test.util.LogbackTestExtension; |
| 68 | +import ca.uhn.test.util.LogbackTestExtensionAssert; |
65 | 69 | import com.google.common.base.Charsets;
|
66 | 70 | import com.google.common.collect.Lists;
|
67 | 71 | import jakarta.annotation.Nonnull;
|
|
170 | 174 | import org.junit.jupiter.api.Disabled;
|
171 | 175 | import org.junit.jupiter.api.Nested;
|
172 | 176 | import org.junit.jupiter.api.Test;
|
| 177 | +import org.junit.jupiter.api.extension.RegisterExtension; |
173 | 178 | import org.junit.jupiter.params.ParameterizedTest;
|
174 | 179 | import org.junit.jupiter.params.provider.Arguments;
|
175 | 180 | import org.junit.jupiter.params.provider.CsvSource;
|
176 | 181 | import org.junit.jupiter.params.provider.MethodSource;
|
177 | 182 | import org.junit.jupiter.params.provider.ValueSource;
|
| 183 | +import ch. qos. logback. classic.Level; |
178 | 184 | import org.springframework.beans.factory.annotation.Autowired;
|
179 | 185 | import org.springframework.test.util.AopTestUtils;
|
180 | 186 | import org.springframework.transaction.TransactionStatus;
|
181 | 187 | import org.springframework.transaction.support.TransactionCallbackWithoutResult;
|
182 | 188 | import org.springframework.transaction.support.TransactionTemplate;
|
| 189 | +import ca.uhn.fhir.rest.api.server.SystemRequestDetails; |
| 190 | +import ca.uhn.fhir.rest.client.apache.ResourceEntity; |
| 191 | + |
183 | 192 |
|
184 | 193 | import java.io.BufferedReader;
|
185 | 194 | import java.io.IOException;
|
@@ -222,6 +231,9 @@ public class ResourceProviderR4Test extends BaseResourceProviderR4Test {
|
222 | 231 | @Autowired
|
223 | 232 | private ISearchDao mySearchEntityDao;
|
224 | 233 |
|
| 234 | + @RegisterExtension |
| 235 | + public LogbackTestExtension myLogbackTestExtension = new LogbackTestExtension(SearchParamValidatingInterceptor.class, Level.WARN); |
| 236 | + |
225 | 237 | @Override
|
226 | 238 | @AfterEach
|
227 | 239 | public void after() throws Exception {
|
@@ -264,7 +276,31 @@ public void before() throws Exception {
|
264 | 276 | myStorageSettings.setSearchPreFetchThresholds(new JpaStorageSettings().getSearchPreFetchThresholds());
|
265 | 277 | }
|
266 | 278 |
|
| 279 | + @Test |
| 280 | + public void testSearchParameterValidation() { |
| 281 | + // setup |
| 282 | + SystemRequestDetails requestDetails = new SystemRequestDetails(); |
| 283 | + requestDetails.getUserData().put(SearchParamValidatingInterceptor.SKIP_VALIDATION, true); |
| 284 | + |
| 285 | + SearchParameter sp = new SearchParameter(); |
| 286 | + sp.setUrl("http://example.com/name"); |
| 287 | + sp.setId("name"); |
| 288 | + sp.setCode("name"); |
| 289 | + sp.setType(Enumerations.SearchParamType.STRING); |
| 290 | + sp.setStatus(Enumerations.PublicationStatus.RETIRED); |
| 291 | + sp.addBase("Patient"); |
| 292 | + sp.setExpression("Patient.name"); |
| 293 | + |
| 294 | + // test |
| 295 | + DaoMethodOutcome outcome = mySearchParameterDao.update(sp, requestDetails); |
267 | 296 |
|
| 297 | + myCaptureQueriesListener.clear(); |
| 298 | + sp.setId(outcome.getId()); |
| 299 | + sp.setStatus(Enumerations.PublicationStatus.ACTIVE); |
| 300 | + mySearchParameterDao.update(sp, requestDetails); |
| 301 | + |
| 302 | + LogbackTestExtensionAssert.assertThat(myLogbackTestExtension).hasWarnMessage("Skipping validation of submitted SearchParameter because " + SearchParamValidatingInterceptor.SKIP_VALIDATION + " flag is true"); |
| 303 | + } |
268 | 304 |
|
269 | 305 | @Test
|
270 | 306 | public void testParameterWithNoValueThrowsError_InvalidChainOnCustomSearch() throws IOException {
|
|
0 commit comments