Fix tests

This commit is contained in:
jamesagnew 2016-04-17 12:58:36 -04:00
parent 5a818a38e8
commit 846e216c04
12 changed files with 52 additions and 36 deletions

View File

@ -21,6 +21,7 @@ package ca.uhn.fhir.rest.server.interceptor;
*/
import java.io.IOException;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletException;
@ -39,6 +40,7 @@ import ca.uhn.fhir.rest.annotation.ResourceParam;
import ca.uhn.fhir.rest.annotation.Search;
import ca.uhn.fhir.rest.api.RestOperationTypeEnum;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.server.IRestfulServerDefaults;
import ca.uhn.fhir.rest.server.exceptions.AuthenticationException;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
@ -446,7 +448,16 @@ public interface IServerInterceptor {
* operation is being invoked which is denoted by this request details.
*/
public void notifyIncomingRequestPreHandled(RestOperationTypeEnum theOperationType) {
for (IServerInterceptor next : getRequestDetails().getServer().getInterceptors()) {
RequestDetails requestDetails = getRequestDetails();
if (requestDetails == null) {
return;
}
IRestfulServerDefaults server = requestDetails.getServer();
if (server == null) {
return;
}
List<IServerInterceptor> interceptors = server.getInterceptors();
for (IServerInterceptor next : interceptors) {
next.incomingRequestPreHandled(theOperationType, this);
}
}

View File

@ -18,6 +18,7 @@ import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.AfterClass;
import org.junit.Before;
import org.mockito.Mockito;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.TransactionCallback;
@ -50,6 +51,7 @@ import ca.uhn.fhir.model.dstu2.resource.Bundle;
import ca.uhn.fhir.model.dstu2.resource.Bundle.Entry;
import ca.uhn.fhir.rest.method.IRequestOperationCallback;
import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.interceptor.IServerInterceptor;
import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
import ca.uhn.fhir.util.TestUtil;
@ -71,8 +73,9 @@ public class BaseJpaTest {
@Before
public void beforeCreateSrd() {
mySrd = mock(ServletRequestDetails.class);
mySrd = mock(ServletRequestDetails.class, Mockito.RETURNS_DEEP_STUBS);
when(mySrd.getRequestOperationCallback()).thenReturn(mock(IRequestOperationCallback.class));
when(mySrd.getServer().getInterceptors()).thenReturn(new ArrayList<IServerInterceptor>());
}
protected List<IIdType> toUnqualifiedVersionlessIds(Bundle theFound) {

View File

@ -9,7 +9,6 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import java.io.InputStream;
import java.io.InputStreamReader;
@ -46,7 +45,6 @@ import ca.uhn.fhir.model.dstu.resource.Patient;
import ca.uhn.fhir.model.dstu2.composite.MetaDt;
import ca.uhn.fhir.model.primitive.IdDt;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.rest.method.RequestDetails;
import ca.uhn.fhir.rest.param.TokenParam;
import ca.uhn.fhir.rest.server.IBundleProvider;
import ca.uhn.fhir.rest.server.exceptions.InvalidRequestException;
@ -61,7 +59,6 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
private static IFhirResourceDao<Observation> ourObservationDao;
private static IFhirResourceDao<Patient> ourPatientDao;
private static IFhirSystemDao<List<IResource>, MetaDt> ourSystemDao;
private RequestDetails myRequestDetails;
private static EntityManager ourEntityManager;
private static PlatformTransactionManager ourTxManager;
@ -74,7 +71,6 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
@Before
public void before() {
myRequestDetails = mock(RequestDetails.class);
super.purgeDatabase(ourEntityManager, ourTxManager);
}
@ -163,7 +159,7 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
obs.getName().addCoding().setSystem("urn:system").setCode("testPersistWithSimpleLinkO01");
obs.setSubject(new ResourceReferenceDt("Patient/testPersistWithSimpleLinkP01"));
ourSystemDao.transaction(myRequestDetails, Arrays.asList((IResource) patient, obs));
ourSystemDao.transaction(mySrd, Arrays.asList((IResource) patient, obs));
String patientId = (patient.getId().getIdPart());
String obsId = (obs.getId().getIdPart());
@ -192,7 +188,7 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
patient.addIdentifier().setSystem("urn:system").setValue("testPersistWithSimpleLinkP02");
obs.getName().addCoding().setSystem("urn:system").setCode("testPersistWithSimpleLinkO02");
ourSystemDao.transaction(myRequestDetails, Arrays.asList((IResource) patient, obs));
ourSystemDao.transaction(mySrd, Arrays.asList((IResource) patient, obs));
String patientId2 = (patient.getId().getIdPart());
String patientVersion2 = (patient.getId().getVersionIdPart());
@ -213,7 +209,7 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
obs.setSubject(new ResourceReferenceDt("Patient/999998888888"));
try {
ourSystemDao.transaction(myRequestDetails, Arrays.asList((IResource) obs));
ourSystemDao.transaction(mySrd, Arrays.asList((IResource) obs));
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), containsString("Resource Patient/999998888888 not found, specified in path: Observation.subject"));
}
@ -223,7 +219,7 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
obs.setSubject(new ResourceReferenceDt("Patient/1.2.3.4"));
try {
ourSystemDao.transaction(myRequestDetails, Arrays.asList((IResource) obs));
ourSystemDao.transaction(mySrd, Arrays.asList((IResource) obs));
} catch (InvalidRequestException e) {
assertThat(e.getMessage(), containsString("Resource Patient/1.2.3.4 not found, specified in path: Observation.subject"));
}
@ -313,7 +309,7 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
patient2.setId(new IdDt("Patient/testTransactionFailsWithDusplicateIds"));
patient2.addIdentifier().setSystem("urn:system").setValue("testPersistWithSimpleLinkP02");
ourSystemDao.transaction(myRequestDetails, Arrays.asList((IResource) patient1, patient2));
ourSystemDao.transaction(mySrd, Arrays.asList((IResource) patient1, patient2));
}
@Test
@ -323,7 +319,7 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
Bundle bundle = ourFhirContext.newXmlParser().parseBundle(new InputStreamReader(bundleRes));
List<IResource> res = bundle.toListOfResources();
ourSystemDao.transaction(myRequestDetails, res);
ourSystemDao.transaction(mySrd, res);
Patient p1 = (Patient) res.get(0);
String id = p1.getId().getValue();
@ -356,7 +352,7 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
o2.setSubject(new ResourceReferenceDt("Patient/cid:patient1"));
res.add(o2);
ourSystemDao.transaction(myRequestDetails, res);
ourSystemDao.transaction(mySrd, res);
assertTrue(p1.getId().getValue(), p1.getId().getIdPart().matches("^[0-9]+$"));
assertTrue(o1.getId().getValue(), o1.getId().getIdPart().matches("^[0-9]+$"));
@ -378,7 +374,7 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
res.add(next.getResource());
}
List<IResource> response = ourSystemDao.transaction(myRequestDetails, res);
List<IResource> response = ourSystemDao.transaction(mySrd, res);
String encodeResourceToString = ourFhirContext.newXmlParser().setPrettyPrint(true).encodeResourceToString(response.get(0));
ourLog.info(encodeResourceToString);
@ -411,7 +407,7 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
o2.setSubject(new ResourceReferenceDt("cid:patient1"));
res.add(o2);
ourSystemDao.transaction(myRequestDetails, res);
ourSystemDao.transaction(mySrd, res);
assertTrue(p1.getId().getValue(), p1.getId().getIdPart().matches("^[0-9]+$"));
assertTrue(o1.getId().getValue(), o1.getId().getIdPart().matches("^[0-9]+$"));
@ -444,7 +440,7 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
p3.addIdentifier().setSystem("urn:system").setValue("testTransactionWithDelete");
res.add(p3);
ourSystemDao.transaction(myRequestDetails, res);
ourSystemDao.transaction(mySrd, res);
/*
* Verify
@ -470,7 +466,7 @@ public class FhirSystemDaoDstu1Test extends BaseJpaTest {
ResourceMetadataKeyEnum.DELETED_AT.put(p2, InstantDt.withCurrentTime());
res.add(p2);
ourSystemDao.transaction(myRequestDetails, res);
ourSystemDao.transaction(mySrd, res);
/*
* Verify

View File

@ -66,6 +66,7 @@ import ca.uhn.fhir.util.TestUtil;
public class AuthorizationInterceptorDstu2Test {
private static final String ERR403 = "<OperationOutcome xmlns=\"http://hl7.org/fhir\"><issue><severity value=\"error\"/><code value=\"processing\"/><diagnostics value=\"Access denied by default policy (no applicable rules)\"/></issue></OperationOutcome>";
private static CloseableHttpClient ourClient;
private static FhirContext ourCtx = FhirContext.forDstu2();
private static boolean ourHitMethod;
@ -325,7 +326,7 @@ public class AuthorizationInterceptorDstu2Test {
status = ourClient.execute(httpPost);
response = extractResponseAndClose(status);
assertEquals(403, status.getStatusLine().getStatusCode());
assertThat(response, containsString("Invalid transaction bundle type: collection"));
assertEquals(ERR403, response);
}
@Test
@ -572,7 +573,7 @@ public class AuthorizationInterceptorDstu2Test {
httpPost.setEntity(createFhirResourceEntity(createPatient(null)));
status = ourClient.execute(httpPost);
String response = extractResponseAndClose(status);
assertEquals("Access denied by default policy (no applicable rules)", response);
assertEquals(ERR403, response);
assertEquals(403, status.getStatusLine().getStatusCode());
assertFalse(ourHitMethod);
@ -581,7 +582,7 @@ public class AuthorizationInterceptorDstu2Test {
httpPost.setEntity(createFhirResourceEntity(createObservation(null, "Patient/2")));
status = ourClient.execute(httpPost);
response = extractResponseAndClose(status);
assertEquals("Access denied by default policy (no applicable rules)", response);
assertEquals(ERR403, response);
assertEquals(403, status.getStatusLine().getStatusCode());
assertFalse(ourHitMethod);
@ -650,7 +651,7 @@ public class AuthorizationInterceptorDstu2Test {
httpPost.setEntity(createFhirResourceEntity(createPatient(2)));
status = ourClient.execute(httpPost);
String response = extractResponseAndClose(status);
assertEquals("Access denied by default policy (no applicable rules)", response);
assertEquals(ERR403, response);
assertEquals(403, status.getStatusLine().getStatusCode());
assertFalse(ourHitMethod);
@ -675,7 +676,7 @@ public class AuthorizationInterceptorDstu2Test {
httpPost.setEntity(createFhirResourceEntity(createObservation(10, "Patient/2")));
status = ourClient.execute(httpPost);
response = extractResponseAndClose(status);
assertEquals("Access denied by default policy (no applicable rules)", response);
assertEquals(ERR403, response);
assertEquals(403, status.getStatusLine().getStatusCode());
assertFalse(ourHitMethod);
}

View File

@ -1065,7 +1065,7 @@ public class XmlParserDstu3Test {
public void testEncodeExtensionWithContainedResource() {
TestPatientFor327 patient = new TestPatientFor327();
patient.setBirthDate(new Date());
patient.setBirthDateElement(new DateType("2016-04-14"));
List<Reference> conditions = new ArrayList<Reference>();
Condition condition = new Condition();

View File

@ -923,7 +923,7 @@ public class XmlParserHl7OrgDstu2Test {
public void testEncodeExtensionWithContainedResource() {
TestPatientFor327 patient = new TestPatientFor327();
patient.setBirthDate(new Date());
patient.setBirthDateElement(new DateType("2016-04-14"));
List<Reference> conditions = new ArrayList<Reference>();
Condition condition = new Condition();

View File

@ -1,5 +1,7 @@
package ca.uhn.fhir.tinder.model;
import static org.apache.commons.lang3.StringUtils.isNotBlank;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -84,8 +86,10 @@ public class SearchParameter {
}
} else {
if (myType == null) {
if (isNotBlank(myName)) {
ourLog.warn("Search parameter {} has no type", myName);
}
}
if ("resource".equals(myType) || "reference".equals(myType)) {
retVal.add(new Include(myResourceName + ":" + myName));
}

View File

@ -516,8 +516,9 @@ public abstract class BaseStructureParser {
}
if (!myImportsResolved) {
ourLog.info("Scanning resources for imports...");
for (BaseRootType next : myResources) {
ourLog.info("Scanning resource for imports {}", next.getName());
ourLog.debug("Scanning resource for imports {}", next.getName());
scanForImportsNames(next);
}
myImportsResolved = true;

View File

@ -56,7 +56,7 @@ public abstract class BaseStructureSpreadsheetParser extends BaseStructureParser
for (InputStream nextInputStream : getInputStreams()) {
String spreadsheetName = getInputStreamNames().get(index);
ourLog.info("Reading spreadsheet file {}", spreadsheetName);
ourLog.debug("Reading spreadsheet file {}", spreadsheetName);
Document file;
try {

View File

@ -35,7 +35,7 @@ public class CompartmentParser {
throw new MojoFailureException("Unknown base resource name: " + resName);
}
ourLog.info("Reading spreadsheet file {}", resName);
ourLog.debug("Reading compartment file {}", resName);
Document file;
try {

14
pom.xml
View File

@ -245,7 +245,7 @@
<!-- Dependency Versions -->
<derby_version>10.12.1.1</derby_version>
<jersey_version>2.22.2</jersey_version>
<jetty_version>9.3.7.v20160115 </jetty_version>
<jetty_version>9.3.8.v20160314</jetty_version>
<!-- Note on Hibernate versions: Hibernate 4.3+ uses JPA 2.1, which is too new for a number of platforms including JBoss EAP 6.x and Glassfish 3.0. Upgrade this version with caution! Also note that if
you change this, you may get a failure in hibernate4-maven-plugin. See the note in hapi-fhir-jpaserver-base/pom.xml's configuration for that plugin... -->
<hibernate_version>5.1.0.Final</hibernate_version>
@ -567,17 +567,17 @@
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-android</artifactId>
<version>1.7.16</version>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.16</version>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>1.7.16</version>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
@ -690,7 +690,7 @@
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>2.0.8</version>
<version>2.0.9</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
@ -781,7 +781,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>animal-sniffer-maven-plugin</artifactId>
<version>1.14</version>
<version>1.15</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
@ -972,7 +972,7 @@
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>6.15</version>
<version>6.17</version>
</dependency>
</dependencies>
<configuration>

View File

@ -14,7 +14,7 @@
<ul>
<li>Hibernate (JPA, Web Tester): 5.0.7 -&gt; 5.1.0</li>
<li>Spring (JPA, Web Tester): 4.2.4 -&gt; 4.2.5</li>
<li>SLF4j (All): 1.7.14 -&gt; 1.7.16</li>
<li>SLF4j (All): 1.7.14 -&gt; 1.7.21</li>
</ul>
]]>
</action>