|
16 | 16 |
|
17 | 17 | package org.springframework.boot.actuate.endpoint.jmx;
|
18 | 18 |
|
| 19 | +import java.net.URL; |
| 20 | +import java.net.URLClassLoader; |
| 21 | + |
19 | 22 | import javax.management.Attribute;
|
20 | 23 | import javax.management.AttributeList;
|
21 | 24 | import javax.management.AttributeNotFoundException;
|
|
29 | 32 | import org.junit.rules.ExpectedException;
|
30 | 33 | import reactor.core.publisher.Mono;
|
31 | 34 |
|
| 35 | +import org.springframework.util.ClassUtils; |
| 36 | + |
32 | 37 | import static org.assertj.core.api.Assertions.assertThat;
|
33 | 38 | import static org.hamcrest.CoreMatchers.instanceOf;
|
34 | 39 | import static org.mockito.Mockito.mock;
|
@@ -84,6 +89,23 @@ public void invokeShouldInvokeJmxOperation()
|
84 | 89 | assertThat(result).isEqualTo("result");
|
85 | 90 | }
|
86 | 91 |
|
| 92 | + @Test |
| 93 | + public void invokeShouldInvokeJmxOperationWithApplicationClassLoader() |
| 94 | + throws ReflectionException, MBeanException { |
| 95 | + TestExposableJmxEndpoint endpoint = new TestExposableJmxEndpoint( |
| 96 | + new TestJmxOperation((arguments) -> ClassUtils.getDefaultClassLoader())); |
| 97 | + EndpointMBean bean = new EndpointMBean(this.responseMapper, endpoint); |
| 98 | + Object result; |
| 99 | + Thread.currentThread().setContextClassLoader(new URLClassLoader(new URL[]{}, getClass().getClassLoader())); |
| 100 | + try { |
| 101 | + result = bean.invoke("testOperation", NO_PARAMS, NO_SIGNATURE); |
| 102 | + } |
| 103 | + finally { |
| 104 | + Thread.currentThread().setContextClassLoader(getClass().getClassLoader()); |
| 105 | + } |
| 106 | + assertThat(result).isEqualTo(getClass().getClassLoader()); |
| 107 | + } |
| 108 | + |
87 | 109 | @Test
|
88 | 110 | public void invokeWhenActionNameIsNotAnOperationShouldThrowException()
|
89 | 111 | throws MBeanException, ReflectionException {
|
|
0 commit comments