Skip to content

Commit 2bab38f

Browse files
committed
Updated some demos. Fixed bug with Operations that returned null from getRequredParameters(). Tried to get tests passing a bit closer.
1 parent 462ba31 commit 2bab38f

14 files changed

Lines changed: 197 additions & 14 deletions

File tree

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package org.ocpsoft.rewrite.param;
2+
3+
import java.util.Set;
4+
5+
import org.ocpsoft.rewrite.config.Configuration;
6+
import org.ocpsoft.rewrite.config.ConfigurationBuilder;
7+
import org.ocpsoft.rewrite.config.ConfigurationProvider;
8+
import org.ocpsoft.rewrite.config.Operation;
9+
import org.ocpsoft.rewrite.context.EvaluationContext;
10+
import org.ocpsoft.rewrite.event.Rewrite;
11+
12+
/**
13+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
14+
*
15+
*/
16+
public class ParameterizedOperationConfigurationProvider implements ConfigurationProvider<Object>
17+
{
18+
19+
public class ParameterizedOperation implements Operation, Parameterized
20+
{
21+
22+
@Override
23+
public void perform(Rewrite event, EvaluationContext context)
24+
{}
25+
26+
@Override
27+
public Set<String> getRequiredParameterNames()
28+
{
29+
return null;
30+
}
31+
32+
@Override
33+
public void setParameterStore(ParameterStore store)
34+
{}
35+
36+
}
37+
38+
public int priority()
39+
{
40+
return 0;
41+
}
42+
43+
@Override
44+
public boolean handles(final Object payload)
45+
{
46+
return true;
47+
}
48+
49+
@Override
50+
public Configuration getConfiguration(final Object context)
51+
{
52+
return ConfigurationBuilder.begin().addRule().perform(new ParameterizedOperation());
53+
}
54+
55+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright 2011 <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.ocpsoft.rewrite.param;
17+
18+
import org.apache.http.client.methods.HttpGet;
19+
import org.jboss.arquillian.container.test.api.Deployment;
20+
import org.jboss.shrinkwrap.api.asset.StringAsset;
21+
import org.jboss.shrinkwrap.api.spec.WebArchive;
22+
import org.junit.Assert;
23+
import org.junit.Test;
24+
import org.ocpsoft.rewrite.Root;
25+
import org.ocpsoft.rewrite.config.ConfigurationProvider;
26+
import org.ocpsoft.rewrite.test.HttpAction;
27+
import org.ocpsoft.rewrite.test.RewriteTest;
28+
29+
/**
30+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
31+
*
32+
*/
33+
public class ParameterizedOperationTest extends RewriteTest
34+
{
35+
@Deployment(testable = false)
36+
public static WebArchive getDeployment()
37+
{
38+
WebArchive deployment = RewriteTest
39+
.getDeployment()
40+
.addPackages(true, Root.class.getPackage())
41+
.addAsWebResource(new StringAsset("exists"), "index.html")
42+
.addAsServiceProvider(ConfigurationProvider.class, ParameterizedOperationConfigurationProvider.class);
43+
return deployment;
44+
}
45+
46+
@Test
47+
public void testParameterizedOperationReturningNullParametersDeploysNormally() throws Exception
48+
{
49+
HttpAction<HttpGet> action = get("/index.html");
50+
Assert.assertEquals(200, action.getResponse().getStatusLine().getStatusCode());
51+
}
52+
53+
}

‎api/src/main/java/org/ocpsoft/rewrite/config/ConfigurationLoader.java‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,12 @@ public void call(Parameterized parameterized)
186186
Set<String> names = parameterized.getRequiredParameterNames();
187187
ParameterStore store = ((RuleBuilder) rule).getParameterStore();
188188

189-
for (String name : names) {
190-
Parameter<?> parameter = store.get(name, new DefaultParameter(name));
191-
if (parameter instanceof ConfigurableParameter<?>)
192-
((ConfigurableParameter<?>) parameter).bindsTo(Evaluation.property(name));
193-
}
189+
if (names != null)
190+
for (String name : names) {
191+
Parameter<?> parameter = store.get(name, new DefaultParameter(name));
192+
if (parameter instanceof ConfigurableParameter<?>)
193+
((ConfigurableParameter<?>) parameter).bindsTo(Evaluation.property(name));
194+
}
194195

195196
parameterized.setParameterStore(store);
196197
}

