Skip to content

Commit f8a992f

Browse files
committed
Added some tests for Subset API
1 parent f8ba7d8 commit f8a992f

4 files changed

Lines changed: 217 additions & 0 deletions

File tree

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright 2013 <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.config;
17+
18+
import org.apache.http.client.methods.HttpGet;
19+
import org.jboss.arquillian.container.test.api.Deployment;
20+
import org.jboss.shrinkwrap.api.spec.WebArchive;
21+
import org.junit.Assert;
22+
import org.junit.Test;
23+
import org.ocpsoft.rewrite.Root;
24+
import org.ocpsoft.rewrite.test.HttpAction;
25+
import org.ocpsoft.rewrite.test.RewriteTest;
26+
27+
/**
28+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
29+
*
30+
*/
31+
public class SubsetConfigurationTest extends RewriteTest
32+
{
33+
34+
@Deployment(testable = false)
35+
public static WebArchive getDeployment()
36+
{
37+
WebArchive deployment = RewriteTest
38+
.getDeployment()
39+
.addPackages(true, Root.class.getPackage())
40+
.addAsServiceProvider(ConfigurationProvider.class,
41+
SubsetConfigurationTestProvider.class);
42+
return deployment;
43+
}
44+
45+
@Test
46+
public void testSubsetBasicFlowControlPerform() throws Exception
47+
{
48+
HttpAction<HttpGet> action = get("/subset/perform");
49+
Assert.assertEquals(200, action.getResponse().getStatusLine().getStatusCode());
50+
}
51+
52+
@Test
53+
public void testSubsetBasicFlowControlOtherwise() throws Exception
54+
{
55+
HttpAction<HttpGet> action = get("/subset/otherwise");
56+
Assert.assertEquals(201, action.getResponse().getStatusLine().getStatusCode());
57+
}
58+
59+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2013 <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.config;
17+
18+
import org.ocpsoft.rewrite.servlet.config.Path;
19+
import org.ocpsoft.rewrite.servlet.config.SendStatus;
20+
21+
/**
22+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
23+
*
24+
*/
25+
public class SubsetConfigurationTestProvider implements ConfigurationProvider<Object>
26+
{
27+
28+
public int priority()
29+
{
30+
return 0;
31+
}
32+
33+
@Override
34+
public boolean handles(final Object payload)
35+
{
36+
return true;
37+
}
38+
39+
@Override
40+
public Configuration getConfiguration(final Object context)
41+
{
42+
return ConfigurationBuilder.begin()
43+
.addRule()
44+
.perform(Subset.evaluate(ConfigurationBuilder.begin()
45+
46+
.addRule()
47+
.when(Path.matches("/subset/perform"))
48+
.perform(SendStatus.code(200))
49+
.otherwise(SendStatus.code(201))
50+
51+
));
52+
}
53+
54+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2013 <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.config;
17+
18+
import org.jboss.arquillian.container.spi.client.container.DeploymentException;
19+
import org.jboss.arquillian.container.test.api.Deployment;
20+
import org.jboss.arquillian.container.test.api.ShouldThrowException;
21+
import org.jboss.shrinkwrap.api.spec.WebArchive;
22+
import org.junit.Test;
23+
import org.ocpsoft.rewrite.Root;
24+
import org.ocpsoft.rewrite.test.RewriteTest;
25+
26+
/**
27+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
28+
*
29+
*/
30+
public class SubsetParameterReconfigurationTest
31+
{
32+
@Deployment(testable = false)
33+
@ShouldThrowException(DeploymentException.class)
34+
public static WebArchive getDeployment()
35+
{
36+
WebArchive deployment = RewriteTest
37+
.getDeployment()
38+
.addPackages(true, Root.class.getPackage())
39+
.addAsServiceProvider(ConfigurationProvider.class,
40+
SubsetParameterReconfigurationTestProvider.class);
41+
return deployment;
42+
}
43+
44+
@Test
45+
public void testSubsetParameterReconfigurationIsDeploymentFailure() throws Exception
46+
{}
47+
48+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* Copyright 2013 <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.config;
17+
18+
import org.ocpsoft.rewrite.servlet.config.Path;
19+
import org.ocpsoft.rewrite.servlet.config.SendStatus;
20+
21+
/**
22+
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
23+
*
24+
*/
25+
public class SubsetParameterReconfigurationTestProvider implements ConfigurationProvider<Object>
26+
{
27+
28+
public int priority()
29+
{
30+
return 0;
31+
}
32+
33+
@Override
34+
public boolean handles(final Object payload)
35+
{
36+
return true;
37+
}
38+
39+
@Override
40+
public Configuration getConfiguration(final Object context)
41+
{
42+
return ConfigurationBuilder.begin()
43+
.addRule()
44+
.when(Path.matches("/{path}"))
45+
.perform(Subset.evaluate(ConfigurationBuilder.begin()
46+
.addRule()
47+
.when(Path.matches("/{path}/foo"))
48+
.perform(SendStatus.code(200))
49+
.where("path").matches("x")
50+
)
51+
)
52+
.where("path").matches(".*");
53+
54+
}
55+
56+
}

0 commit comments

Comments
 (0)