Added namespace support for the <filter/> element.

This commit is contained in:
Mark Fisher
2008-09-25 00:20:36 +00:00
parent 784c732389
commit 91c094a174
6 changed files with 160 additions and 0 deletions

View File

@@ -0,0 +1,58 @@
/*
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.filter;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.channel.MessageChannel;
import org.springframework.integration.channel.PollableChannel;
import org.springframework.integration.message.Message;
import org.springframework.integration.message.StringMessage;
/**
* @author Mark Fisher
*/
public class FilterContextTests {
@Test
public void methodInvokingFilterRejects() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"filterContextTests.xml", this.getClass());
MessageChannel input = (MessageChannel) context.getBean("input");
PollableChannel output = (PollableChannel) context.getBean("output");
input.send(new StringMessage("foo"));
Message<?> reply = output.receive(0);
assertNull(reply);
}
@Test
public void methodInvokingFilterAccepts() {
ApplicationContext context = new ClassPathXmlApplicationContext(
"filterContextTests.xml", this.getClass());
MessageChannel input = (MessageChannel) context.getBean("input");
PollableChannel output = (PollableChannel) context.getBean("output");
input.send(new StringMessage("foobar"));
Message<?> reply = output.receive(0);
assertEquals("foobar", reply.getPayload());
}
}

View File

@@ -0,0 +1,28 @@
/*
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.filter;
/**
* @author Mark Fisher
*/
public class TestBean {
public boolean acceptStringWithMoreThanThreeChars(String s) {
return s.length() > 3;
}
}

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
<message-bus/>
<channel id="input"/>
<channel id="output">
<queue capacity="50"/>
</channel>
<filter input-channel="input"
ref="testBean"
method="acceptStringWithMoreThanThreeChars"
output-channel="output"/>
<beans:bean id="testBean" class="org.springframework.integration.filter.TestBean"/>
</beans:beans>