‎integration-cdi-tests/src/test/java/test/org/ocpsoft/rewrite/cdi/action/DeferredActionsTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class DeferredActionsTest extends RewriteTestBase
1919
@Deployment(testable = false)
2020
public static WebArchive getDeployment()
2121
{
22-
return RewriteTest.getDeploymentWithCDI()
22+
return RewriteTest.getDeploymentWithFacesAndCDI()
2323
.addAsLibrary(RewriteELTest.getRewriteAnnotationArchive())
2424
.addAsLibrary(RewriteELTest.getRewriteFacesArchive())
2525
.addAsLibrary(RewriteELTest.getRewriteCDIArchive())

‎integration-cdi-tests/src/test/java/test/org/ocpsoft/rewrite/cdi/action/IgnorePostbackBean.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
package test.org.ocpsoft.rewrite.cdi.action;
3232

3333
import javax.enterprise.context.RequestScoped;
34+
import javax.faces.bean.ManagedBean;
3435
import javax.inject.Named;
3536

3637
import org.ocpsoft.rewrite.annotation.Join;
@@ -40,6 +41,7 @@
4041

4142
@Named
4243
@RequestScoped
44+
@ManagedBean
4345
@Join(path = "/action", to = "/faces/action.xhtml")
4446
public class IgnorePostbackBean
4547
{

‎integration-cdi-tests/src/test/java/test/org/ocpsoft/rewrite/cdi/action/IgnorePostbackTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class IgnorePostbackTest extends RewriteTestBase
1919
@Deployment(testable = false)
2020
public static WebArchive getDeployment()
2121
{
22-
WebArchive deployment = RewriteTest.getDeploymentWithCDI()
22+
WebArchive deployment = RewriteTest.getDeploymentWithFacesAndCDI()
2323
.addAsLibrary(RewriteELTest.getRewriteAnnotationArchive())
2424
.addAsLibrary(RewriteELTest.getRewriteFacesArchive())
2525
.addAsLibrary(RewriteELTest.getRewriteCDIArchive())

‎integration-cdi-tests/src/test/java/test/org/ocpsoft/rewrite/cdi/binding/BindingPostbackTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class BindingPostbackTest extends RewriteTestBase
1919
@Deployment(testable = false)
2020
public static WebArchive getDeployment()
2121
{
22-
return RewriteTest.getDeploymentWithCDI()
22+
return RewriteTest.getDeploymentWithFacesAndCDI()
2323
.addAsLibrary(RewriteELTest.getRewriteAnnotationArchive())
2424
.addAsLibrary(RewriteELTest.getRewriteFacesArchive())
2525
.addAsLibrary(RewriteELTest.getRewriteCDIArchive())

‎integration-cdi-tests/src/test/java/test/org/ocpsoft/rewrite/cdi/binding/DeferredBindingTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class DeferredBindingTest extends RewriteTestBase
1919
@Deployment(testable = false)
2020
public static WebArchive getDeployment()
2121
{
22-
return RewriteTest.getDeploymentWithCDI()
22+
return RewriteTest.getDeploymentWithFacesAndCDI()
2323
.addAsLibrary(RewriteELTest.getRewriteAnnotationArchive())
2424
.addAsLibrary(RewriteELTest.getRewriteFacesArchive())
2525
.addAsLibrary(RewriteELTest.getRewriteCDIArchive())

‎integration-cdi-tests/src/test/java/test/org/ocpsoft/rewrite/cdi/convert/BindingConverterTest.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class BindingConverterTest extends RewriteTestBase
3434
@Deployment(testable = false)
3535
public static WebArchive getDeployment()
3636
{
37-
return RewriteTest.getDeploymentWithCDI()
37+
return RewriteTest.getDeploymentWithFacesAndCDI()
3838
.addAsLibrary(RewriteELTest.getRewriteAnnotationArchive())
3939
.addAsLibrary(RewriteELTest.getRewriteFacesArchive())
4040
.addAsLibrary(RewriteELTest.getRewriteCDIArchive())

‎showcase/access-control/src/main/java/org/ocpsoft/rewrite/showcase/access/AccessRewriteConfiguration.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ public Configuration getConfiguration(final ServletContext context)
3636
* Domain based access control (only grants access to specific domains)
3737
*/
3838
.addRule(Join.path("/domain").to("/domain.xhtml").withInboundCorrection())
39-
.when(Direction.isInbound().andNot(Domain.matches("localhost").or(Domain.matches("{*}rhcloud{*}"))))
39+
.when(Direction.isInbound().and(Domain.matches("localhost").or(Domain.matches("{*}rhcloud{*}"))))
4040

4141
/*
4242
* Time based access control (only grants access during the first half of each minute)
4343
*/
4444
.addRule(Join.path("/timer").to("/timer.xhtml").withInboundCorrection())
45-
.when(Direction.isInbound().andNot(JodaTime.matches(timeGranted)))
45+
.when(Direction.isInbound().and(JodaTime.matches(timeGranted)))
4646

4747
.addRule()
4848
.when(Direction.isInbound()

0 commit comments

Comments
 (0)