Introduce getAutodetectMode() in MBeanExporter
Closes gh-30855
This commit is contained in:
parent
9ad92b16b0
commit
7c7fa69558
|
@ -92,6 +92,7 @@ import org.springframework.util.ObjectUtils;
|
|||
* @author Rick Evans
|
||||
* @author Mark Fisher
|
||||
* @author Stephane Nicoll
|
||||
* @author Sam Brannen
|
||||
* @since 1.2
|
||||
* @see #setBeans
|
||||
* @see #setAutodetect
|
||||
|
@ -227,6 +228,7 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
|
|||
* @throws IllegalArgumentException if the supplied value is not
|
||||
* one of the {@code AUTODETECT_} constants
|
||||
* @see #setAutodetectModeName(String)
|
||||
* @see #getAutodetectMode()
|
||||
* @see #AUTODETECT_ALL
|
||||
* @see #AUTODETECT_ASSEMBLER
|
||||
* @see #AUTODETECT_MBEAN
|
||||
|
@ -244,6 +246,7 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
|
|||
* @throws IllegalArgumentException if the supplied value is not resolvable
|
||||
* to one of the {@code AUTODETECT_} constants or is {@code null}
|
||||
* @see #setAutodetectMode(int)
|
||||
* @see #getAutodetectMode()
|
||||
* @see #AUTODETECT_ALL
|
||||
* @see #AUTODETECT_ASSEMBLER
|
||||
* @see #AUTODETECT_MBEAN
|
||||
|
@ -256,6 +259,19 @@ public class MBeanExporter extends MBeanRegistrationSupport implements MBeanExpo
|
|||
this.autodetectMode = (Integer) constants.asNumber(constantName);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the autodetect mode to use for this {@code MBeanExporter}.
|
||||
* @return the configured autodetect mode, or {@code null} if not explicitly
|
||||
* configured
|
||||
* @since 6.0.11
|
||||
* @see #setAutodetectModeName(String)
|
||||
* @see #setAutodetectMode(int)
|
||||
*/
|
||||
@Nullable
|
||||
public Integer getAutodetectMode() {
|
||||
return this.autodetectMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify whether to allow eager initialization of candidate beans
|
||||
* when autodetecting MBeans in the Spring application context.
|
||||
|
|
|
@ -441,47 +441,55 @@ public class MBeanExporterTests extends AbstractMBeanServerTests {
|
|||
@Test
|
||||
void setAutodetectModeToSupportedValue() {
|
||||
exporter.setAutodetectMode(MBeanExporter.AUTODETECT_ASSEMBLER);
|
||||
assertThat(exporter.getAutodetectMode()).isEqualTo(MBeanExporter.AUTODETECT_ASSEMBLER);
|
||||
}
|
||||
|
||||
@Test
|
||||
void setAutodetectModeToOutOfRangeNegativeValue() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> exporter.setAutodetectMode(-1));
|
||||
assertThat(exporter.getAutodetectMode()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void setAutodetectModeToOutOfRangePositiveValue() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> exporter.setAutodetectMode(5));
|
||||
assertThat(exporter.getAutodetectMode()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void setAutodetectModeNameToSupportedValue() {
|
||||
exporter.setAutodetectModeName("AUTODETECT_ASSEMBLER");
|
||||
assertThat(exporter.getAutodetectMode()).isEqualTo(MBeanExporter.AUTODETECT_ASSEMBLER);
|
||||
}
|
||||
|
||||
@Test
|
||||
void setAutodetectModeNameToNull() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> exporter.setAutodetectModeName(null));
|
||||
assertThat(exporter.getAutodetectMode()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void setAutodetectModeNameToAnEmptyString() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> exporter.setAutodetectModeName(""));
|
||||
assertThat(exporter.getAutodetectMode()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void setAutodetectModeNameToAWhitespacedString() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> exporter.setAutodetectModeName(" \t"));
|
||||
assertThat(exporter.getAutodetectMode()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void setAutodetectModeNameToARubbishValue() {
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> exporter.setAutodetectModeName("That Hansel is... *sssooo* hot right now!"));
|
||||
assertThat(exporter.getAutodetectMode()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue