Browse Source

Introduce getAutodetectMode() in MBeanExporter

Closes gh-30855
pull/30915/head
Sam Brannen 3 years ago
parent
commit
7c7fa69558
  1. 16
      spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java
  2. 8
      spring-context/src/test/java/org/springframework/jmx/export/MBeanExporterTests.java

16
spring-context/src/main/java/org/springframework/jmx/export/MBeanExporter.java

@ -92,6 +92,7 @@ import org.springframework.util.ObjectUtils; @@ -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 @@ -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 @@ -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 @@ -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.

8
spring-context/src/test/java/org/springframework/jmx/export/MBeanExporterTests.java

@ -441,47 +441,55 @@ public class MBeanExporterTests extends AbstractMBeanServerTests { @@ -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…
Cancel
Save