Skip to content

Commit

Permalink
test resource path with resource type set instead of exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
wetret committed Jul 5, 2024
1 parent 6e0a2b4 commit 4f7f7b7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package de.medizininformatik_initiative.process.report.service;

import java.util.EnumSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import org.camunda.bpm.engine.delegate.DelegateExecution;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.r4.model.Bundle;
import org.hl7.fhir.r4.model.ResourceType;
import org.hl7.fhir.r4.model.Task;
Expand All @@ -19,6 +20,7 @@
import org.springframework.web.util.UriComponentsBuilder;

import de.medizininformatik_initiative.process.report.ConstantsReport;

import dev.dsf.bpe.v1.ProcessPluginApi;
import dev.dsf.bpe.v1.activity.AbstractServiceDelegate;
import dev.dsf.bpe.v1.variables.Target;
Expand All @@ -37,11 +39,12 @@ public class CheckSearchBundle extends AbstractServiceDelegate
private static final String SUMMARY_SEARCH_PARAM_VALUE_COUNT = "count";
private static final String TYPE_SEARCH_PARAM = "type";

private static final Set<String> ALL_RESOURCE_TYPES = EnumSet.allOf(ResourceType.class).stream().map(ResourceType::name).collect(Collectors.toSet());

private static final List<String> DATE_SEARCH_PARAMS = List.of("date", "recorded-date", "onset-date", "effective",
"effective-time", "authored", "collected", "issued", "period", "location-period", "occurrence");
private static final List<String> TOKEN_SEARCH_PARAMS = List.of("code", "ingredient-code", "type");
private static final List<String> OTHER_SEARCH_PARAMS = List.of("_profile", "_summary");

private static final List<String> VALID_SEARCH_PARAMS = Stream
.of(DATE_SEARCH_PARAMS.stream(), TOKEN_SEARCH_PARAMS.stream(), OTHER_SEARCH_PARAMS.stream()).flatMap(s -> s)
.toList();
Expand Down Expand Up @@ -129,15 +132,10 @@ private void testContainsOnlyResourcePath(List<UriComponents> uriComponents)

private void testPath(UriComponents uriComponents)
{
try
{
// Converting to ResourceType enum without exception shows that path contains only resource without id
ResourceType.fromCode(uriComponents.getPath());
}
catch (FHIRException exception)
if (!ALL_RESOURCE_TYPES.contains(uriComponents.getPath()))
{
throw new RuntimeException(
"Search Bundle contains request url with resource id - [" + uriComponents.getPath() + "]");
"Search Bundle contains request url with forbidden path - [" + uriComponents.getPath() + "]");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,13 @@ public void testInvalidRequestMethod()
@Test
public void testInvalidResourceId()
{
testInvalid("/fhir/Bundle/search-bundle-invalid-resource-id.xml", "request url with resource id");
testInvalid("/fhir/Bundle/search-bundle-invalid-resource-id.xml", "request url with forbidden path");
}

@Test
public void testInvalidResourceIdDouble()
{
testInvalid("/fhir/Bundle/search-bundle-invalid-resource-id-double.xml", "request url with resource id");
testInvalid("/fhir/Bundle/search-bundle-invalid-resource-id-double.xml", "request url with forbidden path");
}

@Test
Expand Down

0 comments on commit 4f7f7b7

Please sign in to comment.