Merge remote-tracking branch 'remotes/origin/master' into ks-20200120-near-search

This commit is contained in:
Ken Stevens 2020-01-22 09:21:36 -05:00
commit 02a95115a4
7 changed files with 125 additions and 34 deletions

View File

@ -0,0 +1,5 @@
---
type: fix
issue: 1676
title: "When validating an XML resource, the validatin failed if the resource contained an
`xsi:schemaLocation` declaration. This has been corrected. Thanks to Brian Kaney for reporting!"

View File

@ -187,7 +187,6 @@ public class ArbitrarySqlTask extends BaseTask<ArbitrarySqlTask> {
public int hashCode() {
return new HashCodeBuilder(17, 37)
.append(myTableName)
.append(myExecuteOnlyIfTableExists)
.toHashCode();
}
}

View File

@ -159,8 +159,6 @@ public class RenameColumnTask extends BaseTableTask<RenameColumnTask> {
.appendSuper(super.hashCode())
.append(myOldName)
.append(myNewName)
.append(myIsOkayIfNeitherColumnExists)
.append(myDeleteTargetColumnFirstIfBothExist)
.toHashCode();
}
}

View File

@ -50,9 +50,10 @@ public class Builder {
return new BuilderAddTableRawSql(theVersion, theTableName);
}
public Builder executeRawSql(String theVersion, @Language("SQL") String theSql) {
mySink.addTask(new ExecuteRawSqlTask(myRelease, theVersion).addSql(theSql));
return this;
public BuilderCompleteTask executeRawSql(String theVersion, @Language("SQL") String theSql) {
ExecuteRawSqlTask task = new ExecuteRawSqlTask(myRelease, theVersion).addSql(theSql);
mySink.addTask(task);
return new BuilderCompleteTask(task);
}
public Builder initializeSchema(String theVersion, ISchemaInitializationProvider theSchemaInitializationProvider) {
@ -72,6 +73,7 @@ public class Builder {
return this;
}
// Flyway doesn't support these kinds of migrations
@Deprecated
public Builder startSectionWithMessage(String theMessage) {
@ -395,7 +397,7 @@ public class Builder {
}
}
public static class BuilderAddColumnWithName {
public class BuilderAddColumnWithName {
private final String myRelease;
private final String myVersion;
private final String myColumnName;
@ -427,11 +429,11 @@ public class Builder {
myNullable = theNullable;
}
public BuilderAddColumnComplete type(AddColumnTask.ColumnTypeEnum theColumnType) {
public BuilderCompleteTask type(AddColumnTask.ColumnTypeEnum theColumnType) {
return type(theColumnType, null);
}
public BuilderAddColumnComplete type(AddColumnTask.ColumnTypeEnum theColumnType, Integer theLength) {
public BuilderCompleteTask type(AddColumnTask.ColumnTypeEnum theColumnType, Integer theLength) {
AddColumnTask task = new AddColumnTask(myRelease, myVersion);
task.setColumnName(myColumnName);
task.setNullable(myNullable);
@ -441,24 +443,26 @@ public class Builder {
}
myTaskSink.addTask(task);
return new BuilderAddColumnComplete(task);
return new BuilderCompleteTask(task);
}
public class BuilderAddColumnComplete {
private final AddColumnTask myTask;
public BuilderAddColumnComplete(AddColumnTask theTask) {
myTask = theTask;
}
public BuilderAddColumnComplete failureAllowed() {
myTask.setFailureAllowed(true);
return this;
}
}
}
}
}
public static class BuilderCompleteTask {
private final BaseTask<?> myTask;
public BuilderCompleteTask(BaseTask<?> theTask) {
myTask = theTask;
}
public BuilderCompleteTask failureAllowed() {
myTask.setFailureAllowed(true);
return this;
}
}
}

View File

@ -0,0 +1,48 @@
package ca.uhn.fhir.jpa.migrate.taskdef;
import ca.uhn.fhir.jpa.migrate.tasks.api.BaseMigrationTasks;
import ca.uhn.fhir.util.VersionEnum;
import org.junit.Test;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
public class ExecuteRawSqlTaskTest extends BaseTest {
@Test
public void testExecuteSql() {
executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))");
BaseMigrationTasks<VersionEnum> tasks = new BaseMigrationTasks<>();
tasks
.forVersion(VersionEnum.V4_0_0)
.executeRawSql("2001.01", "INSERT INTO SOMETABLE (PID, TEXTCOL) VALUES (123, 'abc')");
getMigrator().addTasks(tasks.getTasks(VersionEnum.V0_1, VersionEnum.V4_0_0));
getMigrator().migrate();
List<Map<String, Object>> output = executeQuery("SELECT PID FROM SOMETABLE");
assertEquals(1, output.size());
assertEquals(123L, output.get(0).get("PID"));
}
@Test
public void testExecuteSql_AllowedToFail() {
executeSql("create table SOMETABLE (PID bigint not null, TEXTCOL varchar(255))");
BaseMigrationTasks<VersionEnum> tasks = new BaseMigrationTasks<>();
tasks
.forVersion(VersionEnum.V4_0_0)
.executeRawSql("2001.01", "INSERT INTO SOMETABLE (PID_BAD_COLUMN, TEXTCOL) VALUES (123, 'abc')")
.failureAllowed();
getMigrator().addTasks(tasks.getTasks(VersionEnum.V0_1, VersionEnum.V4_0_0));
getMigrator().migrate();
List<Map<String, Object>> output = executeQuery("SELECT PID FROM SOMETABLE");
assertEquals(0, output.size());
}
}

