Skip to content

Commit

Permalink
Merge pull request hapifhir#987 from jamesagnew/983-ci-failures
Browse files Browse the repository at this point in the history
983 ci failures
  • Loading branch information
jamesagnew authored Jun 6, 2018
2 parents f20371c + 6feb238 commit b61a3cc
Show file tree
Hide file tree
Showing 11 changed files with 101 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -959,6 +959,11 @@ protected DaoConfig getConfig() {

@Override
public void setApplicationContext(ApplicationContext theApplicationContext) throws BeansException {
/*
* We do a null check here because Smile's module system tries to
* initialize the application context twice if two modules depend on
* the persistence module. The second time sets the dependency's appctx.
*/
if (myApplicationContext == null) {
myApplicationContext = theApplicationContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.hamcrest.Matchers;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.hl7.fhir.r4.model.Bundle;
Expand All @@ -35,6 +36,7 @@
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.stream.Collectors;

import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.*;
Expand Down Expand Up @@ -174,12 +176,6 @@ public void testCreateResource() throws IOException {
ResourceProviderInterceptorR4Test.verifyDaoInterceptor(myDaoInterceptor);
}

/*
* This is a weird way of verifying, but because this class
* is a child of a superclass that has other test children
* it's possible that other tests are hitting the server
* at the same time
*/
@Test
public void testCreateResourceInTransaction() throws IOException {
String methodName = "testCreateResourceInTransaction";
Expand Down Expand Up @@ -220,15 +216,17 @@ public void testCreateResourceInTransaction() throws IOException {
* DAO Interceptor
*/

/*
* Sometimes we get more than 2 hits of the incomingRequestPreHandled
* method. My working theory is that it's a scheduled background job,
* such as the subscription interceptor or the search parameter cache
* updating.
*/
ardCaptor = ArgumentCaptor.forClass(ActionRequestDetails.class);
opTypeCaptor = ArgumentCaptor.forClass(RestOperationTypeEnum.class);
verify(myDaoInterceptor, times(2)).incomingRequestPreHandled(opTypeCaptor.capture(), ardCaptor.capture());
assertEquals(RestOperationTypeEnum.TRANSACTION, opTypeCaptor.getAllValues().get(0));
assertEquals("Bundle", ardCaptor.getAllValues().get(0).getResourceType());
assertNotNull(ardCaptor.getAllValues().get(0).getResource());
assertEquals(RestOperationTypeEnum.CREATE, opTypeCaptor.getAllValues().get(1));
assertEquals("Patient", ardCaptor.getAllValues().get(1).getResourceType());
assertNotNull(ardCaptor.getAllValues().get(1).getResource());
verify(myDaoInterceptor, atLeast(2)).incomingRequestPreHandled(opTypeCaptor.capture(), ardCaptor.capture());
assertThat(ardCaptor.getAllValues().stream().map(ActionRequestDetails::getResourceType).collect(Collectors.toList()), Matchers.contains("Bundle", "Patient"));
assertThat(opTypeCaptor.getAllValues(), Matchers.contains(RestOperationTypeEnum.TRANSACTION, RestOperationTypeEnum.CREATE));

rdCaptor = ArgumentCaptor.forClass(RequestDetails.class);
srCaptor = ArgumentCaptor.forClass(HttpServletRequest.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface IServerConformanceProvider<T extends IBaseResource> {
*
* See the class documentation for an important note if you are extending this class
*/
public abstract T getServerConformance(HttpServletRequest theRequest);
T getServerConformance(HttpServletRequest theRequest);

/**
* This setter is needed in implementation classes (along with
Expand All @@ -40,5 +40,5 @@ public interface IServerConformanceProvider<T extends IBaseResource> {
*
* @param theRestfulServer
*/
public void setRestfulServer(RestfulServer theRestfulServer);
void setRestfulServer(RestfulServer theRestfulServer);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -26,6 +26,7 @@
import ca.uhn.fhir.context.RuntimeResourceDefinition;
import ca.uhn.fhir.context.api.AddProfileTagEnum;
import ca.uhn.fhir.context.api.BundleInclusionRule;
import ca.uhn.fhir.model.primitive.InstantDt;
import ca.uhn.fhir.parser.IParser;
import ca.uhn.fhir.rest.annotation.Destroy;
import ca.uhn.fhir.rest.annotation.IdParam;
Expand Down Expand Up @@ -125,6 +126,7 @@ public class RestfulServer extends HttpServlet implements IRestfulServer<Servlet
private boolean myUncompressIncomingContents = true;
private boolean myUseBrowserFriendlyContentTypes;
private ITenantIdentificationStrategy myTenantIdentificationStrategy;
private Date myConformanceDate;

/**
* Constructor. Note that if no {@link FhirContext} is passed in to the server (either through the constructor, or
Expand Down Expand Up @@ -194,19 +196,14 @@ public RestulfulServerConfiguration createConfiguration() {
result.setServerName(getServerName());
result.setFhirContext(getFhirContext());
result.setServerAddressStrategy(myServerAddressStrategy);
InputStream inputStream = null;
try {
inputStream = getClass().getResourceAsStream("/META-INF/MANIFEST.MF");
try (InputStream inputStream = getClass().getResourceAsStream("/META-INF/MANIFEST.MF")) {
if (inputStream != null) {
Manifest manifest = new Manifest(inputStream);
result.setConformanceDate(manifest.getMainAttributes().getValue("Build-Time"));
String value = manifest.getMainAttributes().getValue("Build-Time");
result.setConformanceDate(new InstantDt(value));
}
} catch (IOException e) {
} catch (Exception e) {
// fall through
} finally {
if (inputStream != null) {
IOUtils.closeQuietly(inputStream);
}
}
return result;
}
Expand Down Expand Up @@ -573,10 +570,10 @@ public List<IServerInterceptor> getInterceptors() {
*
* @param theList The list of interceptors (may be null)
*/
public void setInterceptors(List<IServerInterceptor> theList) {
public void setInterceptors(IServerInterceptor... theList) {
myInterceptors.clear();
if (theList != null) {
myInterceptors.addAll(theList);
myInterceptors.addAll(Arrays.asList(theList));
}
}

Expand Down Expand Up @@ -606,8 +603,11 @@ public Collection<Object> getPlainProviders() {
*
* @see #setResourceProviders(Collection)
*/
public void setPlainProviders(Object... theProv) {
setPlainProviders(Arrays.asList(theProv));
public void setPlainProviders(Collection<Object> theProviders) {
myPlainProviders.clear();
if (theProviders != null) {
myPlainProviders.addAll(theProviders);
}
}

/**
Expand Down Expand Up @@ -637,10 +637,10 @@ public Collection<IResourceProvider> getResourceProviders() {
/**
* Sets the resource providers for this server
*/
public void setResourceProviders(IResourceProvider... theResourceProviders) {
public void setResourceProviders(Collection<IResourceProvider> theResourceProviders) {
myResourceProviders.clear();
if (theResourceProviders != null) {
myResourceProviders.addAll(Arrays.asList(theResourceProviders));
myResourceProviders.addAll(theResourceProviders);
}
}

Expand Down Expand Up @@ -1518,10 +1518,10 @@ protected void service(HttpServletRequest theReq, HttpServletResponse theResp) t
*
* @param theList The list of interceptors (may be null)
*/
public void setInterceptors(IServerInterceptor... theList) {
public void setInterceptors(List<IServerInterceptor> theList) {
myInterceptors.clear();
if (theList != null) {
myInterceptors.addAll(Arrays.asList(theList));
myInterceptors.addAll(theList);
}
}

Expand All @@ -1530,11 +1530,8 @@ public void setInterceptors(IServerInterceptor... theList) {
*
* @see #setResourceProviders(Collection)
*/
public void setPlainProviders(Collection<Object> theProviders) {
myPlainProviders.clear();
if (theProviders != null) {
myPlainProviders.addAll(theProviders);
}
public void setPlainProviders(Object... theProv) {
setPlainProviders(Arrays.asList(theProv));
}

/**
Expand All @@ -1552,10 +1549,10 @@ public void setProviders(Object... theProviders) {
/**
* Sets the resource providers for this server
*/
public void setResourceProviders(Collection<IResourceProvider> theResourceProviders) {
public void setResourceProviders(IResourceProvider... theResourceProviders) {
myResourceProviders.clear();
if (theResourceProviders != null) {
myResourceProviders.addAll(theResourceProviders);
myResourceProviders.addAll(Arrays.asList(theResourceProviders));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
*/

import java.util.Collection;
import java.util.Date;
import java.util.List;

import ca.uhn.fhir.context.FhirContext;
import ca.uhn.fhir.rest.server.method.BaseMethodBinding;
import ca.uhn.fhir.util.VersionUtil;
import org.hl7.fhir.instance.model.api.IPrimitiveType;

import static org.apache.commons.lang3.StringUtils.isBlank;

Expand All @@ -38,7 +40,7 @@ public class RestulfulServerConfiguration {
private String serverName = "HAPI FHIR";
private FhirContext fhirContext;
private IServerAddressStrategy serverAddressStrategy;
private String conformanceDate;
private IPrimitiveType<Date> myConformanceDate;

/**
* Constructor
Expand Down Expand Up @@ -73,11 +75,10 @@ public List<BaseMethodBinding<?>> getServerBindings() {
}

/**
* Set the serverBindings
* @param serverBindings the serverBindings to set
* Set the theServerBindings
*/
public RestulfulServerConfiguration setServerBindings(List<BaseMethodBinding<?>> serverBindings) {
this.serverBindings = serverBindings;
public RestulfulServerConfiguration setServerBindings(List<BaseMethodBinding<?>> theServerBindings) {
this.serverBindings = theServerBindings;
return this;
}

Expand Down Expand Up @@ -166,23 +167,25 @@ public IServerAddressStrategy getServerAddressStrategy() {
*/
public void setServerAddressStrategy(IServerAddressStrategy serverAddressStrategy) {
this.serverAddressStrategy = serverAddressStrategy;
}
}


/**
* Get the conformanceDate
* @return the conformanceDate
*/
public String getConformanceDate() {
return conformanceDate;

/**
* Get the date that will be specified in the conformance profile
* exported by this server. Typically this would be populated with
* an InstanceType.
*/
public IPrimitiveType<Date> getConformanceDate() {
return myConformanceDate;
}

/**
* Set the conformanceDate
* @param conformanceDate the conformanceDate to set
* Set the date that will be specified in the conformance profile
* exported by this server. Typically this would be populated with
* an InstanceType.
*/
public void setConformanceDate(String conformanceDate) {
this.conformanceDate = conformanceDate;
public void setConformanceDate(IPrimitiveType<Date> theConformanceDate) {
myConformanceDate = theConformanceDate;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import ca.uhn.fhir.rest.server.method.*;
import ca.uhn.fhir.rest.server.method.OperationMethodBinding.ReturnType;
import ca.uhn.fhir.rest.server.method.SearchParameter;
import org.hl7.fhir.instance.model.api.IPrimitiveType;

/**
* Server FHIR Provider which serves the conformance statement for a RESTful server implementation
Expand Down Expand Up @@ -132,10 +133,10 @@ private Map<String, List<BaseMethodBinding<?>>> collectMethodBindings() {
}

private DateTimeType conformanceDate() {
String buildDate = getServerConfiguration().getConformanceDate();
if (buildDate != null) {
IPrimitiveType<Date> buildDate = getServerConfiguration().getConformanceDate();
if (buildDate != null && buildDate.getValue() != null) {
try {
return new DateTimeType(buildDate);
return new DateTimeType(buildDate.getValueAsString());
} catch (DataFormatException e) {
// fall through
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import ca.uhn.fhir.rest.server.method.OperationMethodBinding.ReturnType;
import org.apache.commons.lang3.StringUtils;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -136,10 +137,10 @@ private Map<String, List<BaseMethodBinding<?>>> collectMethodBindings() {
}

private DateTimeDt conformanceDate() {
String buildDate = getServerConfiguration().getConformanceDate();
if (buildDate != null) {
IPrimitiveType<Date> buildDate = getServerConfiguration().getConformanceDate();
if (buildDate != null && buildDate.getValue() != null) {
try {
return new DateTimeDt(buildDate);
return new DateTimeDt(buildDate.getValueAsString());
} catch (DataFormatException e) {
// fall through
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.hl7.fhir.dstu3.model.OperationDefinition.OperationParameterUse;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IPrimitiveType;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
Expand Down Expand Up @@ -76,7 +77,7 @@ public class ServerCapabilityStatementProvider implements IServerConformanceProv
private Callable<RestulfulServerConfiguration> myServerConfiguration;

/**
* No-arg constructor and seetter so that the ServerConfirmanceProvider can be Spring-wired with the RestfulService avoiding the potential reference cycle that would happen.
* No-arg constructor and setter so that the ServerConformanceProvider can be Spring-wired with the RestfulService avoiding the potential reference cycle that would happen.
*/
public ServerCapabilityStatementProvider() {
super();
Expand Down Expand Up @@ -139,10 +140,10 @@ private Map<String, List<BaseMethodBinding<?>>> collectMethodBindings() {
}

private DateTimeType conformanceDate() {
String buildDate = getServerConfiguration().getConformanceDate();
if (buildDate != null) {
IPrimitiveType<Date> buildDate = getServerConfiguration().getConformanceDate();
if (buildDate != null && buildDate.getValue() != null) {
try {
return new DateTimeType(buildDate);
return new DateTimeType(buildDate.getValueAsString());
} catch (DataFormatException e) {
// fall through
}
Expand Down
Loading

0 comments on commit b61a3cc

Please sign in to comment.