39
39
import org .junit .rules .ExpectedException ;
40
40
41
41
import org .springframework .aop .framework .ProxyFactory ;
42
+ import org .springframework .beans .factory .FactoryBean ;
42
43
import org .springframework .beans .factory .support .BeanDefinitionBuilder ;
43
44
import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
45
+ import org .springframework .beans .factory .support .RootBeanDefinition ;
44
46
import org .springframework .context .ConfigurableApplicationContext ;
45
47
import org .springframework .context .support .ClassPathXmlApplicationContext ;
46
48
import org .springframework .jmx .AbstractMBeanServerTests ;
68
70
* @author Sam Brannen
69
71
* @author Stephane Nicoll
70
72
*/
71
- @ SuppressWarnings ("deprecation" )
72
73
public class MBeanExporterTests extends AbstractMBeanServerTests {
73
74
74
75
@ Rule
@@ -235,7 +236,6 @@ public void testWithMBeanExporterListeners() throws Exception {
235
236
assertListener (listener2 );
236
237
}
237
238
238
-
239
239
@ Test
240
240
public void testExportJdkProxy () throws Exception {
241
241
JmxTestBean bean = new JmxTestBean ();
@@ -541,10 +541,7 @@ public void testNotRunningInBeanFactoryAndAutodetectionIsOn() throws Exception {
541
541
start (exporter );
542
542
}
543
543
544
- /**
545
- * SPR-2158
546
- */
547
- @ Test
544
+ @ Test // SPR-2158
548
545
public void testMBeanIsNotUnregisteredSpuriouslyIfSomeExternalProcessHasUnregisteredMBean () throws Exception {
549
546
MBeanExporter exporter = new MBeanExporter ();
550
547
exporter .setBeans (getBeanMap ());
@@ -561,10 +558,7 @@ public void testMBeanIsNotUnregisteredSpuriouslyIfSomeExternalProcessHasUnregist
561
558
listener .getUnregistered ().size ());
562
559
}
563
560
564
- /**
565
- * SPR-3302
566
- */
567
- @ Test
561
+ @ Test // SPR-3302
568
562
public void testBeanNameCanBeUsedInNotificationListenersMap () throws Exception {
569
563
String beanName = "charlesDexterWard" ;
570
564
BeanDefinitionBuilder testBean = BeanDefinitionBuilder .rootBeanDefinition (JmxTestBean .class );
@@ -608,10 +602,7 @@ public void testWildcardCanBeUsedInNotificationListenersMap() throws Exception {
608
602
start (exporter );
609
603
}
610
604
611
- /*
612
- * SPR-3625
613
- */
614
- @ Test
605
+ @ Test // SPR-3625
615
606
public void testMBeanIsUnregisteredForRuntimeExceptionDuringInitialization () throws Exception {
616
607
BeanDefinitionBuilder builder1 = BeanDefinitionBuilder .rootBeanDefinition (Person .class );
617
608
BeanDefinitionBuilder builder2 = BeanDefinitionBuilder
@@ -667,6 +658,37 @@ public void testIgnoreBeanName() throws MalformedObjectNameException {
667
658
ObjectNameManager .getInstance (secondBeanName ));
668
659
}
669
660
661
+ @ Test
662
+ public void testRegisterFactoryBean () throws MalformedObjectNameException {
663
+ DefaultListableBeanFactory factory = new DefaultListableBeanFactory ();
664
+ factory .registerBeanDefinition ("spring:type=FactoryBean" , new RootBeanDefinition (ProperSomethingFactoryBean .class ));
665
+
666
+ MBeanExporter exporter = new MBeanExporter ();
667
+ exporter .setServer (getServer ());
668
+ exporter .setBeanFactory (factory );
669
+ exporter .setAutodetectMode (MBeanExporter .AUTODETECT_ALL );
670
+
671
+ start (exporter );
672
+ assertIsRegistered ("Non-null FactoryBean object registered" ,
673
+ ObjectNameManager .getInstance ("spring:type=FactoryBean" ));
674
+ }
675
+
676
+ @ Test
677
+ public void testIgnoreNullObjectFromFactoryBean () throws MalformedObjectNameException {
678
+ DefaultListableBeanFactory factory = new DefaultListableBeanFactory ();
679
+ factory .registerBeanDefinition ("spring:type=FactoryBean" , new RootBeanDefinition (NullSomethingFactoryBean .class ));
680
+
681
+ MBeanExporter exporter = new MBeanExporter ();
682
+ exporter .setServer (getServer ());
683
+ exporter .setBeanFactory (factory );
684
+ exporter .setAutodetectMode (MBeanExporter .AUTODETECT_ALL );
685
+
686
+ start (exporter );
687
+ assertIsNotRegistered ("Null FactoryBean object not registered" ,
688
+ ObjectNameManager .getInstance ("spring:type=FactoryBean" ));
689
+ }
690
+
691
+
670
692
private ConfigurableApplicationContext load (String context ) {
671
693
return new ClassPathXmlApplicationContext (context , getClass ());
672
694
}
@@ -799,4 +821,41 @@ public boolean includeBean(Class<?> beanClass, String beanName) {
799
821
}
800
822
}
801
823
824
+
825
+ public interface SomethingMBean {}
826
+
827
+ public static class Something implements SomethingMBean {}
828
+
829
+
830
+ public static class ProperSomethingFactoryBean implements FactoryBean <Something > {
831
+
832
+ @ Override public Something getObject () {
833
+ return new Something ();
834
+ }
835
+
836
+ @ Override public Class <?> getObjectType () {
837
+ return Something .class ;
838
+ }
839
+
840
+ @ Override public boolean isSingleton () {
841
+ return true ;
842
+ }
843
+ }
844
+
845
+
846
+ public static class NullSomethingFactoryBean implements FactoryBean <Something > {
847
+
848
+ @ Override public Something getObject () {
849
+ return null ;
850
+ }
851
+
852
+ @ Override public Class <?> getObjectType () {
853
+ return Something .class ;
854
+ }
855
+
856
+ @ Override public boolean isSingleton () {
857
+ return true ;
858
+ }
859
+ }
860
+
802
861
}
0 commit comments