Java 类org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration 实例源码

项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JolokiaAutoConfigurationTests.java   
@Test
public void agentServletWithCustomPath() throws Exception {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context,
            "endpoints.jolokia.path=/foo/bar");
    this.context.register(EndpointsConfig.class, WebMvcAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            JolokiaAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBeanNamesForType(JolokiaMvcEndpoint.class)).hasSize(1);
    MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
    mockMvc.perform(MockMvcRequestBuilders.get("/foo/bar"))
            .andExpect(MockMvcResultMatchers.content()
                    .string(Matchers.containsString("\"request\":{\"type\"")));
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:EndpointWebMvcAutoConfigurationTests.java   
@Test
public void contextPath() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.applicationContext,
            "management.contextPath:/test");
    this.applicationContext.register(RootConfig.class, EndpointConfig.class,
            ServerPortConfig.class, PropertyPlaceholderAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class, JacksonAutoConfiguration.class,
            EmbeddedServletContainerAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class,
            EndpointWebMvcAutoConfiguration.class);
    this.applicationContext.refresh();
    assertContent("/controller", ports.get().server, "controlleroutput");
    assertContent("/test/endpoint", ports.get().server, "endpointoutput");
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:EndpointWebMvcAutoConfigurationTests.java   
@Test
public void overrideServerProperties() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.applicationContext,
            "server.displayName:foo");
    this.applicationContext.register(RootConfig.class, EndpointConfig.class,
            ServerPortConfig.class, PropertyPlaceholderAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class, JacksonAutoConfiguration.class,
            EmbeddedServletContainerAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class,
            EndpointWebMvcAutoConfiguration.class);
    this.applicationContext.refresh();
    assertContent("/controller", ports.get().server, "controlleroutput");
    ServerProperties serverProperties = this.applicationContext
            .getBean(ServerProperties.class);
    assertThat(serverProperties.getDisplayName()).isEqualTo("foo");
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ManagementWebSecurityAutoConfigurationTests.java   
@Test
public void testWebConfiguration() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class,
            WebMvcAutoConfiguration.class,
            ManagementWebSecurityAutoConfiguration.class,
            JacksonAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            EndpointAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    EnvironmentTestUtils.addEnvironment(this.context, "security.basic.enabled:false");
    this.context.refresh();
    assertThat(this.context.getBean(AuthenticationManagerBuilder.class)).isNotNull();
    FilterChainProxy filterChainProxy = this.context.getBean(FilterChainProxy.class);
    // 1 for static resources, one for management endpoints and one for the rest
    assertThat(filterChainProxy.getFilterChains()).hasSize(3);
    assertThat(filterChainProxy.getFilters("/beans")).isNotEmpty();
    assertThat(filterChainProxy.getFilters("/beans/")).isNotEmpty();
    assertThat(filterChainProxy.getFilters("/beans.foo")).isNotEmpty();
    assertThat(filterChainProxy.getFilters("/beans/foo/bar")).isNotEmpty();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:SitePreferenceAutoConfigurationTests.java   
