@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\""))); }
@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"); }
@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"); }
@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(); }
@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); }
@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); }
@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); }
@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(""); }
@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\""))); }
@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(); }
@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))); }
@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))); }
@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); }
@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); }
@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); }
@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")); }
@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))); }
@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); }
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(); }
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); }
@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()); }
@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); }
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(); }
@Test public void doubleModuleRegistration() throws Exception { this.context.register(DoubleModulesConfig.class, HttpMessageConvertersAutoConfiguration.class); this.context.refresh(); ObjectMapper mapper = this.context.getBean(ObjectMapper.class); assertThat(mapper.writeValueAsString(new Foo())).isEqualTo("{\"foo\":\"bar\"}"); }
@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); }
@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); }
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); }
@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); }
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); }