diff --git a/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/ValidationResult.java b/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/ValidationResult.java index fdef37adfef..161aedcf17e 100644 --- a/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/ValidationResult.java +++ b/hapi-fhir-base/src/main/java/ca/uhn/fhir/validation/ValidationResult.java @@ -83,15 +83,15 @@ public class ValidationResult { StringBuilder b = new StringBuilder(100 * myMessages.size()); int shownMsgQty = Math.min(myErrorDisplayLimit, myMessages.size()); + + if (shownMsgQty < myMessages.size()) { + b.append("(showing first ").append(shownMsgQty).append(" messages out of ") + .append(myMessages.size()).append(" total)").append(ourNewLine); + } + for (int i = 0; i < shownMsgQty; i++) { SingleValidationMessage nextMsg = myMessages.get(i); b.append(ourNewLine); - if (i == 0) { - if (shownMsgQty < myMessages.size()) { - b.append("(showing first ").append(shownMsgQty).append(" messages out of ") - .append(myMessages.size()).append(" total)").append(ourNewLine); - } - } if (nextMsg.getSeverity() != null) { b.append(nextMsg.getSeverity().name()); b.append(" - "); diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/BaseRequestGeneratingCommand.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/BaseRequestGeneratingCommand.java index 642aeb85214..58b99afe212 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/BaseRequestGeneratingCommand.java +++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/main/java/ca/uhn/fhir/cli/BaseRequestGeneratingCommand.java @@ -115,7 +115,7 @@ public abstract class BaseRequestGeneratingCommand extends BaseCommand { /** * @return Returns the optional pass-through header name and value */ - protected Map> getAndParseOptionHeadersPassthrough( + private Map> getAndParseOptionHeadersPassthrough( CommandLine theCommandLine, String theOptionName) throws ParseException { if (! theCommandLine.hasOption(theOptionName)) { diff --git a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/BaseRequestGeneratingCommandTest.java b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/BaseRequestGeneratingCommandTest.java index 6c023c82fa7..6f50e533c58 100644 --- a/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/BaseRequestGeneratingCommandTest.java +++ b/hapi-fhir-cli/hapi-fhir-cli-api/src/test/java/ca/uhn/fhir/cli/BaseRequestGeneratingCommandTest.java @@ -1,23 +1,33 @@ package ca.uhn.fhir.cli; +import ca.uhn.fhir.cli.BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions; import com.google.common.collect.Lists; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.Options; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.EnumSource; +import java.security.InvalidParameterException; import java.util.Arrays; +import java.util.Collection; import java.util.Collections; import java.util.List; +import static ca.uhn.fhir.cli.BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.BASIC_AUTH; +import static ca.uhn.fhir.cli.BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.HEADER_PASSTHROUGH; +import static ca.uhn.fhir.cli.BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.VERSION; +import static ca.uhn.fhir.cli.BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.values; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; class BaseRequestGeneratingCommandTest { private final BaseRequestGeneratingCommand tested = new BaseRequestGeneratingCommandChild(); - private final List allOptions = - Arrays.asList(BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.values()); + private final List allOptions = + Arrays.asList(values()); @Test void getOptions() { @@ -31,70 +41,59 @@ class BaseRequestGeneratingCommandTest { assertTrue(options.hasShortOption(BaseRequestGeneratingCommand.HEADER_PASSTHROUGH)); } - @Test - void getSomeOptionsNoVersion() { - Options options = tested.getSomeOptions( - Collections.singleton(BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.VERSION)); - assertEquals(5, options.getOptions().size()); - assertTrue(options.hasShortOption(BaseCommand.BASE_URL_PARAM)); - assertTrue(options.hasShortOption(BaseCommand.BASIC_AUTH_PARAM)); - assertTrue(options.hasShortOption(BaseCommand.BEARER_TOKEN_PARAM_NAME)); - assertTrue(options.hasShortOption(BaseCommand.VERBOSE_LOGGING_PARAM)); - assertTrue(options.hasShortOption(BaseRequestGeneratingCommand.HEADER_PASSTHROUGH)); + @ParameterizedTest(name = "Excluding {0}") + @EnumSource(value = BaseRequestGeneratingCommandOptions.class, + names = {"VERSION", "BASE_URL", "BASIC_AUTH", "VERBOSE_LOGGING", "HEADER_PASSTHROUGH"}) + void getSomeOptionsExcludingOne(BaseRequestGeneratingCommandOptions excludedOption) { + Collection excludeOptions = Collections.singleton(excludedOption); + + Options options = tested.getSomeOptions(excludeOptions); + + // BASIC_AUTH exclusion excludes 2 options + int expectedSize = excludedOption == BASIC_AUTH ? 4 : 5; + assertEquals(expectedSize, options.getOptions().size()); + + assertFalse(options.hasShortOption(getOptionForExcludedOption(excludedOption))); + if (excludedOption == BASIC_AUTH) { + assertFalse(options.hasLongOption(BaseCommand.BEARER_TOKEN_PARAM_LONGOPT)); + } + + Arrays.stream(values()) + .filter(excludeOptValue -> ! excludeOptValue.equals(excludedOption)) + .forEach(excludeOptValue -> { + assertTrue(options.hasShortOption(getOptionForExcludedOption(excludeOptValue))); + // BASIC_AUTH option carries additional BEARER_TOKEN option + if (excludedOption != BASIC_AUTH) { + assertTrue(options.hasLongOption(BaseCommand.BEARER_TOKEN_PARAM_LONGOPT)); + } + }); } - @Test - void getSomeOptionsNoBaseUrl() { - Options options = tested.getSomeOptions( - Collections.singleton(BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.BASE_URL)); - assertEquals(5, options.getOptions().size()); - assertTrue(options.hasShortOption(BaseCommand.FHIR_VERSION_PARAM)); - assertTrue(options.hasShortOption(BaseCommand.BASIC_AUTH_PARAM)); - assertTrue(options.hasShortOption(BaseCommand.BEARER_TOKEN_PARAM_NAME)); - assertTrue(options.hasShortOption(BaseCommand.VERBOSE_LOGGING_PARAM)); - assertTrue(options.hasShortOption(BaseRequestGeneratingCommand.HEADER_PASSTHROUGH)); - } - @Test - void getSomeOptionsNoBasicAuth() { - Options options = tested.getSomeOptions( - Collections.singleton(BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.BASIC_AUTH)); - assertEquals(4, options.getOptions().size()); - assertTrue(options.hasShortOption(BaseCommand.FHIR_VERSION_PARAM)); - assertTrue(options.hasShortOption(BaseCommand.BASE_URL_PARAM)); - assertTrue(options.hasShortOption(BaseCommand.VERBOSE_LOGGING_PARAM)); - assertTrue(options.hasShortOption(BaseRequestGeneratingCommand.HEADER_PASSTHROUGH)); - } + private String getOptionForExcludedOption(BaseRequestGeneratingCommandOptions excludeOption) { + switch (excludeOption) { + case VERSION: + return BaseCommand.FHIR_VERSION_PARAM; - @Test - void getSomeOptionsNoVerboseLogging() { - Options options = tested.getSomeOptions( - Collections.singleton(BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.VERBOSE_LOGGING)); - assertEquals(5, options.getOptions().size()); - assertTrue(options.hasShortOption(BaseCommand.FHIR_VERSION_PARAM)); - assertTrue(options.hasShortOption(BaseCommand.BASE_URL_PARAM)); - assertTrue(options.hasShortOption(BaseCommand.BASIC_AUTH_PARAM)); - assertTrue(options.hasShortOption(BaseCommand.BEARER_TOKEN_PARAM_NAME)); - assertTrue(options.hasShortOption(BaseRequestGeneratingCommand.HEADER_PASSTHROUGH)); - } + case BASE_URL: + return BaseCommand.BASE_URL_PARAM; - @Test - void getSomeOptionsNoHeaderPassthrough() { - Options options = tested.getSomeOptions( - Collections.singleton(BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.HEADER_PASSTHROUGH)); - assertEquals(5, options.getOptions().size()); - assertTrue(options.hasShortOption(BaseCommand.FHIR_VERSION_PARAM)); - assertTrue(options.hasShortOption(BaseCommand.BASE_URL_PARAM)); - assertTrue(options.hasShortOption(BaseCommand.BASIC_AUTH_PARAM)); - assertTrue(options.hasShortOption(BaseCommand.BEARER_TOKEN_PARAM_NAME)); - assertTrue(options.hasShortOption(BaseCommand.VERBOSE_LOGGING_PARAM)); + case BASIC_AUTH: + return BaseCommand.BASIC_AUTH_PARAM; + + case VERBOSE_LOGGING: + return BaseCommand.VERBOSE_LOGGING_PARAM; + + case HEADER_PASSTHROUGH: + return BaseRequestGeneratingCommand.HEADER_PASSTHROUGH; + } + throw new InvalidParameterException("unexpected exclude option " + excludeOption); } @Test void getSomeOptionsExcludeTwo() { - Options options = tested.getSomeOptions(Lists.newArrayList( - BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.VERSION, - BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.HEADER_PASSTHROUGH)); + Options options = tested.getSomeOptions(Lists.newArrayList(VERSION, HEADER_PASSTHROUGH)); + assertEquals(4, options.getOptions().size()); assertTrue(options.hasShortOption(BaseCommand.BASE_URL_PARAM)); assertTrue(options.hasShortOption(BaseCommand.BASIC_AUTH_PARAM)); diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_5_0/2777-hapi-fhir-cli-add-header-passthrough-option.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_5_0/2777-hapi-fhir-cli-add-header-passthrough-option.yaml new file mode 100644 index 00000000000..bb71334b578 --- /dev/null +++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/5_5_0/2777-hapi-fhir-cli-add-header-passthrough-option.yaml @@ -0,0 +1,7 @@ +--- +type: add +issue: 2777 +title: "Support for multiple header-passthrough option using -hp or --header-passthrough + parameter has been added to hapi-fhir-cli commands: example-data-uploader, export-conceptmap-to-csv, + import-csv-to-conceptmap and upload-terminology" +