Search in sources :

Example 1 with FHIRHandler

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();
}
Also used : DPCFHIRConfiguration(gov.cms.dpc.fhir.configuration.DPCFHIRConfiguration) FHIRHandler(gov.cms.dpc.fhir.dropwizard.handlers.FHIRHandler) AuthValueFactoryProvider(io.dropwizard.auth.AuthValueFactoryProvider) DefaultProfileValidationSupport(org.hl7.fhir.dstu3.hapi.ctx.DefaultProfileValidationSupport) FHIRValidatorProvider(gov.cms.dpc.fhir.validations.dropwizard.FHIRValidatorProvider) JsonParseExceptionMapper(gov.cms.dpc.api.exceptions.JsonParseExceptionMapper) BundleHandler(gov.cms.dpc.fhir.dropwizard.handlers.BundleHandler) ProfileValidator(gov.cms.dpc.fhir.validations.ProfileValidator) GrizzlyWebTestContainerFactory(org.glassfish.jersey.test.grizzly.GrizzlyWebTestContainerFactory) OrganizationPrincipal(gov.cms.dpc.api.auth.OrganizationPrincipal) DPCProfileSupport(gov.cms.dpc.fhir.validations.DPCProfileSupport) JerseyExceptionHandler(gov.cms.dpc.fhir.dropwizard.handlers.exceptions.JerseyExceptionHandler) HAPIExceptionHandler(gov.cms.dpc.fhir.dropwizard.handlers.exceptions.HAPIExceptionHandler) ValidationSupportChain(org.hl7.fhir.dstu3.hapi.validation.ValidationSupportChain) InjectingConstraintValidatorFactory(gov.cms.dpc.fhir.validations.dropwizard.InjectingConstraintValidatorFactory)

Aggregations

OrganizationPrincipal (gov.cms.dpc.api.auth.OrganizationPrincipal)1 JsonParseExceptionMapper (gov.cms.dpc.api.exceptions.JsonParseExceptionMapper)1 DPCFHIRConfiguration (gov.cms.dpc.fhir.configuration.DPCFHIRConfiguration)1 BundleHandler (gov.cms.dpc.fhir.dropwizard.handlers.BundleHandler)1 FHIRHandler (gov.cms.dpc.fhir.dropwizard.handlers.FHIRHandler)1 HAPIExceptionHandler (gov.cms.dpc.fhir.dropwizard.handlers.exceptions.HAPIExceptionHandler)1 JerseyExceptionHandler (gov.cms.dpc.fhir.dropwizard.handlers.exceptions.JerseyExceptionHandler)1 DPCProfileSupport (gov.cms.dpc.fhir.validations.DPCProfileSupport)1 ProfileValidator (gov.cms.dpc.fhir.validations.ProfileValidator)1 FHIRValidatorProvider (gov.cms.dpc.fhir.validations.dropwizard.FHIRValidatorProvider)1 InjectingConstraintValidatorFactory (gov.cms.dpc.fhir.validations.dropwizard.InjectingConstraintValidatorFactory)1 AuthValueFactoryProvider (io.dropwizard.auth.AuthValueFactoryProvider)1 GrizzlyWebTestContainerFactory (org.glassfish.jersey.test.grizzly.GrizzlyWebTestContainerFactory)1 DefaultProfileValidationSupport (org.hl7.fhir.dstu3.hapi.ctx.DefaultProfileValidationSupport)1 ValidationSupportChain (org.hl7.fhir.dstu3.hapi.validation.ValidationSupportChain)1