INT-881, Added ControlBusBindingMessageDistributionListener, fixed template.mf (after real OSGi testing), added tests
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd">
|
||||
|
||||
<si-service:config>
|
||||
<si-service:import name="channelA" si-type="publish-subscribe-channel"/>
|
||||
<si-service:import name="channelA" si-type="publish-subscribe-channel" control-bus="DEFAULT_CONTROL_GROUP"/>
|
||||
</si-service:config>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?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:si-service="http://www.springframework.org/schema/integration/integration-service-extender"
|
||||
xmlns:si="http://www.springframework.org/schema/integration"
|
||||
xmlns:osgi="http://www.springframework.org/schema/osgi"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/integration/integration-service-extender http://www.springframework.org/schema/integration/integration-service-extender/spring-integration-service-extender-1.0.xsd
|
||||
http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi-1.2.xsd
|
||||
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd">
|
||||
|
||||
<si-service:config>
|
||||
<si-service:export si-type="publish-subscribe-channel"/>
|
||||
</si-service:config>
|
||||
|
||||
<si:publish-subscribe-channel id="channelA"/>
|
||||
|
||||
</beans>
|
||||
@@ -18,10 +18,18 @@ package org.springframework.integration.osgi.config.xml;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.integration.channel.SubscribableChannel;
|
||||
import org.springframework.integration.controlbus.ControlBus;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.message.MessageHandler;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.osgi.AbstractSIConfigBundleTestDeployer;
|
||||
import org.springframework.integration.osgi.stubs.SIBundleContextStub;
|
||||
import org.springframework.osgi.service.ServiceUnavailableException;
|
||||
|
||||
/**
|
||||
* Tests 'config' element.
|
||||
@@ -32,13 +40,67 @@ import org.springframework.integration.osgi.stubs.SIBundleContextStub;
|
||||
public class ConfigParserImporterTests extends AbstractSIConfigBundleTestDeployer {
|
||||
|
||||
@Test
|
||||
public void testBasicSIServiceConfig() throws Exception {
|
||||
public void testBasicSIServiceConfigNoBackingService() throws Exception {
|
||||
BundleContext bundleContext = SIBundleContextStub.getNewInstance();
|
||||
ApplicationContext ac = this.deploySIConfig(bundleContext,
|
||||
"org/springframework/integration/osgi/config/xml/",
|
||||
"ConfigParserImporterTests-default.xml");
|
||||
SubscribableChannel channel = ac.getBean("channelA", SubscribableChannel.class);
|
||||
assertNotNull(channel);
|
||||
}
|
||||
@Test(expected=ServiceUnavailableException.class)
|
||||
public void testBasicSIServiceConfigNoBackingServiceError() throws Exception {
|
||||
BundleContext bundleContext = SIBundleContextStub.getNewInstance();
|
||||
ApplicationContext ac = this.deploySIConfig(bundleContext,
|
||||
"org/springframework/integration/osgi/config/xml/",
|
||||
"ConfigParserImporterTests-default.xml");
|
||||
SubscribableChannel channel = ac.getBean("channelA", SubscribableChannel.class);
|
||||
assertNotNull(channel);
|
||||
// try to use it and see error
|
||||
channel.send(null);
|
||||
}
|
||||
/**
|
||||
* Will register AC with service importer, then it will register another AC with service exporter
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test
|
||||
public void testBasicSIServiceConfigWithBackingService() throws Exception {
|
||||
BundleContext bundleContext = SIBundleContextStub.getNewInstance();
|
||||
ApplicationContext ac = this.deploySIConfig(bundleContext,
|
||||
"org/springframework/integration/osgi/config/xml/",
|
||||
"ConfigParserImporterTests-default.xml");
|
||||
SubscribableChannel channel = ac.getBean("channelA", SubscribableChannel.class);
|
||||
assertNotNull(channel);
|
||||
this.deploySIConfig(bundleContext,
|
||||
"org/springframework/integration/osgi/config/xml/",
|
||||
"ConfigParserImporterTests-exporter.xml");
|
||||
MessageHandler handler = Mockito.mock(MessageHandler.class);
|
||||
Message<String> message = new StringMessage("hello");
|
||||
channel.subscribe(handler);
|
||||
channel.send(message);
|
||||
Mockito.verify(handler, Mockito.times(1)).handleMessage(message);
|
||||
}
|
||||
@Test
|
||||
public void testControlBusAttributeWithBusPresent() throws Exception {
|
||||
BundleContext bundleContext = SIBundleContextStub.getNewInstance();
|
||||
ConfigurableApplicationContext busAC = this.deploySIConfig(bundleContext,
|
||||
"org/springframework/integration/osgi/config/xml/",
|
||||
"BusConfigParserTests-default.xml");
|
||||
ConfigurableApplicationContext exporterAC = this.deploySIConfig(bundleContext,
|
||||
"org/springframework/integration/osgi/config/xml/",
|
||||
"ConfigParserImporterTests-exporter.xml");
|
||||
ConfigurableApplicationContext ac = this.deploySIConfig(bundleContext,
|
||||
"org/springframework/integration/osgi/config/xml/",
|
||||
"ConfigParserImporterTests-default.xml");
|
||||
assertNotNull(ac.getBean("channelA"));
|
||||
|
||||
|
||||
ControlBus bus = (ControlBus) ac.getBean("DEFAULT_CONTROL_GROUP");
|
||||
assertNotNull(bus);
|
||||
MessageHandler handler = Mockito.mock(MessageHandler.class);
|
||||
bus.subscribe(handler);
|
||||
exporterAC.close();
|
||||
// should be 3 notification messages sent to the bus
|
||||
Mockito.verify(handler, Mockito.times(1)).handleMessage((Message<?>) Mockito.any());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user