INT-1012 Added tests for 'attribute-polling-channel-adapter'.

This commit is contained in:
Mark Fisher
2010-03-09 23:59:17 +00:00
parent 78189b7480
commit bcb0ef0d92
3 changed files with 100 additions and 0 deletions

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:si="http://www.springframework.org/schema/integration"
xmlns:jmx="http://www.springframework.org/schema/integration/jmx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/integration
http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/jmx
http://www.springframework.org/schema/integration/jmx/spring-integration-jmx.xsd">
<context:mbean-export/>
<context:mbean-server/>
<si:channel id="channel">
<si:queue/>
</si:channel>
<jmx:attribute-polling-channel-adapter id="adapter"
channel="channel"
object-name="org.springframework.integration.jmx.config:type=TestBean,name=testBean1"
attribute-name="FirstMessage"
auto-startup="false">
<si:poller max-messages-per-poll="1">
<si:interval-trigger interval="2000"/>
</si:poller>
</jmx:attribute-polling-channel-adapter>
<bean id="testBean1" class="org.springframework.integration.jmx.config.TestBean"/>
</beans>

View File

@@ -0,0 +1,59 @@
/*
* Copyright 2002-2010 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.jmx.config;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.channel.PollableChannel;
import org.springframework.integration.core.Message;
import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* @author Mark Fisher
* @since 2.0
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class AttributePollingChannelAdapterParserTests {
@Autowired
private PollableChannel channel;
@Autowired
private SourcePollingChannelAdapter adapter;
@Autowired
private TestBean testBean;
@Test
public void pollForAttribute() throws Exception {
testBean.test("foo");
adapter.start();
Message<?> result = channel.receive(1000);
assertNotNull(result);
assertEquals("foo", result.getPayload());
}
}

View File

@@ -19,6 +19,7 @@ package org.springframework.integration.jmx.config;
import java.util.ArrayList;
import java.util.List;
import org.springframework.jmx.export.annotation.ManagedAttribute;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedResource;
@@ -31,6 +32,11 @@ public class TestBean {
final List<String> messages = new ArrayList<String>();
@ManagedAttribute
public String getFirstMessage() {
return (messages.size() > 0) ? messages.get(0) : null;
}
@ManagedOperation
public void test(String text) {
this.messages.add(text);