Better CLI error handling for unit tests

This commit is contained in:
James Agnew 2019-01-03 12:57:18 -05:00
parent 4f16fea580
commit 31b8a392b7
20 changed files with 41 additions and 25 deletions

View File

@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
* #%L
* HAPI FHIR - Command Line Client - API
* %%
* Copyright (C) 2014 - 2018 University Health Network
* Copyright (C) 2014 - 2019 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
* #%L
* HAPI FHIR - Command Line Client - API
* %%
* Copyright (C) 2014 - 2018 University Health Network
* Copyright (C) 2014 - 2019 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
* #%L
* HAPI FHIR - Command Line Client - API
* %%
* Copyright (C) 2014 - 2018 University Health Network
* Copyright (C) 2014 - 2019 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -112,7 +112,6 @@ public abstract class BaseApp {
PrintWriter pw = new PrintWriter(System.out);
fmt.printOptions(pw, columns, theCommand.getOptions(), 2, 2);
pw.flush();
pw.close();
// That's it!
System.out.println();
@ -199,7 +198,9 @@ public abstract class BaseApp {
}
}
if (command == null) {
System.err.println("Unknown command: " + theArgs[1]);
String message = "Unknown command: " + theArgs[1];
System.err.println(message);
exitDueToProblem(message);
return;
}
logCommandUsage(command);
@ -215,9 +216,11 @@ public abstract class BaseApp {
}
if (command == null) {
System.out.println("Unrecognized command: " + ansi().bold().fg(Ansi.Color.RED) + theArgs[0] + ansi().boldOff().fg(Ansi.Color.WHITE));
String message = "Unrecognized command: " + ansi().bold().fg(Ansi.Color.RED) + theArgs[0] + ansi().boldOff().fg(Ansi.Color.WHITE);
System.out.println(message);
System.out.println();
logUsage();
exitDueToProblem(message);
return;
}
@ -250,7 +253,9 @@ public abstract class BaseApp {
}
} catch (ParseException e) {
loggingConfigOff();
if (!"true".equals(System.getProperty("test"))) {
loggingConfigOff();
}
System.err.println("Invalid command options for command: " + command.getCommandName());
System.err.println(" " + ansi().fg(Ansi.Color.RED).bold() + e.getMessage());
System.err.println("" + ansi().fg(Ansi.Color.WHITE).boldOff());
@ -269,6 +274,14 @@ public abstract class BaseApp {
}
private void exitDueToProblem(String theDescription) {
if ("true".equals(System.getProperty("test"))) {
throw new Error(theDescription);
} else {
System.exit(1);
}
}
private void exitDueToException(Throwable e) {
if ("true".equals(System.getProperty("test"))) {
if (e instanceof CommandFailureException) {
@ -323,7 +336,7 @@ public abstract class BaseApp {
private class MyShutdownHook extends Thread {
private final BaseCommand myFinalCommand;
public MyShutdownHook(BaseCommand theFinalCommand) {
MyShutdownHook(BaseCommand theFinalCommand) {
myFinalCommand = theFinalCommand;
}

View File

@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
* #%L
* HAPI FHIR - Command Line Client - API
* %%
* Copyright (C) 2014 - 2018 University Health Network
* Copyright (C) 2014 - 2019 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
* #%L
* HAPI FHIR - Command Line Client - API
* %%
* Copyright (C) 2014 - 2018 University Health Network
* Copyright (C) 2014 - 2019 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
* #%L
* HAPI FHIR - Command Line Client - API
* %%
* Copyright (C) 2014 - 2018 University Health Network
* Copyright (C) 2014 - 2019 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
* #%L
* HAPI FHIR - Command Line Client - API
* %%
* Copyright (C) 2014 - 2018 University Health Network
* Copyright (C) 2014 - 2019 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
* #%L
* HAPI FHIR - Command Line Client - API
* %%
* Copyright (C) 2014 - 2018 University Health Network
* Copyright (C) 2014 - 2019 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
* #%L
* HAPI FHIR - Command Line Client - API
* %%
* Copyright (C) 2014 - 2018 University Health Network
* Copyright (C) 2014 - 2019 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
* #%L
* HAPI FHIR - Command Line Client - API
* %%
* Copyright (C) 2014 - 2018 University Health Network
* Copyright (C) 2014 - 2019 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
* #%L
* HAPI FHIR - Command Line Client - API
* %%
* Copyright (C) 2014 - 2018 University Health Network
* Copyright (C) 2014 - 2019 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
* #%L
* HAPI FHIR - Command Line Client - API
* %%
* Copyright (C) 2014 - 2018 University Health Network
* Copyright (C) 2014 - 2019 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
* #%L
* HAPI FHIR - Command Line Client - API
* %%
* Copyright (C) 2014 - 2018 University Health Network
* Copyright (C) 2014 - 2019 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
* #%L
* HAPI FHIR - Command Line Client - API
* %%
* Copyright (C) 2014 - 2018 University Health Network
* Copyright (C) 2014 - 2019 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
* #%L
* HAPI FHIR - Command Line Client - API
* %%
* Copyright (C) 2014 - 2018 University Health Network
* Copyright (C) 2014 - 2019 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
* #%L
* HAPI FHIR - Command Line Client - API
* %%
* Copyright (C) 2014 - 2018 University Health Network
* Copyright (C) 2014 - 2019 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
* #%L
* HAPI FHIR - Command Line Client - API
* %%
* Copyright (C) 2014 - 2018 University Health Network
* Copyright (C) 2014 - 2019 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
* #%L
* HAPI FHIR - Command Line Client - API
* %%
* Copyright (C) 2014 - 2018 University Health Network
* Copyright (C) 2014 - 2019 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -4,7 +4,7 @@ package ca.uhn.fhir.cli;
* #%L
* HAPI FHIR - Command Line Client - API
* %%
* Copyright (C) 2014 - 2018 University Health Network
* Copyright (C) 2014 - 2019 University Health Network
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.

View File

@ -80,6 +80,7 @@ import org.hl7.fhir.instance.model.api.IIdType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.thymeleaf.util.ListUtils;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@ -2060,7 +2061,8 @@ public class SearchBuilder implements ISearchBuilder {
String targetResourceType = defaultString(nextInclude.getParamTargetType(), null);
for (String nextPath : paths) {
String sql;
boolean haveTargetTypesDefinedByParam = param != null && param.getTargets() != null && param.getTargets().isEmpty() == false;
boolean haveTargetTypesDefinedByParam = param.getTargets() != null && param.getTargets().isEmpty() == false;
if (targetResourceType != null) {
sql = "SELECT r FROM ResourceLink r WHERE r.mySourcePath = :src_path AND r." + searchFieldName + " IN (:target_pids) AND r.myTargetResourceType = :target_resource_type";
} else if (haveTargetTypesDefinedByParam) {
@ -2068,6 +2070,7 @@ public class SearchBuilder implements ISearchBuilder {
} else {
sql = "SELECT r FROM ResourceLink r WHERE r.mySourcePath = :src_path AND r." + searchFieldName + " IN (:target_pids)";
}
TypedQuery<ResourceLink> q = theEntityManager.createQuery(sql, ResourceLink.class);
q.setParameter("src_path", nextPath);
q.setParameter("target_pids", nextRoundMatches);