View File

@ -82,6 +82,7 @@ public class ValidatorWrapper {
v.setNoTerminologyChecks(myNoTerminologyChecks);
v.setErrorForUnknownProfiles(myErrorForUnknownProfiles);
v.getExtensionDomains().addAll(myExtensionDomains);
v.setAllowXsiLocation(true);
List<ValidationMessage> messages = new ArrayList<>();

View File

@ -12,7 +12,6 @@ import ca.uhn.fhir.validation.ValidationResult;
import com.google.common.base.Charsets;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.Validate;
import org.hl7.fhir.dstu3.hapi.validation.ResourceValidatorDstu3Test;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.r4.conformance.ProfileUtilities;
@ -36,7 +35,11 @@ import org.hl7.fhir.r4.utils.FHIRPathEngine;
import org.hl7.fhir.r5.utils.IResourceValidator;
import org.hl7.fhir.utilities.validation.ValidationMessage;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.junit.*;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
@ -44,13 +47,25 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import java.io.IOException;
import java.io.InputStream;
import java.util.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
import java.util.stream.Collectors;
import java.util.zip.GZIPInputStream;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -127,8 +142,8 @@ public class FhirInstanceValidatorR4Test extends BaseTest {
});
when(myMockSupport.isCodeSystemSupported(nullable(FhirContext.class), nullable(String.class))).thenAnswer(new Answer<Boolean>() {
@Override
public Boolean answer(InvocationOnMock theInvocation) throws Throwable {
boolean retVal = myValidSystems.contains(theInvocation.getArguments()[1]);
public Boolean answer(InvocationOnMock theInvocation) {
boolean retVal = myValidSystems.contains(theInvocation.getArgument(1, String.class));
ourLog.debug("isCodeSystemSupported({}) : {}", new Object[]{theInvocation.getArguments()[1], retVal});
return retVal;
}
@ -139,7 +154,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest {
IBaseResource retVal;
String id = (String) theInvocation.getArguments()[2];
if ("Questionnaire/q_jon".equals(id)) {
retVal = ourCtx.newJsonParser().parseResource(IOUtils.toString(FhirInstanceValidatorR4Test.class.getResourceAsStream("/q_jon.json")));
retVal = ourCtx.newJsonParser().parseResource(loadResource("/q_jon.json"));
} else {
retVal = myDefaultValidationSupport.fetchResource((FhirContext) theInvocation.getArguments()[0], (Class<IBaseResource>) theInvocation.getArguments()[1], id);
}
@ -210,7 +225,7 @@ public class FhirInstanceValidatorR4Test extends BaseTest {
}
private List<SingleValidationMessage> logResultsAndReturnAll(ValidationResult theOutput) {
List<SingleValidationMessage> retVal = new ArrayList<SingleValidationMessage>();
List<SingleValidationMessage> retVal = new ArrayList<>();
int index = 0;
for (SingleValidationMessage next : theOutput.getMessages()) {
@ -264,6 +279,27 @@ public class FhirInstanceValidatorR4Test extends BaseTest {
assertEquals("Primitive types must have a value that is not empty", all.get(0).getMessage());
}
/**
* See #1676 - We should ignore schema location
*/
@Test
public void testValidateResourceWithSchemaLocation() {
String input = "<Patient xmlns=\"http://hl7.org/fhir\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://hl7.org/fhir ../../schema/foo.xsd\">" +
" <text>\n" +
" <status value=\"generated\"/>\n" +
" <div xmlns=\"http://www.w3.org/1999/xhtml\">AAA</div>\n" +
" </text>" +
" <active value=\"true\"/>" +
"</Patient>";
FhirValidator val = ourCtx.newValidator();
val.registerValidatorModule(new FhirInstanceValidator(myDefaultValidationSupport));
ValidationResult result = val.validateWithResult(input);
logResultsAndReturnAll(result);
assertTrue(result.isSuccessful());
}
/**
* See #942
*/