@Test void webConfiguration() { WebApplicationContextRunner webContextRunner = new WebApplicationContextRunner() .withConfiguration( AutoConfigurations.of(RestTemplateAutoConfiguration.class, JacksonAutoConfiguration.class, HttpMessageConvertersAutoConfiguration.class, WebMvcAutoConfiguration.class, InitializrAutoConfiguration.class)); webContextRunner.run((context) -> { assertThat(context).hasSingleBean(InitializrWebConfig.class); assertThat(context).hasSingleBean(MainController.class); assertThat(context).hasSingleBean(UiController.class); }); }
/** * Create a new {@link WebApplicationContextRunner} instance using an * {@link AnnotationConfigWebApplicationContext} with a {@link MockServletContext} as * the underlying source. * @see #withMockServletContext(Supplier) */ public WebApplicationContextRunner() { this(withMockServletContext(AnnotationConfigWebApplicationContext::new)); }
private WebApplicationContextRunner webApplicationContextRunner() { return new WebApplicationContextRunner().withConfiguration( AutoConfigurations.of(ServiceBrokerWebMvcAutoConfiguration.class, ServiceBrokerWebFluxAutoConfiguration.class)); }
@Test public void testAddedWhenCommons() { this.webApplicationContextRunner .withPropertyValues("joinfaces.primefaces.uploader=commons") .run(context -> { assertThat(context).hasSingleBean(FileUploadFilter.class); }); }
@Test public void requestContextFilter() { this.webApplicationContextRunner.run(context -> { assertThat(context).hasSingleBean(RequestContextFilter.class); }); } }
@Test public void controllersAreCreated() { webApplicationContextRunner() .withUserConfiguration(FullServicesConfiguration.class) .run((context) -> { assertThat(context).hasSingleBean(CatalogController.class); assertThat(context).hasSingleBean(ServiceInstanceController.class); assertThat(context).hasSingleBean(ServiceInstanceBindingController.class); }); }
@Test public void apiVersionCheckIsDisabled() { webApplicationContextRunner() .withUserConfiguration(ServicesConfiguration.class) .withPropertyValues("spring.cloud.openservicebroker.api-version-check-enabled=false") .run((context) -> assertThat(context).doesNotHaveBean(BrokerApiVersion.class)); }
@Override protected WebApplicationContextRunner newInstance( Supplier<ConfigurableWebApplicationContext> contextFactory, List<ApplicationContextInitializer<? super ConfigurableWebApplicationContext>> initializers, TestPropertyValues environmentProperties, TestPropertyValues systemProperties, ClassLoader classLoader, ApplicationContext parent, List<Configurations> configurations) { return new WebApplicationContextRunner(contextFactory, initializers, environmentProperties, systemProperties, classLoader, parent, configurations); }
@Test public void testDisabledByMissingEntityManagerClass() { this.webApplicationContextRunner .withClassLoader(new FilteredClassLoader(EntityManager.class)) .run(context -> { assertThat(context).doesNotHaveBean(OpenEntityManagerInViewInterceptor.class); assertThat(context).doesNotHaveBean(OpenEntityManagerInViewFilter.class); }); } }
private WebApplicationContextRunner webApplicationContextRunner() { return new WebApplicationContextRunner().withConfiguration( AutoConfigurations.of(ApiVersionWebMvcAutoConfiguration.class, ApiVersionWebFluxAutoConfiguration.class)); }
@Test public void testExplicitMappingTakesPrecedence() { this.webApplicationContextRunner .withPropertyValues("joinfaces.jsf.project-stage=UnitTest") .run(context -> assertThat(context.getBean(JavaxFaces2_0Properties.class).getProjectStage()).isEqualTo(ProjectStage.UnitTest) ); this.webApplicationContextRunner .withPropertyValues("debug", "joinfaces.jsf.project-stage=UnitTest") .run(context -> assertThat(context.getBean(JavaxFaces2_0Properties.class).getProjectStage()).isEqualTo(ProjectStage.UnitTest) ); }
@Test public void testNotAdded() { this.webApplicationContextRunner .run(context -> { assertThat(context).doesNotHaveBean(FileUploadFilter.class); }); } }
@Test public void apiVersionBeansAreCreatedFromCustomVersionProperty() { webApplicationContextRunner() .withUserConfiguration(ServicesConfiguration.class, CustomBrokerApiVersionConfigurationFromProperty.class) .run((context) -> { assertThat(context).getBean(BrokerApiVersion.class) .hasFieldOrPropertyWithValue("apiVersion", "42.321"); assertThat(context).hasSingleBean(ApiVersionInterceptor.class); assertThat(context).hasSingleBean(ApiVersionWebMvcConfigurerAdapter.class); }); }
@BeforeEach public void setUp() { this.webApplicationContextRunner = new WebApplicationContextRunner() .withConfiguration(AutoConfigurations.of(RewriteAutoConfiguration.class, FooConfiguration.class)); }
@Test public void testDisabledByProperty() { this.webApplicationContextRunner .withPropertyValues("spring.jpa.open-in-view=false") .run(context -> { assertThat(context).doesNotHaveBean(OpenEntityManagerInViewInterceptor.class); assertThat(context).doesNotHaveBean(OpenEntityManagerInViewFilter.class); }); }
@Test public void testInterceptorReplacedByFilter() { this.webApplicationContextRunner.run(context -> { assertThat(context).doesNotHaveBean(OpenEntityManagerInViewInterceptor.class); assertThat(context).hasSingleBean(OpenEntityManagerInViewFilter.class); }); }
@Test public void apiVersionBeansAreCreatedWithDefault() { webApplicationContextRunner() .withUserConfiguration(ServicesConfiguration.class) .run((context) -> { assertThat(context).getBean(BrokerApiVersion.class) .hasFieldOrPropertyWithValue("apiVersion", API_VERSION_ANY); assertThat(context).hasSingleBean(ApiVersionInterceptor.class); assertThat(context).hasSingleBean(ApiVersionWebMvcConfigurerAdapter.class); }); }
@BeforeEach public void setUp() { this.webApplicationContextRunner = new WebApplicationContextRunner() .withConfiguration(AutoConfigurations.of(AngularfacesAutoConfiguration.class, JavaxFacesAutoConfiguration.class)); }
@Test public void testDevelopmentWhenDebug() { this.webApplicationContextRunner .withPropertyValues("debug") .run(context -> assertThat(context.getBean(JavaxFaces2_0Properties.class).getProjectStage()).isEqualTo(ProjectStage.Development) ); }
@Test public void controllersAreNotCreatedWithoutRequiredServices() { webApplicationContextRunner() .run(context -> assertThat(context.getStartupFailure()) .isInstanceOf(UnsatisfiedDependencyException.class)); }