23
23
import java .util .Stack ;
24
24
import java .util .function .Supplier ;
25
25
26
+ import ch .qos .logback .core .model .processor .IncludeModelHandler ;
26
27
import org .junit .jupiter .api .AfterEach ;
27
28
import org .junit .jupiter .api .Assertions ;
28
29
import org .junit .jupiter .api .BeforeEach ;
49
50
import ch .qos .logback .core .status .testUtil .StatusChecker ;
50
51
import ch .qos .logback .core .util .StatusPrinter ;
51
52
52
- @ Disabled
53
+ import static ch .qos .logback .core .joran .JoranConstants .CONFIGURATION_TAG ;
54
+ import static ch .qos .logback .core .joran .JoranConstants .INCLUDED_TAG ;
55
+
56
+
53
57
public class IncludeActionTest {
54
58
55
59
final static String INCLUDE_KEY = "includeKey" ;
@@ -96,27 +100,32 @@ public class IncludeActionTest {
96
100
public void setUp () throws Exception {
97
101
FileTestUtil .makeTestOutputDir ();
98
102
HashMap <ElementSelector , Supplier <Action >> rulesMap = new HashMap <>();
99
- rulesMap .put (new ElementSelector ("x" ), () -> new TopElementAction ());
100
- rulesMap .put (new ElementSelector ("x /include" ), () -> new IncludeAction ());
101
- rulesMap .put (new ElementSelector ("x /stack" ), () -> new StackAction ());
103
+ rulesMap .put (new ElementSelector (CONFIGURATION_TAG ), () -> new TopElementAction ());
104
+ rulesMap .put (new ElementSelector (CONFIGURATION_TAG + " /include" ), () -> new IncludeAction ());
105
+ rulesMap .put (new ElementSelector (CONFIGURATION_TAG + " /stack" ), () -> new StackAction ());
102
106
103
107
tc = new TrivialConfigurator (rulesMap ) {
104
-
105
-
108
+
106
109
@ Override
107
110
protected void addModelHandlerAssociations (DefaultProcessor defaultProcessor ) {
108
111
defaultProcessor .addHandler (TopModel .class , NOPModelHandler ::makeInstance );
109
- defaultProcessor .addHandler (IncludeModel .class , NOPModelHandler ::makeInstance );
112
+ defaultProcessor .addHandler (IncludeModel .class , IncludeModelHandler ::makeInstance );
110
113
defaultProcessor .addHandler (StackModel .class , StackModelHandler ::makeInstance );
111
114
}
115
+
116
+ public void buildModelInterpretationContext () {
117
+ super .buildModelInterpretationContext ();
118
+ this .modelInterpretationContext .setConfiguratorSupplier ( () -> this .makeAnotherInstance () );
119
+ }
112
120
};
113
121
114
122
tc .setContext (context );
123
+ tc .getRuleStore ().addPathPathMapping (INCLUDED_TAG , CONFIGURATION_TAG );
115
124
}
116
125
117
126
@ AfterEach
118
127
public void tearDown () throws Exception {
119
- StatusPrinter .printInCaseOfErrorsOrWarnings (context );
128
+ // StatusPrinter.printInCaseOfErrorsOrWarnings(context);
120
129
context = null ;
121
130
System .clearProperty (INCLUDE_KEY );
122
131
System .clearProperty (SECOND_FILE_KEY );
@@ -128,22 +137,22 @@ public void tearDown() throws Exception {
128
137
public void basicFile () throws JoranException {
129
138
System .setProperty (INCLUDE_KEY , INCLUDED_FILE );
130
139
tc .doConfigure (TOP_BY_FILE );
131
- StatusPrinter .print (context );
140
+ // StatusPrinter.print(context);
132
141
verifyConfig (new String [] { "IA" , "IB" });
133
142
}
134
143
135
144
@ Test
136
145
public void optionalFile () throws JoranException {
137
146
tc .doConfigure (TOP_OPTIONAL );
138
147
verifyConfig (new String [] { "IA" , "IB" });
139
- StatusPrinter .print (context );
148
+ // StatusPrinter.print(context);
140
149
}
141
150
142
151
@ Test
143
152
public void optionalResource () throws JoranException {
144
153
tc .doConfigure (TOP_OPTIONAL_RESOURCE );
145
154
verifyConfig (new String [] { "IA" , "IB" });
146
- StatusPrinter .print (context );
155
+ // StatusPrinter.print(context);
147
156
Assertions .assertEquals (Status .INFO , statusChecker .getHighestLevel (0 ));
148
157
}
149
158
@@ -158,7 +167,7 @@ public void basicResource() throws JoranException {
158
167
public void basicURL () throws JoranException {
159
168
System .setProperty (INCLUDE_KEY , URL_TO_INCLUDE );
160
169
tc .doConfigure (TOP_BY_URL );
161
- StatusPrinter .print (context );
170
+ // StatusPrinter.print(context);
162
171
verifyConfig (new String [] { "IA" , "IB" });
163
172
}
164
173
@@ -175,7 +184,7 @@ public void withCorruptFile() throws JoranException, IOException {
175
184
System .setProperty (INCLUDE_KEY , tmpOut );
176
185
tc .doConfigure (TOP_BY_FILE );
177
186
Assertions .assertEquals (Status .ERROR , statusChecker .getHighestLevel (0 ));
178
- StatusPrinter .print (context );
187
+ // StatusPrinter.print(context);
179
188
Assertions .assertTrue (statusChecker .containsException (SAXParseException .class ));
180
189
181
190
// we like to erase the temp file in order to see
0 commit comments