18
18
*/
19
19
package org .apache .cloudstack .spring .module .factory ;
20
20
21
- import static org .junit .Assert .assertEquals ;
22
- import static org .junit .Assert .assertNotNull ;
23
- import static org .junit .Assert .assertNull ;
24
- import static org .junit .Assert .assertTrue ;
25
- import static org .junit .Assert .fail ;
26
-
27
- import java .io .IOException ;
28
- import java .util .Collection ;
29
-
21
+ import org .apache .cloudstack .spring .module .locator .impl .ClasspathModuleDefinitionLocator ;
22
+ import org .apache .cloudstack .spring .module .model .ModuleDefinition ;
23
+ import org .apache .cloudstack .spring .module .model .ModuleDefinitionSet ;
30
24
import org .junit .Before ;
31
25
import org .junit .Test ;
32
26
import org .springframework .beans .factory .NoSuchBeanDefinitionException ;
33
27
import org .springframework .context .ApplicationContext ;
28
+ import org .springframework .core .io .Resource ;
34
29
35
- import org .apache .cloudstack .spring .module .locator .impl .ClasspathModuleDefinitionLocator ;
36
- import org .apache .cloudstack .spring .module .model .ModuleDefinition ;
37
- import org .apache .cloudstack .spring .module .model .ModuleDefinitionSet ;
30
+ import java .io .IOException ;
31
+ import java .util .Arrays ;
32
+ import java .util .Collection ;
33
+ import java .util .List ;
34
+ import java .util .stream .Collectors ;
35
+
36
+ import static org .junit .Assert .assertEquals ;
37
+ import static org .junit .Assert .assertNotNull ;
38
+ import static org .junit .Assert .assertNull ;
39
+ import static org .junit .Assert .assertTrue ;
40
+ import static org .junit .Assert .fail ;
38
41
39
42
public class ModuleBasedContextFactoryTest {
40
43
41
44
Collection <ModuleDefinition > defs ;
45
+ ModuleBasedContextFactory factory = new ModuleBasedContextFactory ();
42
46
43
47
@ Before
44
48
public void setUp () throws IOException {
@@ -51,8 +55,6 @@ public void setUp() throws IOException {
51
55
@ Test
52
56
public void testLoad () throws IOException {
53
57
54
- ModuleBasedContextFactory factory = new ModuleBasedContextFactory ();
55
-
56
58
ModuleDefinitionSet set = factory .loadModules (defs , "base" );
57
59
58
60
assertNotNull (set .getApplicationContext ("base" ));
@@ -63,8 +65,6 @@ public void testOverride() throws IOException {
63
65
64
66
InitTest .initted = false ;
65
67
66
- ModuleBasedContextFactory factory = new ModuleBasedContextFactory ();
67
-
68
68
ModuleDefinitionSet set = factory .loadModules (defs , "base" );
69
69
70
70
assertTrue (!InitTest .initted );
@@ -73,7 +73,6 @@ public void testOverride() throws IOException {
73
73
74
74
@ Test
75
75
public void testExcluded () throws IOException {
76
- ModuleBasedContextFactory factory = new ModuleBasedContextFactory ();
77
76
ModuleDefinitionSet set = factory .loadModules (defs , "base" );
78
77
79
78
assertNull (set .getApplicationContext ("excluded" ));
@@ -83,7 +82,6 @@ public void testExcluded() throws IOException {
83
82
84
83
@ Test
85
84
public void testBeans () throws IOException {
86
- ModuleBasedContextFactory factory = new ModuleBasedContextFactory ();
87
85
ModuleDefinitionSet set = factory .loadModules (defs , "base" );
88
86
89
87
testBeansInContext (set , "base" , 1 , new String [] {"base" }, new String [] {"child1" , "child2" , "child1-1" });
@@ -92,6 +90,25 @@ public void testBeans() throws IOException {
92
90
testBeansInContext (set , "child1-1" , 3 , new String [] {"base" , "child1" , "child1-1" }, new String [] {"child2" });
93
91
}
94
92
93
+ @ Test
94
+ public void testConfigResources () throws IOException {
95
+ ModuleDefinitionSet set = factory .loadModules (defs , "base" );
96
+
97
+ testConfigResourcesArray (new String [] {}, set .getConfigResources ("" ));
98
+ testConfigResourcesArray (new String [] {"base-context.xml" , "base-context-inheritable.xml" }, set .getConfigResources ("base" ));
99
+ testConfigResourcesArray (new String [] {"child1-context.xml" , "child1-context-inheritable.xml" , "base-context-inheritable.xml" , "chil1-context-override.xml" }, set .getConfigResources ("child1" ));
100
+ testConfigResourcesArray (new String [] {"child2-context.xml" , "base-context-inheritable.xml" }, set .getConfigResources ("child2" ));
101
+ testConfigResourcesArray (new String [] {"chil1-1-context.xml" , "child1-context-inheritable.xml" , "base-context-inheritable.xml" }, set .getConfigResources ("child1-1" ));
102
+ }
103
+
104
+ private void testConfigResourcesArray (String [] expected , Resource [] actual ) {
105
+ assertEquals (expected .length , actual .length );
106
+ List <String > actualFileNameList = Arrays .stream (actual ).map (Resource ::getFilename ).collect (Collectors .toList ());
107
+ for (int i = 0 ; i < expected .length ; i ++) {
108
+ assertEquals (expected [i ], actualFileNameList .get (i ));
109
+ }
110
+ }
111
+
95
112
protected void testBeansInContext (ModuleDefinitionSet set , String name , int order , String [] parents , String [] notTheres ) {
96
113
ApplicationContext context = set .getApplicationContext (name );
97
114
0 commit comments