Skip to content

Commit 1198929

Browse files
committed
Added an Arquillian test for the Spring integration
1 parent 1a73545 commit 1198929

9 files changed

Lines changed: 242 additions & 7 deletions

File tree

‎integration-spring/pom.xml‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@
3535
<artifactId>jboss-servlet-api_3.0_spec</artifactId>
3636
</dependency>
3737

38+
<dependency>
39+
<groupId>com.ocpsoft.rewrite</groupId>
40+
<artifactId>rewrite-test-harness</artifactId>
41+
</dependency>
42+
3843
</dependencies>
3944

4045
</project>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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 com.ocpsoft.rewrite.spring;
17+
18+
import org.springframework.stereotype.Component;
19+
20+
/**
21+
* @author Christian Kaltepoth
22+
*/
23+
@Component
24+
public class SpringFeaturesBean {
25+
26+
private String name;
27+
28+
private String uppercase;
29+
30+
public void action() {
31+
uppercase = name != null ? name.toUpperCase() : null;
32+
}
33+
34+
public String getName() {
35+
return name;
36+
}
37+
38+
public void setName(String name) {
39+
this.name = name;
40+
}
41+
42+
public String getUppercase() {
43+
return uppercase;
44+
}
45+
46+
public void setUppercase(String uppercase) {
47+
this.uppercase = uppercase;
48+
}
49+
50+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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 com.ocpsoft.rewrite.spring;
17+
18+
import javax.servlet.ServletContext;
19+
20+
import com.ocpsoft.rewrite.bind.El;
21+
import com.ocpsoft.rewrite.config.Configuration;
22+
import com.ocpsoft.rewrite.config.ConfigurationBuilder;
23+
import com.ocpsoft.rewrite.config.Invoke;
24+
import com.ocpsoft.rewrite.servlet.config.HttpConfigurationProvider;
25+
import com.ocpsoft.rewrite.servlet.config.Path;
26+
import com.ocpsoft.rewrite.servlet.config.Redirect;
27+
import com.ocpsoft.rewrite.servlet.config.SendStatus;
28+
29+
/**
30+
* @author Christian Kaltepoth
31+
*/
32+
public class SpringFeaturesConfigProvider extends HttpConfigurationProvider
33+
{
34+
35+
@Override
36+
public Configuration getConfiguration(final ServletContext context)
37+
{
38+
return ConfigurationBuilder
39+
.begin()
40+
.defineRule()
41+
.when(Path.matches("/name-{name}")
42+
.where("name").bindsTo(El.property("springFeaturesBean.name")))
43+
.perform(Invoke.binding(El.retrievalMethod("springFeaturesBean.action()"))
44+
.and(Redirect.permanent(context.getContextPath() + "/hello/{name}")
45+
.where("name").bindsTo(El.property("springFeaturesBean.uppercase"))))
46+
47+
.defineRule()
48+
.when(Path.matches("/hello/{name}"))
49+
.perform(SendStatus.code(200));
50+
}
51+
52+
@Override
53+
public int priority()
54+
{
55+
return 0;
56+
}
57+
58+
}
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 com.ocpsoft.rewrite.spring;
17+
18+
import junit.framework.Assert;
19+
20+
import org.apache.http.client.methods.HttpGet;
21+
import org.jboss.arquillian.container.test.api.Deployment;
22+
import org.jboss.arquillian.junit.Arquillian;
23+
import org.jboss.shrinkwrap.api.ArchivePaths;
24+
import org.jboss.shrinkwrap.api.ShrinkWrap;
25+
import org.jboss.shrinkwrap.api.asset.StringAsset;
26+
import org.jboss.shrinkwrap.api.spec.WebArchive;
27+
import org.junit.Test;
28+
import org.junit.runner.RunWith;
29+
30+
import com.ocpsoft.common.spi.ServiceEnricher;
31+
import com.ocpsoft.rewrite.config.ConfigurationProvider;
32+
import com.ocpsoft.rewrite.spi.ExpressionLanguageProvider;
33+
import com.ocpsoft.rewrite.test.HttpAction;
34+
import com.ocpsoft.rewrite.test.RewriteTestBase;
35+
36+
/**
37+
* @author Christian Kaltepoth
38+
*/
39+
@RunWith(Arquillian.class)
40+
public class SpringFeaturesTest extends RewriteTestBase {
41+
@Deployment(testable = false)
42+
public static WebArchive getDeployment() {
43+
return ShrinkWrap
44+
.create(WebArchive.class, "rewrite-test.war")
45+
.addAsLibraries(getRewriteArchive())
46+
.setWebXML("jetty-web-spring.xml")
47+
.addAsResource("jetty-log4j.xml", ArchivePaths.create("/log4j.xml"))
48+
.addAsWebInfResource("applicationContext.xml")
49+
.addPackages(true, SpringRoot.class.getPackage())
50+
.addAsResource(new StringAsset(SpringFeaturesConfigProvider.class.getName()),
51+
"/META-INF/services/" + ConfigurationProvider.class.getName())
52+
.addAsResource(new StringAsset(SpringServiceEnricher.class.getName()),
53+
"/META-INF/services/" + ServiceEnricher.class.getName())
54+
.addAsResource(new StringAsset(SpringExpressionLanguageProvider.class.getName()),
55+
"/META-INF/services/" + ExpressionLanguageProvider.class.getName());
56+
}
57+
58+
@Test
59+
public void testSpringFeatures() {
60+
HttpAction<HttpGet> action = get("/name-christian");
61+
Assert.assertEquals(200, action.getResponse().getStatusLine().getStatusCode());
62+
Assert.assertEquals("/hello/CHRISTIAN", action.getCurrentContextRelativeURL());
63+
}
64+
65+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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 com.ocpsoft.rewrite.spring;
17+
18+
/**
19+
* @author Christian Kaltepoth
20+
*/
21+
public interface SpringRoot {
22+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xmlns:context="http://www.springframework.org/schema/context"
4+
xsi:schemaLocation="http://www.springframework.org/schema/beans
5+
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
6+
http://www.springframework.org/schema/context
7+
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
8+
9+
<context:annotation-config />
10+
11+
<context:component-scan base-package="com.ocpsoft" />
12+
13+
</beans>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="3.0"
3+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
4+
5+
<context-param>
6+
<param-name>contextConfigLocation</param-name>
7+
<param-value>/WEB-INF/applicationContext*.xml</param-value>
8+
</context-param>
9+
10+
<listener>
11+
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
12+
</listener>
13+
14+
</web-app>

‎test-harness/src/main/java/com/ocpsoft/rewrite/test/RewriteTestBase.java‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,10 @@ public class RewriteTestBase
7272
@Deployment(testable = false)
7373
public static WebArchive getDeployment()
7474
{
75-
JavaArchive rewrite = ShrinkWrap.create(JavaArchive.class, "rewrite-servlet.jar")
76-
.addAsResource(new File("../api/target/classes/com"))
77-
.addAsResource(new File("../api/target/classes/META-INF"))
78-
.addAsResource(new File("../impl-servlet/target/classes/com"))
79-
.addAsResource(new File("../impl-servlet/target/classes/META-INF"));
8075

8176
return ShrinkWrap
8277
.create(WebArchive.class, "rewrite-test.war")
83-
.addAsLibraries(rewrite)
78+
.addAsLibraries(getRewriteArchive())
8479
.addAsLibraries(resolveDependencies("org.jboss.weld.servlet:weld-servlet:1.1.2.Final"))
8580

8681
/*
@@ -98,6 +93,15 @@ public static WebArchive getDeployment()
9893
.addAsResource("jetty-log4j.xml", ArchivePaths.create("/log4j.xml"));
9994
}
10095

96+
protected static JavaArchive getRewriteArchive()
97+
{
98+
return ShrinkWrap.create(JavaArchive.class, "rewrite-servlet.jar")
99+
.addAsResource(new File("../api/target/classes/com"))
100+
.addAsResource(new File("../api/target/classes/META-INF"))
101+
.addAsResource(new File("../impl-servlet/target/classes/com"))
102+
.addAsResource(new File("../impl-servlet/target/classes/META-INF"));
103+
}
104+
101105
protected static Collection<GenericArchive> resolveDependencies(final String coords)
102106
{
103107
return DependencyResolvers.use(MavenDependencyResolver.class)

‎test-harness/src/main/resources/jetty-log4j.xml‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
<logger name="org.apache">
1616
<level value="info" />
1717
</logger>
18-
18+
19+
<logger name="org.springframework">
20+
<level value="warn" />
21+
</logger>
22+
1923
<logger name="com.ocpsoft">
2024
<level value="debug" />
2125
</logger>

0 commit comments

Comments
 (0)