Skip to content

Commit 7cbb2bb

Browse files
committed
Updated tests and further cleanup of old manual parameter APIs
1 parent 09e7441 commit 7cbb2bb

24 files changed

Lines changed: 150 additions & 429 deletions

‎config-servlet-tests/src/test/java/org/ocpsoft/rewrite/servlet/config/DomainTest.java‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ public void testDomainMatchesInbound()
6161
public void testCanConvertAndValidateDomain() throws Exception
6262
{
6363
MockEvaluationContext context = new MockEvaluationContext();
64-
Hostname.matches("{p}.com").getParameterStore().get("p").convertedBy(new DomainConverter())
65-
.evaluate(inbound, context);
64+
Hostname hostname = Hostname.matches("{p}.com");
65+
hostname.getParameterStore().get("p").convertedBy(new DomainConverter());
66+
hostname.evaluate(inbound, context);
6667

6768
Assert.assertEquals("example", Evaluation.property("p").retrieve(inbound, context));
6869
Assert.assertEquals(new DomainConvertedType("example"),
@@ -73,8 +74,9 @@ public void testCanConvertAndValidateDomain() throws Exception
7374
public void testDomainMatchesBindsInbound()
7475
{
7576
MockEvaluationContext context = new MockEvaluationContext();
76-
Assert.assertTrue(Hostname.matches("{domain}.com").getParameterStore().get("domain")
77-
.bindsTo(Request.attribute("domain"))
77+
Hostname hostname = Hostname.matches("{domain}.com");
78+
hostname.getParameterStore().get("domain").bindsTo(Request.attribute("domain"));
79+
Assert.assertTrue(hostname
7880
.evaluate(inbound, context));
7981

8082
// Invoke the binding.

‎config-servlet-tests/src/test/java/org/ocpsoft/rewrite/servlet/config/HeaderTest.java‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ public void before()
4343
{
4444
request = Mockito.mock(HttpServletRequest.class);
4545
Mockito.when(request.getHeaderNames())
46-
.thenReturn(Collections.enumeration(Arrays.asList("Accept-Charset", "Content-Length")));
46+
.thenReturn(Collections.enumeration(Arrays.asList("Accept-Charset", "Content-Length")));
4747

4848
Mockito.when(request.getHeaders("Content-Length"))
49-
.thenReturn(Collections.enumeration(Arrays.asList("06091984")));
49+
.thenReturn(Collections.enumeration(Arrays.asList("06091984")));
5050

5151
Mockito.when(request.getHeaders("Accept-Charset"))
52-
.thenReturn(Collections.enumeration(Arrays.asList("ISO-9965", "UTF-8")));
52+
.thenReturn(Collections.enumeration(Arrays.asList("ISO-9965", "UTF-8")));
5353

5454
rewrite = new HttpInboundRewriteImpl(request, null, null);
5555
}
@@ -81,9 +81,9 @@ public void testHeaderContains()
8181
@Test
8282
public void testHeaderMatches()
8383
{
84-
Assert.assertTrue(Header.matches("Accept-Charset", "{enc}").getParameterStore().get("enc").matches("(ISO|UTF)-\\d+")
85-
.evaluate(rewrite,
86-
new MockEvaluationContext()));
84+
Header header = Header.matches("Accept-Charset", "{enc}");
85+
header.getParameterStore().get("enc").matches("(ISO|UTF)-\\d+");
86+
Assert.assertTrue(header.evaluate(rewrite, new MockEvaluationContext()));
8787
}
8888

8989
@Test

‎config-servlet-tests/src/test/java/org/ocpsoft/rewrite/servlet/config/JoinConstrainedTargetTest.java‎

Lines changed: 0 additions & 79 deletions
This file was deleted.

‎config-servlet-tests/src/test/java/org/ocpsoft/rewrite/servlet/config/RequestParameterTest.java‎

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ public void before()
4343
{
4444
request = Mockito.mock(HttpServletRequest.class);
4545
Mockito.when(request.getParameterNames())
46-
.thenReturn(Collections.enumeration(Arrays.asList("foo", "baz")));
46+
.thenReturn(Collections.enumeration(Arrays.asList("foo", "baz")));
4747

4848
Mockito.when(request.getParameterValues("foo"))
49-
.thenReturn(new String[] { "bar" });
49+
.thenReturn(new String[] { "bar" });
5050

5151
Mockito.when(request.getParameterValues("baz"))
52-
.thenReturn(new String[] { "cab", "caz" });
52+
.thenReturn(new String[] { "cab", "caz" });
5353

5454
Mockito.when(request.getParameter("foo"))
55-
.thenReturn("bar");
55+
.thenReturn("bar");
5656

5757
Mockito.when(request.getParameter("baz"))
58-
.thenReturn("cab");
58+
.thenReturn("cab");
5959

6060
rewrite = new HttpInboundRewriteImpl(request, null, null);
6161
}
@@ -87,15 +87,17 @@ public void testRequestParameterContains()
8787
@Test
8888
public void testRequestParameterMatches()
8989
{
90-
Assert.assertTrue(RequestParameter.matches("foo", "{value}").getParameterStore().get("value").matches("(bar|baz)")
91-
.evaluate(rewrite, new MockEvaluationContext()));
90+
RequestParameter requestParam = RequestParameter.matches("foo", "{value}");
91+
requestParam.getParameterStore().get("value").matches("(bar|baz)");
92+
Assert.assertTrue(requestParam.evaluate(rewrite, new MockEvaluationContext()));
9293
}
9394

9495
@Test
9596
public void testRequestParameterMatchesAll()
9697
{
97-
Assert.assertTrue(RequestParameter.matchesAll("baz", "{value}").getParameterStore().get("value").matches("(cab|caz)")
98-
.evaluate(rewrite, new MockEvaluationContext()));
98+
RequestParameter requestParam = RequestParameter.matchesAll("baz", "{value}");
99+
requestParam.getParameterStore().get("value").matches("(cab|caz)");
100+
Assert.assertTrue(requestParam.evaluate(rewrite, new MockEvaluationContext()));
99101
}
100102

101103
@Test
@@ -108,22 +110,25 @@ public void testRequestParameterMatchesAllNamesAllValues()
108110
@Test
109111
public void testRequestParameterMatchesAllNamesNotValues()
110112
{
111-
Assert.assertFalse(RequestParameter.matchesAll("{name}", "{value}").getParameterStore().get("value").matches("nothing")
112-
.evaluate(rewrite, new MockEvaluationContext()));
113+
RequestParameter requestParam = RequestParameter.matchesAll("{name}", "{value}");
114+
requestParam.getParameterStore().get("value").matches("nothing");
115+
Assert.assertFalse(requestParam.evaluate(rewrite, new MockEvaluationContext()));
113116
}
114117

115118
@Test
116119
public void testRequestParameterMatchesAllNotName()
117120
{
118-
Assert.assertFalse(RequestParameter.matchesAll("{name}", "{value}").getParameterStore().get("name").matches("nothing")
119-
.evaluate(rewrite, new MockEvaluationContext()));
121+
RequestParameter requestParam = RequestParameter.matchesAll("{name}", "{value}");
122+
requestParam.getParameterStore().get("name").matches("nothing");
123+
Assert.assertFalse(requestParam.evaluate(rewrite, new MockEvaluationContext()));
120124
}
121125

122126
@Test
123127
public void testRequestParameterMatchesAllInvalid()
124128
{
125-
Assert.assertFalse(RequestParameter.matchesAll("baz", "{value}").getParameterStore().get("value").matches("(cab|xxx)")
126-
.evaluate(rewrite, new MockEvaluationContext()));
129+
RequestParameter requestParam = RequestParameter.matchesAll("baz", "{value}");
130+
requestParam.getParameterStore().get("value").matches("(cab|xxx)");
131+
Assert.assertFalse(requestParam.evaluate(rewrite, new MockEvaluationContext()));
127132
}
128133

129134
@Test

‎config-servlet-tests/src/test/java/org/ocpsoft/rewrite/servlet/config/SchemeTest.java‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,9 @@ public void testSchemeMatchesInbound()
6161
public void testShemeMatchesBindsInbound()
6262
{
6363
MockEvaluationContext context = new MockEvaluationContext();
64-
Assert.assertTrue(Scheme.matches("{scheme}").getParameterStore().get("scheme").bindsTo(Request.attribute("scheme"))
65-
.evaluate(inbound, context));
64+
Scheme scheme = Scheme.matches("{scheme}");
65+
scheme.getParameterStore().get("scheme").bindsTo(Request.attribute("scheme"));
66+
Assert.assertTrue(scheme.evaluate(inbound, context));
6667

6768
// Invoke the binding.
6869
context.getPreOperations().get(0).perform(inbound, context);

‎config-servlet-tests/src/test/java/org/ocpsoft/rewrite/servlet/config/URLTest.java‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
22
* Copyright 2011 <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
3-
*
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -33,7 +33,7 @@
3333

3434
/**
3535
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
36-
*
36+
*
3737
*/
3838
public class URLTest
3939
{
@@ -46,22 +46,22 @@ public void before()
4646
request = Mockito.mock(HttpServletRequest.class);
4747

4848
Mockito.when(request.getRequestURI())
49-
.thenReturn("/context/application/path");
49+
.thenReturn("/context/application/path");
5050

5151
Mockito.when(request.getContextPath())
52-
.thenReturn("/context");
52+
.thenReturn("/context");
5353

5454
Mockito.when(request.getQueryString())
55-
.thenReturn("foo=bar&baz=bazaar");
55+
.thenReturn("foo=bar&baz=bazaar");
5656

5757
Mockito.when(request.getScheme())
58-
.thenReturn("http");
58+
.thenReturn("http");
5959

6060
Mockito.when(request.getServerName())
61-
.thenReturn("domain.com");
61+
.thenReturn("domain.com");
6262

6363
Mockito.when(request.getServerPort())
64-
.thenReturn(8080);
64+
.thenReturn(8080);
6565

6666
rewrite = new HttpInboundRewriteImpl(request, null, null);
6767
}
@@ -77,10 +77,10 @@ public void testMatchesWithParameters()
7777
public void testAttemptsToBindParameters()
7878
{
7979
MockBinding mockBinding = new MockBinding();
80-
IURL url = URL.matches("{prefix}/application/{seg}{suffix}")
81-
.where("prefix").matches(".*")
82-
.where("suffix").matches("\\?.*")
83-
.where("seg").bindsTo(mockBinding);
80+
URL url = URL.matches("{prefix}/application/{seg}{suffix}");
81+
url.getParameterStore().get("prefix").matches(".*");
82+
url.getParameterStore().get("suffix").matches("\\?.*");
83+
url.getParameterStore().get("seg").bindsTo(mockBinding);
8484
MockEvaluationContext context = new MockEvaluationContext();
8585
Assert.assertTrue(url.evaluate(rewrite, context));
8686

@@ -101,8 +101,8 @@ public void testAttemptsToBindParameters()
101101
public void testCaptureInBindsParameters()
102102
{
103103
MockBinding mockBinding = new MockBinding();
104-
IURL url = URL.captureIn("foo")
105-
.where("foo").bindsTo(mockBinding);
104+
URL url = URL.captureIn("foo");
105+
url.getParameterStore().get("foo").bindsTo(mockBinding);
106106
MockEvaluationContext context = new MockEvaluationContext();
107107
Assert.assertTrue(url.evaluate(rewrite, context));
108108

‎config-servlet/src/main/java/org/ocpsoft/rewrite/servlet/config/DispatchType.java‎

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@
2323
import org.ocpsoft.common.pattern.WeightedComparator;
2424
import org.ocpsoft.common.services.ServiceLoader;
2525
import org.ocpsoft.common.util.Iterators;
26-
import org.ocpsoft.rewrite.bind.Bindable;
27-
import org.ocpsoft.rewrite.bind.Binding;
28-
import org.ocpsoft.rewrite.bind.Bindings;
29-
import org.ocpsoft.rewrite.bind.DefaultBindable;
3026
import org.ocpsoft.rewrite.context.EvaluationContext;
3127
import org.ocpsoft.rewrite.servlet.DispatcherType;
3228
import org.ocpsoft.rewrite.servlet.http.event.HttpServletRewrite;
@@ -37,13 +33,10 @@
3733
*
3834
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
3935
*/
40-
public class DispatchType extends HttpCondition implements Bindable<DispatchType>
36+
public class DispatchType extends HttpCondition
4137
{
4238
private final DispatcherType type;
4339

44-
@SuppressWarnings("rawtypes")
45-
private final DefaultBindable<?> bindable = new DefaultBindable();
46-
4740
private final List<DispatcherTypeProvider> providers;
4841

4942
private DispatchType(final DispatcherType type)
@@ -62,7 +55,6 @@ public boolean evaluateHttp(final HttpServletRewrite event, final EvaluationCont
6255
{
6356
if (this.type.equals(getDispatcherType(event)))
6457
{
65-
Bindings.enqueueSubmission(event, context, bindable, type);
6658
return true;
6759
}
6860
return false;
@@ -133,11 +125,4 @@ public String toString()
133125
return type == null ? "unknown" : type.toString();
134126
}
135127

136-
@Override
137-
public DispatchType bindsTo(final Binding binding)
138-
{
139-
bindable.bindsTo(binding);
140-
return this;
141-
}
142-
143128
}

0 commit comments

Comments
 (0)