-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP Test Framework #437
WIP Test Framework #437
Conversation
import ca.uhn.fhir.context.FhirContext; | ||
import ca.uhn.fhir.jpa.api.dao.DaoRegistry; | ||
|
||
public class DaoRegistryOperationProvider implements OperationProvider, DaoRegistryUser, FhirContextUser { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a new class that provides CRUD helpers out of the box.
|
||
public static <CanonicalType extends IPrimitiveType<String>> String getId(CanonicalType theCanonicalType) { | ||
checkNotNull(theCanonicalType); | ||
checkArgument(theCanonicalType.getValue() != null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are examples of validating inputs to public APIs. Validate inputs as the very first step in a function.
/** | ||
* Simulate FhirDal operations until such time as that is fully baked | ||
*/ | ||
public interface DaoRegistryUser { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're working through an implementation of a common API for Java FHIR access. This interface approximates that so it's easier to get convergence when that finally happens.
|
||
public interface ResourceCreator extends FhirContextUser { | ||
@SuppressWarnings("unchecked") | ||
default <T extends IBaseResource, I extends IIdType> T newResource(I theId) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a helper that lets you create a new resource of the correct type and version based only on the id.
private Searches() { | ||
} | ||
|
||
public static SearchParameterMap all() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Find all resources (when combined with the Dao API above)
search(Measure.class, Searches.all())
import ca.uhn.fhir.rest.param.StringParam; | ||
import ca.uhn.fhir.rest.param.UriParam; | ||
|
||
public class Searches { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a set of utilities to construct commonly needed search parameter maps.
for (IBaseResource baseBundle : bundles) { | ||
if (baseBundle instanceof Bundle) { | ||
Bundle bundle = (Bundle) baseBundle; | ||
List<Bundle> bundles = search(Bundle.class, Searches.all()).getAllResourcesTyped(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line combines the Search API with the new TypedBundleProvider. Compare to the previous code.
throw new RuntimeException("Could not find Group/" + subjectGroupRef); | ||
} | ||
Group group = (Group) baseGroup; | ||
Group group = read(new IdType(subjectGroupRef)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's another example to compare to the previous code.
@@ -149,9 +132,9 @@ private void gatherPatientsFromReport(MeasureReport report, Map<String, Referenc | |||
logger.debug("No subject results found."); | |||
return results; | |||
} | |||
IBaseResource baseList = myDaoRegistry.getResourceDao(subjectResults.getReferenceElement().getResourceType()).read(subjectResults.getReferenceElement()); | |||
IBaseResource baseList = read(subjectResults.getReferenceElement()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And one more example to compare to the old code.
if (baseList == null) { | ||
logger.debug(String.format("No subject results found for: %s", subjectResults.getReference())); | ||
logger.debug("No subject results found for: {}", subjectResults.getReference()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was quite a bit of this too. The loggers accept a string format and parameters, so no need to pre-format it.
"hapi.fhir.enforce_referential_integrity_on_write=false", | ||
}) | ||
@EnableAutoConfiguration(exclude=QuartzAutoConfiguration.class) | ||
public class SubmitDataProviderIT extends DaoIntegrationTest implements IdCreator, ResourceCreator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm working on collapsing all the cruft from above into the base classes. Then the body of the tests will become the focus of the code.
SubmitDataProvider mySubmitDataProvider; | ||
|
||
@Test | ||
public void testSubmitData() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An example of using a few of the utilities to round-trip the database in just a few lines of code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a lot here to fully digest. Will adopt patterns in future implementations.
…into feature-plugins-test-framework
In starting to build the submit-data tests and reviewing the work that's been done so far it became obvious that I hadn't provided quite enough guidance on testing or on building out shared components. This is a PR to fix a few of those things:
Read the documentation in the base README
A concrete example for usage of some of the new classes:
Still to do: