Merge pull request #2783 from hapifhir/2777-hapi-fhir-cli-Add-option-to-pass-request-headers-to-target-server
Add changelog. Address MR comments.
This commit is contained in:
commit
0a27b08aad
|
@ -83,15 +83,15 @@ public class ValidationResult {
|
||||||
|
|
||||||
StringBuilder b = new StringBuilder(100 * myMessages.size());
|
StringBuilder b = new StringBuilder(100 * myMessages.size());
|
||||||
int shownMsgQty = Math.min(myErrorDisplayLimit, myMessages.size());
|
int shownMsgQty = Math.min(myErrorDisplayLimit, myMessages.size());
|
||||||
for (int i = 0; i < shownMsgQty; i++) {
|
|
||||||
SingleValidationMessage nextMsg = myMessages.get(i);
|
|
||||||
b.append(ourNewLine);
|
|
||||||
if (i == 0) {
|
|
||||||
if (shownMsgQty < myMessages.size()) {
|
if (shownMsgQty < myMessages.size()) {
|
||||||
b.append("(showing first ").append(shownMsgQty).append(" messages out of ")
|
b.append("(showing first ").append(shownMsgQty).append(" messages out of ")
|
||||||
.append(myMessages.size()).append(" total)").append(ourNewLine);
|
.append(myMessages.size()).append(" total)").append(ourNewLine);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
for (int i = 0; i < shownMsgQty; i++) {
|
||||||
|
SingleValidationMessage nextMsg = myMessages.get(i);
|
||||||
|
b.append(ourNewLine);
|
||||||
if (nextMsg.getSeverity() != null) {
|
if (nextMsg.getSeverity() != null) {
|
||||||
b.append(nextMsg.getSeverity().name());
|
b.append(nextMsg.getSeverity().name());
|
||||||
b.append(" - ");
|
b.append(" - ");
|
||||||
|
|
|
@ -115,7 +115,7 @@ public abstract class BaseRequestGeneratingCommand extends BaseCommand {
|
||||||
/**
|
/**
|
||||||
* @return Returns the optional pass-through header name and value
|
* @return Returns the optional pass-through header name and value
|
||||||
*/
|
*/
|
||||||
protected Map<String, List<String>> getAndParseOptionHeadersPassthrough(
|
private Map<String, List<String>> getAndParseOptionHeadersPassthrough(
|
||||||
CommandLine theCommandLine, String theOptionName) throws ParseException {
|
CommandLine theCommandLine, String theOptionName) throws ParseException {
|
||||||
|
|
||||||
if (! theCommandLine.hasOption(theOptionName)) {
|
if (! theCommandLine.hasOption(theOptionName)) {
|
||||||
|
|
|
@ -1,23 +1,33 @@
|
||||||
package ca.uhn.fhir.cli;
|
package ca.uhn.fhir.cli;
|
||||||
|
|
||||||
|
import ca.uhn.fhir.cli.BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions;
|
||||||
import com.google.common.collect.Lists;
|
import com.google.common.collect.Lists;
|
||||||
import org.apache.commons.cli.CommandLine;
|
import org.apache.commons.cli.CommandLine;
|
||||||
import org.apache.commons.cli.Options;
|
import org.apache.commons.cli.Options;
|
||||||
import org.junit.jupiter.api.Test;
|
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.Arrays;
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
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.assertEquals;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
class BaseRequestGeneratingCommandTest {
|
class BaseRequestGeneratingCommandTest {
|
||||||
|
|
||||||
private final BaseRequestGeneratingCommand tested = new BaseRequestGeneratingCommandChild();
|
private final BaseRequestGeneratingCommand tested = new BaseRequestGeneratingCommandChild();
|
||||||
|
|
||||||
private final List<BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions> allOptions =
|
private final List<BaseRequestGeneratingCommandOptions> allOptions =
|
||||||
Arrays.asList(BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.values());
|
Arrays.asList(values());
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getOptions() {
|
void getOptions() {
|
||||||
|
@ -31,70 +41,59 @@ class BaseRequestGeneratingCommandTest {
|
||||||
assertTrue(options.hasShortOption(BaseRequestGeneratingCommand.HEADER_PASSTHROUGH));
|
assertTrue(options.hasShortOption(BaseRequestGeneratingCommand.HEADER_PASSTHROUGH));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@ParameterizedTest(name = "Excluding {0}")
|
||||||
void getSomeOptionsNoVersion() {
|
@EnumSource(value = BaseRequestGeneratingCommandOptions.class,
|
||||||
Options options = tested.getSomeOptions(
|
names = {"VERSION", "BASE_URL", "BASIC_AUTH", "VERBOSE_LOGGING", "HEADER_PASSTHROUGH"})
|
||||||
Collections.singleton(BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.VERSION));
|
void getSomeOptionsExcludingOne(BaseRequestGeneratingCommandOptions excludedOption) {
|
||||||
assertEquals(5, options.getOptions().size());
|
Collection<BaseRequestGeneratingCommandOptions> excludeOptions = Collections.singleton(excludedOption);
|
||||||
assertTrue(options.hasShortOption(BaseCommand.BASE_URL_PARAM));
|
|
||||||
assertTrue(options.hasShortOption(BaseCommand.BASIC_AUTH_PARAM));
|
Options options = tested.getSomeOptions(excludeOptions);
|
||||||
assertTrue(options.hasShortOption(BaseCommand.BEARER_TOKEN_PARAM_NAME));
|
|
||||||
assertTrue(options.hasShortOption(BaseCommand.VERBOSE_LOGGING_PARAM));
|
// BASIC_AUTH exclusion excludes 2 options
|
||||||
assertTrue(options.hasShortOption(BaseRequestGeneratingCommand.HEADER_PASSTHROUGH));
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
Arrays.stream(values())
|
||||||
void getSomeOptionsNoBaseUrl() {
|
.filter(excludeOptValue -> ! excludeOptValue.equals(excludedOption))
|
||||||
Options options = tested.getSomeOptions(
|
.forEach(excludeOptValue -> {
|
||||||
Collections.singleton(BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.BASE_URL));
|
assertTrue(options.hasShortOption(getOptionForExcludedOption(excludeOptValue)));
|
||||||
assertEquals(5, options.getOptions().size());
|
// BASIC_AUTH option carries additional BEARER_TOKEN option
|
||||||
assertTrue(options.hasShortOption(BaseCommand.FHIR_VERSION_PARAM));
|
if (excludedOption != BASIC_AUTH) {
|
||||||
assertTrue(options.hasShortOption(BaseCommand.BASIC_AUTH_PARAM));
|
assertTrue(options.hasLongOption(BaseCommand.BEARER_TOKEN_PARAM_LONGOPT));
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
private String getOptionForExcludedOption(BaseRequestGeneratingCommandOptions excludeOption) {
|
||||||
void getSomeOptionsNoVerboseLogging() {
|
switch (excludeOption) {
|
||||||
Options options = tested.getSomeOptions(
|
case VERSION:
|
||||||
Collections.singleton(BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.VERBOSE_LOGGING));
|
return BaseCommand.FHIR_VERSION_PARAM;
|
||||||
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));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
case BASE_URL:
|
||||||
void getSomeOptionsNoHeaderPassthrough() {
|
return BaseCommand.BASE_URL_PARAM;
|
||||||
Options options = tested.getSomeOptions(
|
|
||||||
Collections.singleton(BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.HEADER_PASSTHROUGH));
|
case BASIC_AUTH:
|
||||||
assertEquals(5, options.getOptions().size());
|
return BaseCommand.BASIC_AUTH_PARAM;
|
||||||
assertTrue(options.hasShortOption(BaseCommand.FHIR_VERSION_PARAM));
|
|
||||||
assertTrue(options.hasShortOption(BaseCommand.BASE_URL_PARAM));
|
case VERBOSE_LOGGING:
|
||||||
assertTrue(options.hasShortOption(BaseCommand.BASIC_AUTH_PARAM));
|
return BaseCommand.VERBOSE_LOGGING_PARAM;
|
||||||
assertTrue(options.hasShortOption(BaseCommand.BEARER_TOKEN_PARAM_NAME));
|
|
||||||
assertTrue(options.hasShortOption(BaseCommand.VERBOSE_LOGGING_PARAM));
|
case HEADER_PASSTHROUGH:
|
||||||
|
return BaseRequestGeneratingCommand.HEADER_PASSTHROUGH;
|
||||||
|
}
|
||||||
|
throw new InvalidParameterException("unexpected exclude option " + excludeOption);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void getSomeOptionsExcludeTwo() {
|
void getSomeOptionsExcludeTwo() {
|
||||||
Options options = tested.getSomeOptions(Lists.newArrayList(
|
Options options = tested.getSomeOptions(Lists.newArrayList(VERSION, HEADER_PASSTHROUGH));
|
||||||
BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.VERSION,
|
|
||||||
BaseRequestGeneratingCommand.BaseRequestGeneratingCommandOptions.HEADER_PASSTHROUGH));
|
|
||||||
assertEquals(4, options.getOptions().size());
|
assertEquals(4, options.getOptions().size());
|
||||||
assertTrue(options.hasShortOption(BaseCommand.BASE_URL_PARAM));
|
assertTrue(options.hasShortOption(BaseCommand.BASE_URL_PARAM));
|
||||||
assertTrue(options.hasShortOption(BaseCommand.BASIC_AUTH_PARAM));
|
assertTrue(options.hasShortOption(BaseCommand.BASIC_AUTH_PARAM));
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
---
|
||||||
|
type: add
|
||||||
|
issue: 2777
|
||||||
|
title: "Support for multiple header-passthrough option using <b>-hp</b> or <b>--header-passthrough</b>
|
||||||
|
parameter has been added to hapi-fhir-cli commands: <b>example-data-uploader</b>, <b>export-conceptmap-to-csv</b>,
|
||||||
|
<b>import-csv-to-conceptmap</b> and <b>upload-terminology</b>"
|
||||||
|
|
Loading…
Reference in New Issue