Skip to content

Commit 30b1542

Browse files
committed
Added EvaluationContext to API, can be used to add dynamic Operations
1 parent 33cd313 commit 30b1542

57 files changed

Lines changed: 404 additions & 172 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎api-tests/src/test/java/com/ocpsoft/rewrite/config/AndTest.java‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@ public class AndTest
2727
@Test
2828
public void testTrueAndTrueIsTrue()
2929
{
30-
Assert.assertTrue(And.all(new True(), new True()).evaluate(new MockRewrite()));
30+
Assert.assertTrue(And.all(new True(), new True()).evaluate(new MockRewrite(), null));
3131
}
3232

3333
@Test
3434
public void testTrueAndFalseIsFalse()
3535
{
36-
Assert.assertFalse(And.all(new True(), new False()).evaluate(new MockRewrite()));
36+
Assert.assertFalse(And.all(new True(), new False()).evaluate(new MockRewrite(), null));
3737
}
3838

3939
@Test
4040
public void testFalseAndFalseIsFalse()
4141
{
42-
Assert.assertFalse(And.all(new False(), new False()).evaluate(new MockRewrite()));
42+
Assert.assertFalse(And.all(new False(), new False()).evaluate(new MockRewrite(), null));
4343
}
4444
}

‎api-tests/src/test/java/com/ocpsoft/rewrite/config/ConfigurationBuilderTest.java‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919

2020
import org.junit.Test;
2121

22+
import com.ocpsoft.rewrite.EvaluationContext;
23+
import com.ocpsoft.rewrite.event.InboundRewrite;
2224
import com.ocpsoft.rewrite.event.Rewrite;
25+
import com.ocpsoft.rewrite.mock.MockEvaluationContext;
2326

2427
/**
2528
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
@@ -37,17 +40,18 @@ public void testBuildConfiguration()
3740
.perform(operation);
3841

3942
Rule rule = config.getRules().get(0);
40-
MockInboundRewrite rewrite = new MockInboundRewrite();
41-
if (rule.getCondition().evaluate(rewrite))
43+
InboundRewrite rewrite = new MockInboundRewrite();
44+
EvaluationContext context = new MockEvaluationContext();
45+
if (rule.getCondition().evaluate(rewrite, context))
4246
{
43-
rule.getOperation().perform(rewrite);
47+
rule.getOperation().perform(rewrite, context);
4448
}
4549
Assert.assertTrue(performed);
4650
}
4751

4852
Operation operation = new Operation() {
4953
@Override
50-
public void perform(final Rewrite event)
54+
public void perform(final Rewrite event, final EvaluationContext context)
5155
{
5256
performed = true;
5357
}

‎api-tests/src/test/java/com/ocpsoft/rewrite/config/InboundTest.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import org.junit.Assert;
1919
import org.junit.Test;
2020

21+
import com.ocpsoft.rewrite.mock.MockEvaluationContext;
22+
2123
/**
2224
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
2325
*
@@ -29,13 +31,13 @@ public class InboundTest
2931
public void testInboundReturnsTrue()
3032
{
3133
Condition condition = Inbound.only();
32-
Assert.assertTrue(condition.evaluate(new MockInboundRewrite()));
34+
Assert.assertTrue(condition.evaluate(new MockInboundRewrite(), new MockEvaluationContext()));
3335
}
3436

3537
@Test
3638
public void testNotInboundReturnsFalse()
3739
{
3840
Condition condition = Inbound.only();
39-
Assert.assertFalse(condition.evaluate(new MockRewrite()));
41+
Assert.assertFalse(condition.evaluate(new MockRewrite(), new MockEvaluationContext()));
4042
}
4143
}

‎api-tests/src/test/java/com/ocpsoft/rewrite/config/MockInboundRewrite.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package com.ocpsoft.rewrite.config;
1717

18-
import com.ocpsoft.rewrite.RewriteContext;
18+
import com.ocpsoft.rewrite.Context;
1919
import com.ocpsoft.rewrite.event.InboundRewrite;
2020

2121
/**
@@ -24,7 +24,7 @@
2424
public class MockInboundRewrite implements InboundRewrite
2525
{
2626
@Override
27-
public RewriteContext getRewriteContext()
27+
public Context getRewriteContext()
2828
{
2929
return new MockRewriteContext();
3030
}

‎api-tests/src/test/java/com/ocpsoft/rewrite/config/MockOutboundRewrite.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package com.ocpsoft.rewrite.config;
1717

18-
import com.ocpsoft.rewrite.RewriteContext;
18+
import com.ocpsoft.rewrite.Context;
1919
import com.ocpsoft.rewrite.event.OutboundRewrite;
2020

2121
/**
@@ -24,7 +24,7 @@
2424
public class MockOutboundRewrite implements OutboundRewrite
2525
{
2626
@Override
27-
public RewriteContext getRewriteContext()
27+
public Context getRewriteContext()
2828
{
2929
return new MockRewriteContext();
3030
}

‎api-tests/src/test/java/com/ocpsoft/rewrite/config/MockRewrite.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package com.ocpsoft.rewrite.config;
1717

18-
import com.ocpsoft.rewrite.RewriteContext;
18+
import com.ocpsoft.rewrite.Context;
1919
import com.ocpsoft.rewrite.event.Rewrite;
2020

2121
/**
@@ -24,7 +24,7 @@
2424
public class MockRewrite implements Rewrite
2525
{
2626
@Override
27-
public RewriteContext getRewriteContext()
27+
public Context getRewriteContext()
2828
{
2929
return new MockRewriteContext();
3030
}

‎api-tests/src/test/java/com/ocpsoft/rewrite/config/MockRewriteContext.java‎

Lines changed: 2 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,12 @@
1515
*/
1616
package com.ocpsoft.rewrite.config;
1717