@Test
public void sitePreferenceHandlerInterceptorRegistered() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(Config.class, WebMvcAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            SitePreferenceAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    RequestMappingHandlerMapping mapping = this.context
            .getBean(RequestMappingHandlerMapping.class);
    HandlerInterceptor[] interceptors = mapping
            .getHandler(new MockHttpServletRequest()).getInterceptors();
    assertThat(interceptors)
            .hasAtLeastOneElementOfType(SitePreferenceHandlerInterceptor.class);
}
项目:spring-boot-concourse    文件:EndpointWebMvcAutoConfigurationTests.java   
@Test
public void contextPath() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.applicationContext,
            "management.contextPath:/test");
    this.applicationContext.register(RootConfig.class, EndpointConfig.class,
            ServerPortConfig.class, PropertyPlaceholderAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class, JacksonAutoConfiguration.class,
            EmbeddedServletContainerAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class,
            EndpointWebMvcAutoConfiguration.class);
    this.applicationContext.refresh();
    assertContent("/controller", ports.get().server, "controlleroutput");
    assertContent("/test/endpoint", ports.get().server, "endpointoutput");
}
项目:spring-boot-concourse    文件:EndpointWebMvcAutoConfigurationTests.java   
@Test
public void overrideServerProperties() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.applicationContext,
            "server.displayName:foo");
    this.applicationContext.register(RootConfig.class, EndpointConfig.class,
            ServerPortConfig.class, PropertyPlaceholderAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class, JacksonAutoConfiguration.class,
            EmbeddedServletContainerAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class,
            EndpointWebMvcAutoConfiguration.class);
    this.applicationContext.refresh();
    assertContent("/controller", ports.get().server, "controlleroutput");
    ServerProperties serverProperties = this.applicationContext
            .getBean(ServerProperties.class);
    assertThat(serverProperties.getDisplayName()).isEqualTo("foo");
}
项目:spring-boot-concourse    文件:ManagementWebSecurityAutoConfigurationTests.java   
@Test
public void testWebConfiguration() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class,
            WebMvcAutoConfiguration.class,
            ManagementWebSecurityAutoConfiguration.class,
            JacksonAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            EndpointAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    EnvironmentTestUtils.addEnvironment(this.context, "security.basic.enabled:false");
    this.context.refresh();
    assertThat(this.context.getBean(AuthenticationManagerBuilder.class)).isNotNull();
    FilterChainProxy filterChainProxy = this.context.getBean(FilterChainProxy.class);
    // 1 for static resources, one for management endpoints and one for the rest
    assertThat(filterChainProxy.getFilterChains()).hasSize(3);
    assertThat(filterChainProxy.getFilters("/beans")).isNotEmpty();
    assertThat(filterChainProxy.getFilters("/beans/")).isNotEmpty();
    assertThat(filterChainProxy.getFilters("/beans.foo")).isNotEmpty();
    assertThat(filterChainProxy.getFilters("/beans/foo/bar")).isNotEmpty();
}
项目:spring-boot-concourse    文件:SitePreferenceAutoConfigurationTests.java   
@Test
public void sitePreferenceHandlerInterceptorRegistered() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(Config.class, WebMvcAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            SitePreferenceAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    RequestMappingHandlerMapping mapping = this.context
            .getBean(RequestMappingHandlerMapping.class);
    HandlerInterceptor[] interceptors = mapping
            .getHandler(new MockHttpServletRequest()).getInterceptors();
    assertThat(interceptors)
            .hasAtLeastOneElementOfType(SitePreferenceHandlerInterceptor.class);
}
项目:spring-boot-concourse    文件:DeviceDelegatingViewResolverAutoConfigurationTests.java   
@Test
public void deviceDelegatingThymeleafViewResolverEnabled() throws Exception {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context,
            "spring.mobile.devicedelegatingviewresolver.enabled:true");
    this.context.register(Config.class, WebMvcAutoConfiguration.class,
            ThymeleafAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            DeviceDelegatingViewResolverConfiguration.class);
    this.context.refresh();
    ThymeleafViewResolver thymeleafViewResolver = this.context
            .getBean(ThymeleafViewResolver.class);
    AbstractDeviceDelegatingViewResolver deviceDelegatingViewResolver = this.context
            .getBean("deviceDelegatingViewResolver",
                    AbstractDeviceDelegatingViewResolver.class);
    assertThat(thymeleafViewResolver).isNotNull();
    assertThat(deviceDelegatingViewResolver).isNotNull();
    assertThat(deviceDelegatingViewResolver.getViewResolver())
            .isInstanceOf(ThymeleafViewResolver.class);
    assertThat(this.context.getBean(InternalResourceViewResolver.class)).isNotNull();
    assertThat(this.context.getBean(ThymeleafViewResolver.class)).isNotNull();
    assertThat(deviceDelegatingViewResolver.getOrder())
            .isEqualTo(thymeleafViewResolver.getOrder() - 1);
}
项目:spring-boot-concourse    文件:DeviceDelegatingViewResolverAutoConfigurationTests.java   
@Test(expected = NoSuchBeanDefinitionException.class)
public void deviceDelegatingThymeleafViewResolverDisabled() throws Exception {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context,
            "spring.mobile.devicedelegatingviewresolver.enabled:false");
    this.context.register(Config.class, WebMvcAutoConfiguration.class,
            ThymeleafAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            DeviceDelegatingViewResolverConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBean(InternalResourceViewResolver.class)).isNotNull();
    assertThat(this.context.getBean(ThymeleafViewResolver.class)).isNotNull();
    this.context.getBean("deviceDelegatingViewResolver",
            AbstractDeviceDelegatingViewResolver.class);
}
项目:spring-boot-concourse    文件:DeviceDelegatingViewResolverAutoConfigurationTests.java   
@Test
public void defaultPropertyValues() throws Exception {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context,
            "spring.mobile.devicedelegatingviewresolver.enabled:true");
    this.context.register(Config.class, WebMvcAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            DeviceDelegatingViewResolverConfiguration.class);
    this.context.refresh();
    LiteDeviceDelegatingViewResolver liteDeviceDelegatingViewResolver = this.context
            .getBean("deviceDelegatingViewResolver",
                    LiteDeviceDelegatingViewResolver.class);

    DirectFieldAccessor accessor = new DirectFieldAccessor(
            liteDeviceDelegatingViewResolver);
    assertThat(accessor.getPropertyValue("enableFallback")).isEqualTo(Boolean.FALSE);
    assertThat(accessor.getPropertyValue("normalPrefix")).isEqualTo("");
    assertThat(accessor.getPropertyValue("mobilePrefix")).isEqualTo("mobile/");
    assertThat(accessor.getPropertyValue("tabletPrefix")).isEqualTo("tablet/");
    assertThat(accessor.getPropertyValue("normalSuffix")).isEqualTo("");
    assertThat(accessor.getPropertyValue("mobileSuffix")).isEqualTo("");
    assertThat(accessor.getPropertyValue("tabletSuffix")).isEqualTo("");
}
项目:contestparser    文件:JolokiaAutoConfigurationTests.java   
@Test
public void agentServletWithCustomPath() throws Exception {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context,
            "endpoints.jolokia.path=/foo/bar");
    this.context.register(EndpointsConfig.class, WebMvcAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            JolokiaAutoConfiguration.class);
    this.context.refresh();
    assertEquals(1,
            this.context.getBeanNamesForType(JolokiaMvcEndpoint.class).length);
    MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
    mockMvc.perform(MockMvcRequestBuilders.get("/foo/bar"))
            .andExpect(MockMvcResultMatchers.content()
                    .string(Matchers.containsString("\"request\":{\"type\"")));
}
项目:contestparser    文件:EndpointWebMvcAutoConfigurationTests.java   
@Test
public void contextPath() throws Exception {
    EnvironmentTestUtils.addEnvironment(this.applicationContext,
            "management.contextPath:/test");
    this.applicationContext.register(RootConfig.class, EndpointConfig.class,
            ServerPortConfig.class, PropertyPlaceholderAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            ServerPropertiesAutoConfiguration.class, JacksonAutoConfiguration.class,
            EmbeddedServletContainerAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            DispatcherServletAutoConfiguration.class, WebMvcAutoConfiguration.class,
            EndpointWebMvcAutoConfiguration.class);
    this.applicationContext.refresh();
    assertContent("/controller", ports.get().server, "controlleroutput");
    assertContent("/test/endpoint", ports.get().server, "endpointoutput");
    this.applicationContext.close();
    assertAllClosed();
}
项目:contestparser    文件:ManagementWebSecurityAutoConfigurationTests.java   
@Test
public void testWebConfiguration() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(SecurityAutoConfiguration.class,
            WebMvcAutoConfiguration.class,
            ManagementWebSecurityAutoConfiguration.class,
            JacksonAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            EndpointAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    EnvironmentTestUtils.addEnvironment(this.context, "security.basic.enabled:false");
    this.context.refresh();
    assertNotNull(this.context.getBean(AuthenticationManagerBuilder.class));
    FilterChainProxy filterChainProxy = this.context.getBean(FilterChainProxy.class);
    // 4 for static resources, one for management endpoints and one for the rest
    assertThat(filterChainProxy.getFilterChains(), hasSize(6));
    assertThat(filterChainProxy.getFilters("/beans"), hasSize(greaterThan(0)));
    assertThat(filterChainProxy.getFilters("/beans/"), hasSize(greaterThan(0)));
    assertThat(filterChainProxy.getFilters("/beans.foo"), hasSize(greaterThan(0)));
    assertThat(filterChainProxy.getFilters("/beans/foo/bar"),
            hasSize(greaterThan(0)));
}
项目:contestparser    文件:SitePreferenceAutoConfigurationTests.java   
@Test
public void sitePreferenceHandlerInterceptorRegistered() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(Config.class, WebMvcAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            SitePreferenceAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    RequestMappingHandlerMapping mapping = this.context
            .getBean(RequestMappingHandlerMapping.class);
    HandlerInterceptor[] interceptors = mapping
            .getHandler(new MockHttpServletRequest()).getInterceptors();
    assertThat(interceptors,
            hasItemInArray(instanceOf(SitePreferenceHandlerInterceptor.class)));
}
项目:contestparser    文件:DeviceDelegatingViewResolverAutoConfigurationTests.java   
@Test(expected = NoSuchBeanDefinitionException.class)
public void deviceDelegatingInternalResourceViewResolverDisabled() throws Exception {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context,
            "spring.mobile.devicedelegatingviewresolver.enabled:false");
    this.context.register(Config.class, WebMvcAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            DeviceDelegatingViewResolverConfiguration.class);
    this.context.refresh();
    assertNotNull(this.context.getBean(InternalResourceViewResolver.class));
    try {
        this.context.getBean(ThymeleafViewResolver.class);
    }
    catch (NoSuchBeanDefinitionException ex) {
        // expected. ThymeleafViewResolver shouldn't be defined.
    }
    this.context.getBean("deviceDelegatingViewResolver",
            AbstractDeviceDelegatingViewResolver.class);
}
项目:contestparser    文件:DeviceDelegatingViewResolverAutoConfigurationTests.java   
@Test
public void deviceDelegatingThymeleafViewResolverEnabled() throws Exception {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context,
            "spring.mobile.devicedelegatingviewresolver.enabled:true");
    this.context.register(Config.class, WebMvcAutoConfiguration.class,
            ThymeleafAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            DeviceDelegatingViewResolverConfiguration.class);
    this.context.refresh();
    ThymeleafViewResolver thymeleafViewResolver = this.context
            .getBean(ThymeleafViewResolver.class);
    AbstractDeviceDelegatingViewResolver deviceDelegatingViewResolver = this.context
            .getBean("deviceDelegatingViewResolver",
                    AbstractDeviceDelegatingViewResolver.class);
    assertNotNull(thymeleafViewResolver);
    assertNotNull(deviceDelegatingViewResolver);
    assertTrue(deviceDelegatingViewResolver
            .getViewResolver() instanceof ThymeleafViewResolver);
    assertNotNull(this.context.getBean(InternalResourceViewResolver.class));
    assertNotNull(this.context.getBean(ThymeleafViewResolver.class));
    assertTrue(deviceDelegatingViewResolver
            .getOrder() == thymeleafViewResolver.getOrder() - 1);
}
项目:contestparser    文件:DeviceDelegatingViewResolverAutoConfigurationTests.java   
@Test(expected = NoSuchBeanDefinitionException.class)
public void deviceDelegatingThymeleafViewResolverDisabled() throws Exception {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context,
            "spring.mobile.devicedelegatingviewresolver.enabled:false");
    this.context.register(Config.class, WebMvcAutoConfiguration.class,
            ThymeleafAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            DeviceDelegatingViewResolverConfiguration.class);
    this.context.refresh();
    assertNotNull(this.context.getBean(InternalResourceViewResolver.class));
    assertNotNull(this.context.getBean(ThymeleafViewResolver.class));
    this.context.getBean("deviceDelegatingViewResolver",
            AbstractDeviceDelegatingViewResolver.class);
}
项目:contestparser    文件:DeviceDelegatingViewResolverAutoConfigurationTests.java   
@Test
public void defaultPropertyValues() throws Exception {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context,
            "spring.mobile.devicedelegatingviewresolver.enabled:true");
    this.context.register(Config.class, WebMvcAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            DeviceDelegatingViewResolverConfiguration.class);
    this.context.refresh();
    LiteDeviceDelegatingViewResolver liteDeviceDelegatingViewResolver = this.context
            .getBean("deviceDelegatingViewResolver",
                    LiteDeviceDelegatingViewResolver.class);

    DirectFieldAccessor accessor = new DirectFieldAccessor(
            liteDeviceDelegatingViewResolver);
    assertEquals(false, accessor.getPropertyValue("enableFallback"));
    assertEquals("", accessor.getPropertyValue("normalPrefix"));
    assertEquals("mobile/", accessor.getPropertyValue("mobilePrefix"));
    assertEquals("tablet/", accessor.getPropertyValue("tabletPrefix"));
    assertEquals("", accessor.getPropertyValue("normalSuffix"));
    assertEquals("", accessor.getPropertyValue("mobileSuffix"));
    assertEquals("", accessor.getPropertyValue("tabletSuffix"));
}
项目:contestparser    文件:DeviceResolverAutoConfigurationTests.java   
@Test
public void deviceResolverHandlerInterceptorRegistered() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(Config.class, WebMvcAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            DeviceResolverAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();
    RequestMappingHandlerMapping mapping = this.context
            .getBean(RequestMappingHandlerMapping.class);
    HandlerInterceptor[] interceptors = mapping
            .getHandler(new MockHttpServletRequest()).getInterceptors();
    assertThat(interceptors,
            hasItemInArray(instanceOf(DeviceResolverHandlerInterceptor.class)));
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JolokiaAutoConfigurationTests.java   
@Test
public void agentServletRegisteredWithAppContext() throws Exception {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, "jolokia.config[key1]:value1",
            "jolokia.config[key2]:value2");
    this.context.register(Config.class, WebMvcAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            JolokiaAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBeanNamesForType(JolokiaMvcEndpoint.class)).hasSize(1);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JolokiaAutoConfigurationTests.java   
private void assertEndpointDisabled(String... pairs) {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, pairs);
    this.context.register(Config.class, WebMvcAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            JolokiaAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBeanNamesForType(JolokiaMvcEndpoint.class)).isEmpty();
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:JolokiaAutoConfigurationTests.java   
private void assertEndpointEnabled(String... pairs) {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, pairs);
    this.context.register(Config.class, WebMvcAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            JolokiaAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBeanNamesForType(JolokiaMvcEndpoint.class)).hasSize(1);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:ManagementWebSecurityAutoConfigurationTests.java   
@Test
public void realmSameForManagement() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(AuthenticationConfig.class, SecurityAutoConfiguration.class,
            ManagementWebSecurityAutoConfiguration.class,
            JacksonAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            EndpointAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            WebMvcAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();

    Filter filter = this.context.getBean("springSecurityFilterChain", Filter.class);
    MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
            .addFilters(filter).build();

    // no user (Main)
    mockMvc.perform(MockMvcRequestBuilders.get("/home"))
            .andExpect(MockMvcResultMatchers.status().isUnauthorized())
            .andExpect(springAuthenticateRealmHeader());

    // invalid user (Main)
    mockMvc.perform(
            MockMvcRequestBuilders.get("/home").header("authorization", "Basic xxx"))
            .andExpect(MockMvcResultMatchers.status().isUnauthorized())
            .andExpect(springAuthenticateRealmHeader());

    // no user (Management)
    mockMvc.perform(MockMvcRequestBuilders.get("/beans"))
            .andExpect(MockMvcResultMatchers.status().isUnauthorized())
            .andExpect(springAuthenticateRealmHeader());

    // invalid user (Management)
    mockMvc.perform(
            MockMvcRequestBuilders.get("/beans").header("authorization", "Basic xxx"))
            .andExpect(MockMvcResultMatchers.status().isUnauthorized())
            .andExpect(springAuthenticateRealmHeader());
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:MvcEndpointCorsIntegrationTests.java   
@Before
public void createContext() {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(JacksonAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            EndpointAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            JolokiaAutoConfiguration.class, WebMvcAutoConfiguration.class);
}
项目:https-github.com-g0t4-jenkins2-course-spring-boot    文件:DeviceDelegatingViewResolverAutoConfigurationTests.java   
public void load(List<Class<?>> config, String... environment) {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    if (config != null) {
        this.context.register(config.toArray(new Class[config.size()]));
    }
    this.context.register(WebMvcAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            DeviceDelegatingViewResolverAutoConfiguration.class);
    EnvironmentTestUtils.addEnvironment(this.context, environment);
    this.context.refresh();
}
项目:spring-boot-concourse    文件:JolokiaAutoConfigurationTests.java   
@Test
public void agentServletRegisteredWithAppContext() throws Exception {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, "jolokia.config[key1]:value1",
            "jolokia.config[key2]:value2");
    this.context.register(Config.class, WebMvcAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            JolokiaAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBeanNamesForType(JolokiaMvcEndpoint.class)).hasSize(1);
}
项目:spring-boot-concourse    文件:JolokiaAutoConfigurationTests.java   
@Test
public void agentServletWithCustomPath() throws Exception {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context,
            "endpoints.jolokia.path=/foo/bar");
    this.context.register(EndpointsConfig.class, WebMvcAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            JolokiaAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBeanNamesForType(JolokiaMvcEndpoint.class)).hasSize(1);
    MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context).build();
    mockMvc.perform(MockMvcRequestBuilders.get("/foo/bar"))
            .andExpect(MockMvcResultMatchers.content()
                    .string(Matchers.containsString("\"request\":{\"type\"")));
}
项目:spring-boot-concourse    文件:JolokiaAutoConfigurationTests.java   
private void assertEndpointDisabled(String... pairs) {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, pairs);
    this.context.register(Config.class, WebMvcAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            JolokiaAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBeanNamesForType(JolokiaMvcEndpoint.class)).isEmpty();
}
项目:spring-boot-concourse    文件:JolokiaAutoConfigurationTests.java   
private void assertEndpointEnabled(String... pairs) {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, pairs);
    this.context.register(Config.class, WebMvcAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            JolokiaAutoConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBeanNamesForType(JolokiaMvcEndpoint.class)).hasSize(1);
}
项目:spring-boot-concourse    文件:ManagementWebSecurityAutoConfigurationTests.java   
@Test
public void realmSameForManagement() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(AuthenticationConfig.class, SecurityAutoConfiguration.class,
            ManagementWebSecurityAutoConfiguration.class,
            JacksonAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            EndpointAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            WebMvcAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();

    Filter filter = this.context.getBean("springSecurityFilterChain", Filter.class);
    MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
            .addFilters(filter).build();

    // no user (Main)
    mockMvc.perform(MockMvcRequestBuilders.get("/home"))
            .andExpect(MockMvcResultMatchers.status().isUnauthorized())
            .andExpect(springAuthenticateRealmHeader());

    // invalid user (Main)
    mockMvc.perform(
            MockMvcRequestBuilders.get("/home").header("authorization", "Basic xxx"))
            .andExpect(MockMvcResultMatchers.status().isUnauthorized())
            .andExpect(springAuthenticateRealmHeader());

    // no user (Management)
    mockMvc.perform(MockMvcRequestBuilders.get("/beans"))
            .andExpect(MockMvcResultMatchers.status().isUnauthorized())
            .andExpect(springAuthenticateRealmHeader());

    // invalid user (Management)
    mockMvc.perform(
            MockMvcRequestBuilders.get("/beans").header("authorization", "Basic xxx"))
            .andExpect(MockMvcResultMatchers.status().isUnauthorized())
            .andExpect(springAuthenticateRealmHeader());
}
项目:spring-boot-concourse    文件:MvcEndpointCorsIntegrationTests.java   
@Before
public void createContext() {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(JacksonAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            EndpointAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            JolokiaAutoConfiguration.class, WebMvcAutoConfiguration.class);
}
项目:spring-boot-concourse    文件:DeviceDelegatingViewResolverAutoConfigurationTests.java   
@Test
public void deviceDelegatingInternalResourceViewResolverEnabled() throws Exception {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context,
            "spring.mobile.devicedelegatingviewresolver.enabled:true");
    this.context.register(Config.class, WebMvcAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            DeviceDelegatingViewResolverConfiguration.class);
    this.context.refresh();
    InternalResourceViewResolver internalResourceViewResolver = this.context
            .getBean(InternalResourceViewResolver.class);
    AbstractDeviceDelegatingViewResolver deviceDelegatingViewResolver = this.context
            .getBean("deviceDelegatingViewResolver",
                    AbstractDeviceDelegatingViewResolver.class);
    assertThat(internalResourceViewResolver).isNotNull();
    assertThat(deviceDelegatingViewResolver).isNotNull();
    assertThat(deviceDelegatingViewResolver.getViewResolver())
            .isInstanceOf(InternalResourceViewResolver.class);
    try {
        this.context.getBean(ThymeleafViewResolver.class);
    }
    catch (NoSuchBeanDefinitionException ex) {
        // expected. ThymeleafViewResolver shouldn't be defined.
    }
    assertThat(deviceDelegatingViewResolver.getOrder())
            .isEqualTo(internalResourceViewResolver.getOrder() - 1);
}
项目:spring-boot-concourse    文件:DeviceDelegatingViewResolverAutoConfigurationTests.java   
@Test(expected = NoSuchBeanDefinitionException.class)
public void deviceDelegatingInternalResourceViewResolverDisabled() throws Exception {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context,
            "spring.mobile.devicedelegatingviewresolver.enabled:false");
    this.context.register(Config.class, WebMvcAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            DeviceDelegatingViewResolverConfiguration.class);
    this.context.refresh();
    assertThat(this.context.getBean(InternalResourceViewResolver.class)).isNotNull();
    try {
        this.context.getBean(ThymeleafViewResolver.class);
    }
    catch (NoSuchBeanDefinitionException ex) {
        // expected. ThymeleafViewResolver shouldn't be defined.
    }
    this.context.getBean("deviceDelegatingViewResolver",
            AbstractDeviceDelegatingViewResolver.class);
}
项目:spring-boot-concourse    文件:DeviceDelegatingViewResolverAutoConfigurationTests.java   
private PropertyAccessor getLiteDeviceDelegatingViewResolverAccessor(
        String... configuration) {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, configuration);
    this.context.register(Config.class, WebMvcAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            DeviceDelegatingViewResolverConfiguration.class);
    this.context.refresh();
    LiteDeviceDelegatingViewResolver liteDeviceDelegatingViewResolver = this.context
            .getBean("deviceDelegatingViewResolver",
                    LiteDeviceDelegatingViewResolver.class);
    return new DirectFieldAccessor(liteDeviceDelegatingViewResolver);
}
项目:contestparser    文件:JolokiaAutoConfigurationTests.java   
@Test
public void agentServletRegisteredWithAppContext() throws Exception {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, "jolokia.config[key1]:value1",
            "jolokia.config[key2]:value2");
    this.context.register(Config.class, WebMvcAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            JolokiaAutoConfiguration.class);
    this.context.refresh();
    assertEquals(1,
            this.context.getBeanNamesForType(JolokiaMvcEndpoint.class).length);
}
项目:contestparser    文件:JolokiaAutoConfigurationTests.java   
private void assertEndpointDisabled(String... pairs) {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, pairs);
    this.context.register(Config.class, WebMvcAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            JolokiaAutoConfiguration.class);
    this.context.refresh();
    assertEquals(0,
            this.context.getBeanNamesForType(JolokiaMvcEndpoint.class).length);
}
项目:contestparser    文件:JolokiaAutoConfigurationTests.java   
private void assertEndpointEnabled(String... pairs) {
    this.context = new AnnotationConfigEmbeddedWebApplicationContext();
    EnvironmentTestUtils.addEnvironment(this.context, pairs);
    this.context.register(Config.class, WebMvcAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            JolokiaAutoConfiguration.class);
    this.context.refresh();
    assertEquals(1,
            this.context.getBeanNamesForType(JolokiaMvcEndpoint.class).length);
}
项目:contestparser    文件:ManagementWebSecurityAutoConfigurationTests.java   
@Test
public void realmSameForManagement() throws Exception {
    this.context = new AnnotationConfigWebApplicationContext();
    this.context.setServletContext(new MockServletContext());
    this.context.register(AuthenticationConfig.class, SecurityAutoConfiguration.class,
            ManagementWebSecurityAutoConfiguration.class,
            JacksonAutoConfiguration.class,
            HttpMessageConvertersAutoConfiguration.class,
            EndpointAutoConfiguration.class, EndpointWebMvcAutoConfiguration.class,
            ManagementServerPropertiesAutoConfiguration.class,
            WebMvcAutoConfiguration.class,
            PropertyPlaceholderAutoConfiguration.class);
    this.context.refresh();

    Filter filter = this.context.getBean("springSecurityFilterChain", Filter.class);
    MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(this.context)
            .addFilters(filter).build();

    // no user (Main)
    mockMvc.perform(MockMvcRequestBuilders.get("/home"))
            .andExpect(MockMvcResultMatchers.status().isUnauthorized())
            .andExpect(springAuthenticateRealmHeader());

    // invalid user (Main)
    mockMvc.perform(
            MockMvcRequestBuilders.get("/home").header("authorization", "Basic xxx"))
            .andExpect(MockMvcResultMatchers.status().isUnauthorized())
            .andExpect(springAuthenticateRealmHeader());

    // no user (Management)
    mockMvc.perform(MockMvcRequestBuilders.get("/beans"))
            .andExpect(MockMvcResultMatchers.status().isUnauthorized())
            .andExpect(springAuthenticateRealmHeader());

    // invalid user (Management)
    mockMvc.perform(
            MockMvcRequestBuilders.get("/beans").header("authorization", "Basic xxx"))
            .andExpect(MockMvcResultMatchers.status().isUnauthorized())
            .andExpect(springAuthenticateRealmHeader());
}