3232
3333/**
3434 * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
35- *
35+ *
3636 */
3737public class ConfigurationBuilderTest
3838{
@@ -64,12 +64,12 @@ public void perform(final Rewrite event, final EvaluationContext context)
6464 };
6565 }
6666
67- private void execute (Rule rule )
67+ private void execute (Configuration config )
6868 {
69- if ( rule . evaluate ( rewrite , context ))
70- rule .perform (rewrite , context );
71- else
72- rule . otherwise ( rewrite , context );
69+ for ( Rule rule : config . getRules ()) {
70+ if ( rule .evaluate (rewrite , context ))
71+ rule . perform ( rewrite , context );
72+ }
7373 }
7474
7575 @ Test
@@ -82,8 +82,7 @@ public void testBuildConfigurationPerformOnly()
8282 .when (And .all (Direction .isInbound (), new True ()))
8383 .perform (operation );
8484
85- Rule rule = config .getRules ().get (0 );
86- execute (rule );
85+ execute (config );
8786
8887 Assert .assertTrue (performed );
8988 Assert .assertFalse (performedOtherwise );
@@ -99,8 +98,7 @@ public void testBuildConfigurationPerformOnlyNegative()
9998 .when (And .all (new False ()))
10099 .perform (operation );
101100
102- Rule rule = config .getRules ().get (0 );
103- execute (rule );
101+ execute (config );
104102
105103 Assert .assertFalse (performed );
106104 Assert .assertFalse (performedOtherwise );
@@ -116,8 +114,7 @@ public void testBuildConfigurationOtherwiseOnly()
116114 .when (new False ())
117115 .otherwise (otherwise );
118116
119- Rule rule = config .getRules ().get (0 );
120- execute (rule );
117+ execute (config );
121118
122119 Assert .assertFalse (performed );
123120 Assert .assertTrue (performedOtherwise );
@@ -133,8 +130,7 @@ public void testBuildConfigurationOtherwiseNegative()
133130 .when (new True ())
134131 .otherwise (otherwise );
135132
136- Rule rule = config .getRules ().get (0 );
137- execute (rule );
133+ execute (config );
138134
139135 Assert .assertFalse (performed );
140136 Assert .assertFalse (performedOtherwise );
@@ -152,8 +148,7 @@ public void testBuildConfigurationPerformAndOtherwise() throws Exception
152148 .perform (operation )
153149 .otherwise (otherwise );
154150
155- Rule rule = config .getRules ().get (0 );
156- execute (rule );
151+ execute (config );
157152
158153 Assert .assertTrue (performed );
159154 Assert .assertFalse (performedOtherwise );
@@ -171,8 +166,7 @@ public void testBuildConfigurationPerformAndOtherwiseNegative() throws Exception
171166 .perform (operation )
172167 .otherwise (otherwise );
173168
174- Rule rule = config .getRules ().get (0 );
175- execute (rule );
169+ execute (config );
176170
177171 Assert .assertFalse (performed );
178172 Assert .assertTrue (performedOtherwise );
@@ -181,13 +175,19 @@ public void testBuildConfigurationPerformAndOtherwiseNegative() throws Exception
181175 @ Test
182176 public void testSubsetAPI () throws Exception
183177 {
184- ConfigurationBuilder .begin ()
178+ Configuration config = ConfigurationBuilder .begin ()
185179
186180 .addRule ()
187- .when (Path .matches ("/admin" ))
188- .perform (Subset .when (JAASRoles .required ("admin" ))
189- .otherwise (SendError .code (401 )))
190- .otherwise (SendStatus .code (201 ));
181+ .when (new False ())
182+ .otherwise (Subset .when (ConfigurationBuilder .begin ()
183+ .addRule ()
184+ .when (new True ())
185+ .perform (operation )));
186+
187+ execute (config );
188+
189+ Assert .assertTrue (performed );
190+ Assert .assertFalse (performedOtherwise );
191191 }
192192
193193 @ Test
0 commit comments