18-
import java.util.HashMap;
19-
import java.util.Map;
20-
21-
import com.ocpsoft.rewrite.RewriteContext;
18+
import com.ocpsoft.rewrite.ContextBase;
2219

2320
/**
2421
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
2522
*
2623
*/
27-
public class MockRewriteContext implements RewriteContext
24+
public class MockRewriteContext extends ContextBase
2825
{
29-
30-
private final Map<Object, Object> map = new HashMap<Object, Object>();
31-
32-
@Override
33-
public Object get(final Object key)
34-
{
35-
return map.get(key);
36-
}
37-
38-
@Override
39-
public void put(final Object key, final Object value)
40-
{
41-
map.put(key, value);
42-
}
43-
44-
@Override
45-
public void containsKey(final Object key)
46-
{
47-
map.containsKey(key);
48-
}
49-
5026
}

‎api-tests/src/test/java/com/ocpsoft/rewrite/config/NotTest.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import org.junit.Assert;
1919
import org.junit.Test;
2020

21+
import com.ocpsoft.rewrite.mock.MockEvaluationContext;
22+
2123
/**
2224
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
2325
*
@@ -28,13 +30,13 @@ public class NotTest
2830
public void testNotFalseIsTrue()
2931
{
3032
Condition condition = Not.any(new False());
31-
Assert.assertTrue(condition.evaluate(new MockRewrite()));
33+
Assert.assertTrue(condition.evaluate(new MockRewrite(), new MockEvaluationContext()));
3234
}
3335

3436
@Test
3537
public void testNotTrueIsFalse()
3638
{
3739
Condition condition = Not.any(new True());
38-
Assert.assertFalse(condition.evaluate(new MockRewrite()));
40+
Assert.assertFalse(condition.evaluate(new MockRewrite(), new MockEvaluationContext()));
3941
}
4042
}

‎api-tests/src/test/java/com/ocpsoft/rewrite/config/OrTest.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import org.junit.Assert;
1919
import org.junit.Test;
2020

21+
import com.ocpsoft.rewrite.mock.MockEvaluationContext;
22+
2123
/**
2224
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
2325
*
@@ -27,18 +29,18 @@ public class OrTest
2729
@Test
2830
public void testTrueAndTrueIsTrue()
2931
{
30-
Assert.assertTrue(Or.any(new True(), new True()).evaluate(new MockRewrite()));
32+
Assert.assertTrue(Or.any(new True(), new True()).evaluate(new MockRewrite(), new MockEvaluationContext()));
3133
}
3234

3335
@Test
3436
public void testTrueAndFalseIsTrue()
3537
{
36-
Assert.assertTrue(Or.any(new True(), new False()).evaluate(new MockRewrite()));
38+
Assert.assertTrue(Or.any(new True(), new False()).evaluate(new MockRewrite(), new MockEvaluationContext()));
3739
}
3840

3941
@Test
4042
public void testFalseAndFalseIsFalse()
4143
{
42-
Assert.assertFalse(Or.any(new False(), new False()).evaluate(new MockRewrite()));
44+
Assert.assertFalse(Or.any(new False(), new False()).evaluate(new MockRewrite(), new MockEvaluationContext()));
4345
}
4446
}

‎api-tests/src/test/java/com/ocpsoft/rewrite/config/OutboundTest.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import org.junit.Assert;
1919
import org.junit.Test;
2020

21+
import com.ocpsoft.rewrite.mock.MockEvaluationContext;
22+
2123
/**
2224
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
2325
*
@@ -29,13 +31,13 @@ public class OutboundTest
2931
public void testOutboundReturnsTrue()
3032
{
3133
Condition condition = new Outbound();
32-
Assert.assertTrue(condition.evaluate(new MockOutboundRewrite()));
34+
Assert.assertTrue(condition.evaluate(new MockOutboundRewrite(), new MockEvaluationContext()));
3335
}
3436

3537
@Test
3638
public void testNotOutboundReturnsFalse()
3739
{
3840
Condition condition = new Outbound();
39-
Assert.assertFalse(condition.evaluate(new MockRewrite()));
41+
Assert.assertFalse(condition.evaluate(new MockRewrite(), new MockEvaluationContext()));
4042
}
4143
}

0 commit comments

Comments
 (0)