parent
							
								
									ff7717932a
								
							
						
					
					
						commit
						6d2af95d59
					
				| 
						 | 
				
			
			@ -53,7 +53,7 @@ public class JolokiaMvcEndpoint implements MvcEndpoint, InitializingBean,
 | 
			
		|||
	 * Endpoint URL path.
 | 
			
		||||
	 */
 | 
			
		||||
	@NotNull
 | 
			
		||||
	@Pattern(regexp = "/[^/]*", message = "Path must start with /")
 | 
			
		||||
	@Pattern(regexp = "/[^?#]*", message = "Path must start with /")
 | 
			
		||||
	private String path;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,9 +16,14 @@
 | 
			
		|||
 | 
			
		||||
package org.springframework.boot.actuate.autoconfigure;
 | 
			
		||||
 | 
			
		||||
import java.util.Collection;
 | 
			
		||||
 | 
			
		||||
import org.hamcrest.Matchers;
 | 
			
		||||
import org.junit.After;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
import org.springframework.boot.actuate.endpoint.mvc.EndpointHandlerMapping;
 | 
			
		||||
import org.springframework.boot.actuate.endpoint.mvc.JolokiaMvcEndpoint;
 | 
			
		||||
import org.springframework.boot.actuate.endpoint.mvc.MvcEndpoint;
 | 
			
		||||
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
 | 
			
		||||
import org.springframework.boot.autoconfigure.web.HttpMessageConvertersAutoConfiguration;
 | 
			
		||||
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
 | 
			
		||||
| 
						 | 
				
			
			@ -30,6 +35,10 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
 | 
			
		|||
import org.springframework.boot.test.EnvironmentTestUtils;
 | 
			
		||||
import org.springframework.context.annotation.Bean;
 | 
			
		||||
import org.springframework.context.annotation.Configuration;
 | 
			
		||||
import org.springframework.test.web.servlet.MockMvc;
 | 
			
		||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
 | 
			
		||||
import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
 | 
			
		||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
 | 
			
		||||
 | 
			
		||||
import static org.junit.Assert.assertEquals;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -67,6 +76,24 @@ public class JolokiaAutoConfigurationTests {
 | 
			
		|||
		assertEquals(1, this.context.getBeanNamesForType(JolokiaMvcEndpoint.class).length);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@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 endpointDisabled() throws Exception {
 | 
			
		||||
		assertEndpointDisabled("endpoints.jolokia.enabled:false");
 | 
			
		||||
| 
						 | 
				
			
			@ -106,6 +133,15 @@ public class JolokiaAutoConfigurationTests {
 | 
			
		|||
		assertEquals(1, this.context.getBeanNamesForType(JolokiaMvcEndpoint.class).length);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Configuration
 | 
			
		||||
	protected static class EndpointsConfig extends Config {
 | 
			
		||||
		@Bean
 | 
			
		||||
		public EndpointHandlerMapping endpointHandlerMapping(
 | 
			
		||||
				Collection<? extends MvcEndpoint> endpoints) {
 | 
			
		||||
			return new EndpointHandlerMapping(endpoints);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Configuration
 | 
			
		||||
	@EnableConfigurationProperties
 | 
			
		||||
	protected static class Config {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue