INT-793, INT-1015 Added tests for operation-invoking-channel-adapter parser.

This commit is contained in:
Mark Fisher
2010-03-09 22:56:32 +00:00
parent 0885ee15d8
commit 54e8157e0f
3 changed files with 161 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
<?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/>
<jmx:operation-invoking-channel-adapter id="withDefaultsChannel"
default-object-name="org.springframework.integration.jmx.config:type=TestBean,name=testBeanForDefaults"
default-operation-name="test"/>
<jmx:operation-invoking-channel-adapter id="withoutDefaultsChannel"/>
<bean id="testBeanForDefaults" class="org.springframework.integration.jmx.config.TestBean"/>
<bean id="testBeanForNoDefaults" class="org.springframework.integration.jmx.config.TestBean"/>
</beans>

View File

@@ -0,0 +1,93 @@
/*
* 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 org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessageChannel;
import org.springframework.integration.jmx.JmxHeaders;
import org.springframework.integration.message.MessageBuilder;
import org.springframework.integration.message.StringMessage;
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 OperationInvokingChannelAdapterParserTests {
@Autowired
private MessageChannel withDefaultsChannel;
@Autowired
private MessageChannel withoutDefaultsChannel;
@Autowired
private TestBean testBeanForDefaults;
@Autowired
private TestBean testBeanForNoDefaults;
@After
public void resetLists() {
testBeanForDefaults.messages.clear();
testBeanForNoDefaults.messages.clear();
}
@Test
public void adapterWithDefaults() throws Exception {
assertEquals(0, testBeanForDefaults.messages.size());
assertEquals(0, testBeanForNoDefaults.messages.size());
withDefaultsChannel.send(new StringMessage("test1"));
withDefaultsChannel.send(new StringMessage("test2"));
withDefaultsChannel.send(new StringMessage("test3"));
assertEquals(3, testBeanForDefaults.messages.size());
assertEquals(0, testBeanForNoDefaults.messages.size());
}
@Test
public void adapterWithoutDefaults() throws Exception {
assertEquals(0, testBeanForDefaults.messages.size());
assertEquals(0, testBeanForNoDefaults.messages.size());
withoutDefaultsChannel.send(createMessageWithHeaders("1"));
withoutDefaultsChannel.send(createMessageWithHeaders("2"));
withoutDefaultsChannel.send(createMessageWithHeaders("3"));
assertEquals(0, testBeanForDefaults.messages.size());
assertEquals(3, testBeanForNoDefaults.messages.size());
}
private static Message<String> createMessageWithHeaders(String payload) {
String objectName = "org.springframework.integration.jmx.config:name=testBeanForNoDefaults,type=TestBean";
return MessageBuilder.withPayload(payload)
.setHeader(JmxHeaders.OBJECT_NAME, objectName)
.setHeader(JmxHeaders.OPERATION_NAME, "test")
.build();
}
}

View File

@@ -0,0 +1,39 @@
/*
* 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 java.util.ArrayList;
import java.util.List;
import org.springframework.jmx.export.annotation.ManagedOperation;
import org.springframework.jmx.export.annotation.ManagedResource;
/**
* @author Mark Fisher
* @since 2.0
*/
@ManagedResource
public class TestBean {
final List<String> messages = new ArrayList<String>();
@ManagedOperation
public void test(String text) {
this.messages.add(text);
}
}