Add test for localizer and add some docs

This commit is contained in:
James 2016-12-30 08:53:42 -05:00
parent 65f597aeb1
commit e05b0e5d8a
6 changed files with 61 additions and 4 deletions

View File

@ -24,9 +24,12 @@ import static org.apache.commons.lang3.StringUtils.isNotBlank;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
/**
@ -95,4 +98,17 @@ public class HapiLocalizer {
return retVal;
}
}
public Set<String> getAllKeys(){
HashSet<String> retVal = new HashSet<String>();
for (ResourceBundle nextBundle : myBundle) {
Enumeration<String> keysEnum = nextBundle.getKeys();
while (keysEnum.hasMoreElements()) {
retVal.add(keysEnum.nextElement());
}
}
return retVal;
}
}

View File

@ -47,14 +47,14 @@ public class LoggingInterceptor implements IClientInterceptor {
private boolean myLogResponseSummary = true;
/**
* Constructor
* Constructor for client logging interceptor
*/
public LoggingInterceptor() {
super();
}
/**
* Constructor
* Constructor for client logging interceptor
*
* @param theVerbose
* If set to true, all logging is enabled

View File

@ -137,6 +137,13 @@ public class LoggingInterceptor extends InterceptorAdapter {
private Logger myLogger = ourLog;
private String myMessageFormat = "${operationType} - ${idOrResourceName}";
/**
* Constructor for server logging interceptor
*/
public LoggingInterceptor() {
super();
}
/**
* Get the log message format to be used when logging exceptions
*/

View File

@ -0,0 +1,25 @@
package ca.uhn.fhir.i18n;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
import java.util.Set;
import org.junit.Test;
public class HapiLocalizerTest {
@Test
public void testAllKeys() {
HapiLocalizer svc = new HapiLocalizer();
Set<String> allKeys = svc.getAllKeys();
assertThat(allKeys, not(empty()));
for (String next : allKeys) {
svc.getMessage(next);
}
}
}

View File

@ -17,6 +17,7 @@ import ca.uhn.fhir.context.FhirVersionEnum;
import ca.uhn.fhir.jpa.term.IHapiTerminologyLoaderSvc;
import ca.uhn.fhir.rest.client.IGenericClient;
import ca.uhn.fhir.rest.client.interceptor.BearerTokenAuthInterceptor;
import ca.uhn.fhir.rest.client.interceptor.LoggingInterceptor;
public class UploadTerminologyCommand extends BaseCommand {
@ -59,6 +60,10 @@ public class UploadTerminologyCommand extends BaseCommand {
opt.setRequired(false);
options.addOption(opt);
opt = new Option("v", "verbose", false, "Verbose output");
opt.setRequired(false);
options.addOption(opt);
return options;
}
@ -85,7 +90,6 @@ public class UploadTerminologyCommand extends BaseCommand {
String bearerToken = theCommandLine.getOptionValue("b");
IGenericClient client = super.newClient(ctx, targetServer);
IBaseParameters inputParameters;
if (ctx.getVersion().getVersion() == FhirVersionEnum.DSTU3) {
@ -103,6 +107,10 @@ public class UploadTerminologyCommand extends BaseCommand {
client.registerInterceptor(new BearerTokenAuthInterceptor(bearerToken));
}
if (theCommandLine.hasOption('v')) {
client.registerInterceptor(new LoggingInterceptor(true));
}
ourLog.info("Beginning upload - This may take a while...");
IBaseParameters response = client
.operation()

View File

@ -45,6 +45,7 @@ import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import org.apache.commons.csv.QuoteMode;
import org.apache.commons.io.IOUtils;
import org.apache.commons.io.input.BOMInputStream;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;
import org.springframework.beans.factory.annotation.Autowired;
@ -174,7 +175,7 @@ public class TerminologyLoaderSvc implements IHapiTerminologyLoaderSvc {
Reader reader = null;
CSVParser parsed = null;
try {
reader = new InputStreamReader(zis, Charsets.UTF_8);
reader = new InputStreamReader(new BOMInputStream(zis), Charsets.UTF_8);
CSVFormat format = CSVFormat.newFormat(theDelimiter).withFirstRecordAsHeader();
if (theQuoteMode != null) {
format = format.withQuote('"').withQuoteMode(theQuoteMode);