use of gov.cms.dpc.fhir.dropwizard.handlers.FHIRHandler in project dpc-app by CMSgov.
the class APITestHelpers method buildResourceExtension.
/**
* Build Dropwizard test instance with a specific subset of Resources and Providers
*
* @param ctx - {@link FhirContext} context to use
* @param resources - {@link List} of resources to add to test instance
* @param providers - {@link List} of providers to add to test instance
* @param validation - {@code true} enable custom validation. {@code false} Disable custom validation
* @return - {@link ResourceExtension}
*/
public static ResourceExtension buildResourceExtension(FhirContext ctx, List<Object> resources, List<Object> providers, boolean validation) {
final FHIRHandler fhirHandler = new FHIRHandler(ctx);
final var builder = ResourceExtension.builder().setRegisterDefaultExceptionMappers(false).setTestContainerFactory(new GrizzlyWebTestContainerFactory()).addProvider(fhirHandler).addProvider(new BundleHandler(fhirHandler)).addProvider(JerseyExceptionHandler.class).addProvider(PersistenceExceptionHandler.class).addProvider(HAPIExceptionHandler.class).addProvider(DefaultFHIRExceptionHandler.class).addProvider(JsonParseExceptionMapper.class).addProvider(new AuthValueFactoryProvider.Binder<>(OrganizationPrincipal.class));
// Optionally enable validation
if (validation) {
// Validation config
final DPCFHIRConfiguration.FHIRValidationConfiguration config = new DPCFHIRConfiguration.FHIRValidationConfiguration();
config.setEnabled(true);
config.setSchematronValidation(true);
config.setSchemaValidation(true);
final DPCProfileSupport dpcModule = new DPCProfileSupport(ctx);
final ValidationSupportChain support = new ValidationSupportChain(new DefaultProfileValidationSupport(), dpcModule);
final InjectingConstraintValidatorFactory constraintFactory = new InjectingConstraintValidatorFactory(Set.of(new ProfileValidator(new FHIRValidatorProvider(ctx, config, support).get())));
builder.setValidator(provideValidator(constraintFactory));
}
resources.forEach(builder::addResource);
providers.forEach(builder::addProvider);
return builder.build();
}
Aggregations