3737 */
3838public class ConfigurationBuilderTest
3939{
40+ private int performCount = 0 ;
41+ private int performOtherwiseCount = 0 ;
4042 private boolean performed = false ;
4143 private boolean performedOtherwise = false ;
4244 private Operation operation ;
@@ -53,13 +55,15 @@ public void before()
5355 @ Override
5456 public void perform (final Rewrite event , final EvaluationContext context )
5557 {
58+ performCount ++;
5659 performed = true ;
5760 }
5861 };
5962 otherwise = new Operation () {
6063 @ Override
6164 public void perform (final Rewrite event , final EvaluationContext context )
6265 {
66+ performOtherwiseCount ++;
6367 performedOtherwise = true ;
6468 }
6569 };
@@ -73,6 +77,22 @@ private void execute(Configuration config)
7377 }
7478 }
7579
80+ @ Test
81+ public void testBuildConfigurationCompositeWhenPerformOnly ()
82+ {
83+ Assert .assertFalse (performed );
84+ Assert .assertFalse (performedOtherwise );
85+
86+ Configuration config = ConfigurationBuilder .begin ().addRule ()
87+ .when (Direction .isInbound (), new True ())
88+ .perform (operation );
89+
90+ execute (config );
91+
92+ Assert .assertTrue (performed );
93+ Assert .assertFalse (performedOtherwise );
94+ }
95+
7696 @ Test
7797 public void testBuildConfigurationPerformOnly ()
7898 {
@@ -89,6 +109,24 @@ public void testBuildConfigurationPerformOnly()
89109 Assert .assertFalse (performedOtherwise );
90110 }
91111
112+ @ Test
113+ public void testBuildConfigurationPerformMultipleOnly ()
114+ {
115+ Assert .assertFalse (performed );
116+ Assert .assertFalse (performedOtherwise );
117+
118+ Configuration config = ConfigurationBuilder .begin ().addRule ()
119+ .when (And .all (Direction .isInbound (), new True ()))
120+ .perform (operation , operation , operation );
121+
122+ execute (config );
123+
124+ Assert .assertEquals (3 , performCount );
125+ Assert .assertEquals (0 , performOtherwiseCount );
126+ Assert .assertTrue (performed );
127+ Assert .assertFalse (performedOtherwise );
128+ }
129+
92130 @ Test
93131 public void testBuildConfigurationPerformOnlyNegative ()
94132 {
@@ -105,6 +143,22 @@ public void testBuildConfigurationPerformOnlyNegative()
105143 Assert .assertFalse (performedOtherwise );
106144 }
107145
146+ @ Test
147+ public void testBuildConfigurationCompositeConditionPerformOnlyNegative ()
148+ {
149+ Assert .assertFalse (performed );
150+ Assert .assertFalse (performedOtherwise );
151+
152+ Configuration config = ConfigurationBuilder .begin ().addRule ()
153+ .when (new True (), new False ())
154+ .perform (operation );
155+
156+ execute (config );
157+
158+ Assert .assertFalse (performed );
159+ Assert .assertFalse (performedOtherwise );
160+ }
161+
108162 @ Test
109163 public void testBuildConfigurationOtherwiseOnly ()
110164 {
@@ -121,6 +175,40 @@ public void testBuildConfigurationOtherwiseOnly()
121175 Assert .assertTrue (performedOtherwise );
122176 }
123177
178+ @ Test
179+ public void testBuildConfigurationCompositeConditionOtherwiseOnly ()
180+ {
181+ Assert .assertFalse (performed );
182+ Assert .assertFalse (performedOtherwise );
183+
184+ Configuration config = ConfigurationBuilder .begin ().addRule ()
185+ .when (new True (), new False ())
186+ .otherwise (otherwise );
187+
188+ execute (config );
189+
190+ Assert .assertFalse (performed );
191+ Assert .assertTrue (performedOtherwise );
192+ }
193+
194+ @ Test
195+ public void testBuildConfigurationOtherwiseMultipleOnly ()
196+ {
197+ Assert .assertFalse (performed );
198+ Assert .assertFalse (performedOtherwise );
199+
200+ Configuration config = ConfigurationBuilder .begin ().addRule ()
201+ .when (new False ())
202+ .otherwise (otherwise , otherwise );
203+
204+ execute (config );
205+
206+ Assert .assertEquals (0 , performCount );
207+ Assert .assertEquals (2 , performOtherwiseCount );
208+ Assert .assertFalse (performed );
209+ Assert .assertTrue (performedOtherwise );
210+ }
211+
124212 @ Test
125213 public void testBuildConfigurationOtherwiseNegative ()
126214 {
@@ -137,6 +225,22 @@ public void testBuildConfigurationOtherwiseNegative()
137225 Assert .assertFalse (performedOtherwise );
138226 }
139227
228+ @ Test
229+ public void testBuildConfigurationCompositeConditionOtherwiseNegative ()
230+ {
231+ Assert .assertFalse (performed );
232+ Assert .assertFalse (performedOtherwise );
233+
234+ Configuration config = ConfigurationBuilder .begin ().addRule ()
235+ .when (new True (), new True ())
236+ .otherwise (otherwise );
237+
238+ execute (config );
239+
240+ Assert .assertFalse (performed );
241+ Assert .assertFalse (performedOtherwise );
242+ }
243+
140244 @ Test
141245 public void testBuildConfigurationPerformAndOtherwise () throws Exception
142246 {
@@ -218,15 +322,14 @@ public void testMetadataAPI() throws Exception
218322 .withMetadata (null , null )
219323 .addRule ();
220324
221-
222325 ConfigurationBuilder .begin ().addRule ()
223326 .when (new False ())
224327 .perform (operation )
225328 .withId (null )
226329 .withPriority (12 )
227330 .withMetadata (null , null )
228331 .addRule ();
229-
332+
230333 ConfigurationBuilder .begin ().addRule ()
231334 .when (new False ())
232335 .perform (operation )
@@ -352,6 +455,10 @@ public void testFluentAPI() throws Exception
352455 .addRule ()
353456 .perform (operation ).addRule ();
354457
458+ ConfigurationBuilder .begin ()
459+ .addRule ()
460+ .perform (operation , operation ).addRule ();
461+
355462 ConfigurationBuilder .begin ()
356463 .addRule ()
357464 .perform (operation )
@@ -370,6 +477,20 @@ public void testFluentAPI() throws Exception
370477 .withId ("id" )
371478 .withPriority (0 ).addRule ();
372479
480+ ConfigurationBuilder .begin ()
481+ .addRule ()
482+ .perform (operation , operation )
483+ .otherwise (otherwise , otherwise )
484+ .withId ("id" )
485+ .withPriority (0 ).addRule ();
486+
487+ ConfigurationBuilder .begin ()
488+ .addRule ()
489+ .perform (operation )
490+ .otherwise (otherwise , otherwise )
491+ .withId ("id" )
492+ .withPriority (0 ).addRule ();
493+
373494 ConfigurationBuilder .begin ()
374495 .addRule ()
375496 .when (new False ())
0 commit comments