INT-1554 removed Presence headers, Inbound/Outboound Message Mapper, fixed schema and tests
This commit is contained in:
@@ -17,11 +17,7 @@
|
||||
<channel id="output"/>
|
||||
|
||||
<xmpp:header-enricher input-channel="input" output-channel="output">
|
||||
<xmpp:presence-from value="test@example.org"/>
|
||||
<xmpp:presence-mode value="available"/>
|
||||
<xmpp:message-to value="test1@example.org"/>
|
||||
<xmpp:presence-type value="unavailable"/>
|
||||
<xmpp:message-to value="test1@example.org"/>
|
||||
</xmpp:header-enricher>
|
||||
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -16,19 +16,25 @@
|
||||
|
||||
package org.springframework.integration.xmpp.config;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mockito;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.MessageDeliveryException;
|
||||
import org.springframework.integration.MessageHandlingException;
|
||||
import org.springframework.integration.MessageRejectedException;
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.core.MessageHandler;
|
||||
import org.springframework.integration.core.MessagingTemplate;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.xmpp.XmppHeaders;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -41,27 +47,30 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class XmppHeaderEnricherParserTests {
|
||||
|
||||
|
||||
private static final Log logger = LogFactory.getLog(XmppHeaderEnricherParserTests.class);
|
||||
|
||||
@Value("#{input}")
|
||||
private DirectChannel input;
|
||||
|
||||
@Value("#{output}")
|
||||
private DirectChannel output;
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void to() {
|
||||
MessagingTemplate messagingTemplate = new MessagingTemplate();
|
||||
output.subscribe(new MessageHandler() {
|
||||
public void handleMessage(Message<?> message)
|
||||
throws MessageRejectedException, MessageHandlingException,
|
||||
MessageDeliveryException {
|
||||
for (String h : message.getHeaders().keySet())
|
||||
logger.debug(String.format("%s=%s (class: %s)", h, message.getHeaders().get(h), message.getHeaders().get(h).getClass().toString()));
|
||||
MessageHandler handler = mock(MessageHandler.class);
|
||||
doAnswer(new Answer() {
|
||||
@Override
|
||||
public Object answer(InvocationOnMock invocation) throws Throwable {
|
||||
Message message = (Message) invocation.getArguments()[0];
|
||||
String chatToUser = (String) message.getHeaders().get(XmppHeaders.CHAT_TO_USER);
|
||||
assertNotNull(chatToUser);
|
||||
assertEquals("test1@example.org", chatToUser);
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}).when(handler).handleMessage(Mockito.any(Message.class));
|
||||
output.subscribe(handler);
|
||||
messagingTemplate.send(input, MessageBuilder.withPayload("foo").build());
|
||||
verify(handler, times(1)).handleMessage(Mockito.any(Message.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -26,12 +26,7 @@
|
||||
|
||||
<int-xmpp:roster-event-outbound-channel-adapter id="eventOutboundRosterAdapter"
|
||||
xmpp-connection="testConnection"
|
||||
channel="eventChannel"
|
||||
message-mapper="mockMappper"/>
|
||||
channel="eventChannel"/>
|
||||
|
||||
<bean id="mockMappper" class="org.mockito.Mockito" factory-method="mock">
|
||||
<constructor-arg value="org.springframework.integration.mapping.OutboundMessageMapper"/>
|
||||
</bean>
|
||||
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -15,8 +15,6 @@
|
||||
*/
|
||||
package org.springframework.integration.xmpp.config;
|
||||
|
||||
import static junit.framework.Assert.assertFalse;
|
||||
import static junit.framework.Assert.assertNotNull;
|
||||
import static junit.framework.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -24,10 +22,6 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.endpoint.EventDrivenConsumer;
|
||||
import org.springframework.integration.endpoint.PollingConsumer;
|
||||
import org.springframework.integration.mapping.OutboundMessageMapper;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.integration.xmpp.presence.XmppPresenceMessageMapper;
|
||||
import org.springframework.integration.xmpp.presence.XmppRosterEventMessageSendingHandler;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
@@ -42,29 +36,12 @@ public class XmppRosterEventOutboundChannelAdapterParserTests {
|
||||
Object pollingConsumer = ac.getBean("pollingOutboundRosterAdapter");
|
||||
assertTrue(pollingConsumer instanceof PollingConsumer);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void testRosterEventOutboundChannelAdapterParserDefaultMapper(){
|
||||
ApplicationContext ac =
|
||||
new ClassPathXmlApplicationContext("XmppRosterEventOutboundChannelAdapterParserTests-context.xml", this.getClass());
|
||||
Object pollingConsumer = ac.getBean("pollingOutboundRosterAdapter");
|
||||
XmppRosterEventMessageSendingHandler handler =
|
||||
TestUtils.getPropertyValue(pollingConsumer, "handler", XmppRosterEventMessageSendingHandler.class);
|
||||
OutboundMessageMapper mapper = TestUtils.getPropertyValue(handler, "messageMapper", OutboundMessageMapper.class);
|
||||
assertNotNull(mapper);
|
||||
assertTrue(mapper instanceof XmppPresenceMessageMapper);
|
||||
}
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Test
|
||||
public void testRosterEventOutboundChannelAdapterParserCustomMapperEventDriven(){
|
||||
public void testRosterEventOutboundChannelAdapterParserEventConsumer(){
|
||||
ApplicationContext ac =
|
||||
new ClassPathXmlApplicationContext("XmppRosterEventOutboundChannelAdapterParserTests-context.xml", this.getClass());
|
||||
Object eventConsumer = ac.getBean("eventOutboundRosterAdapter");
|
||||
assertTrue(eventConsumer instanceof EventDrivenConsumer);
|
||||
XmppRosterEventMessageSendingHandler handler =
|
||||
TestUtils.getPropertyValue(eventConsumer, "handler", XmppRosterEventMessageSendingHandler.class);
|
||||
OutboundMessageMapper mapper = TestUtils.getPropertyValue(handler, "messageMapper", OutboundMessageMapper.class);
|
||||
assertNotNull(mapper);
|
||||
assertFalse(mapper instanceof XmppPresenceMessageMapper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,33 +8,33 @@
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
|
||||
http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool-3.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
|
||||
http://www.springframework.org/schema/integration/xmpp http://www.springframework.org/schema/integration/xmpp/spring-integration-xmpp.xsd
|
||||
http://www.springframework.org/schema/integration/xmpp http://www.springframework.org/schema/integration/xmpp/spring-integration-xmpp-2.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
|
||||
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd
|
||||
http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd">
|
||||
|
||||
|
||||
<beans:bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer" p:ignoreUnresolvablePlaceholders="false">
|
||||
<beans:bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
||||
<beans:property name="location" value="classpath:test.properties"/>
|
||||
</beans:bean>
|
||||
|
||||
<xmpp:xmpp-connection
|
||||
id="testConnection"
|
||||
user="${user.2.login}"
|
||||
password="${user.2.password}"
|
||||
host="${user.2.host}"
|
||||
port="${user.2.port}"
|
||||
resource="${user.2.resource}"
|
||||
service-name="${user.2.service}"
|
||||
/>
|
||||
user="${user.1.login}"
|
||||
password="${user.1.password}"
|
||||
host="${user.1.host}"
|
||||
service-name="${user.1.service}"/>
|
||||
|
||||
<console:stdout-channel-adapter id="stdout" append-newline="true"/>
|
||||
<console:stdin-channel-adapter id="stdin"/>
|
||||
|
||||
<header-enricher input-channel="stdin" output-channel="messagesToSend">
|
||||
<header name="#{T(org.springframework.integration.xmpp.XmppHeaders).CHAT_TO_USER}" value="${user.1.login}"/>
|
||||
</header-enricher>
|
||||
|
||||
<console:stdin-channel-adapter id="stdin">
|
||||
<poller fixed-rate="1000"/>
|
||||
</console:stdin-channel-adapter>
|
||||
|
||||
<xmpp:header-enricher input-channel="stdin" output-channel="messagesToSend">
|
||||
<xmpp:message-to value="${user.2.login}"/>
|
||||
</xmpp:header-enricher>
|
||||
|
||||
<xmpp:message-inbound-channel-adapter channel="stdout" xmpp-connection="testConnection"/>
|
||||
|
||||
@@ -42,9 +42,4 @@
|
||||
|
||||
<xmpp:message-outbound-channel-adapter channel="messagesToSend" xmpp-connection="testConnection"/>
|
||||
|
||||
<poller default="true">
|
||||
<interval-trigger interval="1" time-unit="SECONDS"/>
|
||||
</poller>
|
||||
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ConsoleChatTests {
|
||||
@Test
|
||||
@Ignore
|
||||
public void run() throws Exception {
|
||||
Thread.sleep(10 * 1000);
|
||||
Thread.sleep(10 * 1000 * 1000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -33,13 +33,13 @@ public class XmppRosterEventConsumer {
|
||||
|
||||
@ServiceActivator
|
||||
public void presenceChanged(Message<?> presenceEventMsg) throws Exception {
|
||||
System.out.println(StringUtils.repeat("-", 100));
|
||||
String whosePresence = (String) presenceEventMsg.getHeaders().get(XmppHeaders.PRESENCE_FROM);
|
||||
System.out.println("entries affected: " + whosePresence);
|
||||
MessageHeaders messageHeaders = presenceEventMsg.getHeaders();
|
||||
for (String h : messageHeaders.keySet()) {
|
||||
System.out.println(String.format("%s = %s", h, messageHeaders.get(h)));
|
||||
}
|
||||
// System.out.println(StringUtils.repeat("-", 100));
|
||||
// String whosePresence = (String) presenceEventMsg.getHeaders().get(XmppHeaders.PRESENCE_FROM);
|
||||
// System.out.println("entries affected: " + whosePresence);
|
||||
// MessageHeaders messageHeaders = presenceEventMsg.getHeaders();
|
||||
// for (String h : messageHeaders.keySet()) {
|
||||
// System.out.println(String.format("%s = %s", h, messageHeaders.get(h)));
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,17 +35,18 @@ import org.springframework.integration.xmpp.XmppHeaders;
|
||||
public class XmppRosterEventProducer implements MessageSource<String> {
|
||||
|
||||
public Message<String> receive() {
|
||||
try {
|
||||
Thread.sleep(1000 * 10);
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
// eat it
|
||||
}
|
||||
return (Math.random() > .5) ? MessageBuilder.withPayload("available").setHeader(
|
||||
XmppHeaders.PRESENCE_MODE, Presence.Mode.chat)
|
||||
.setHeader(XmppHeaders.PRESENCE_STATUS, "She Loves me").build()
|
||||
: MessageBuilder.withPayload(StringUtils.EMPTY).setHeader(XmppHeaders.PRESENCE_MODE, Presence.Mode.dnd)
|
||||
.setHeader(XmppHeaders.PRESENCE_STATUS, "She Loves me not").build();
|
||||
// try {
|
||||
// Thread.sleep(1000 * 10);
|
||||
// }
|
||||
// catch (InterruptedException e) {
|
||||
// // eat it
|
||||
// }
|
||||
// return (Math.random() > .5) ? MessageBuilder.withPayload("available").setHeader(
|
||||
// XmppHeaders.PRESENCE_MODE, Presence.Mode.chat)
|
||||
// .setHeader(XmppHeaders.PRESENCE_STATUS, "She Loves me").build()
|
||||
// : MessageBuilder.withPayload(StringUtils.EMPTY).setHeader(XmppHeaders.PRESENCE_MODE, Presence.Mode.dnd)
|
||||
// .setHeader(XmppHeaders.PRESENCE_STATUS, "She Loves me not").build();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import org.junit.Test;
|
||||
import org.springframework.integration.Message;
|
||||
import org.springframework.integration.mapping.MessageMappingException;
|
||||
import org.springframework.integration.support.MessageBuilder;
|
||||
import org.springframework.integration.xmpp.XmppHeaders;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
@@ -34,61 +33,61 @@ public class XmppPresenceMessageMapperTests {
|
||||
|
||||
@Test
|
||||
public void testFromMessageWithPayloadPresence() throws Exception{
|
||||
Presence presence = new Presence(Type.available, "Hello", 1, Mode.chat);
|
||||
Message<?> message = MessageBuilder.withPayload(presence).build();
|
||||
XmppPresenceMessageMapper mapper = new XmppPresenceMessageMapper();
|
||||
Presence mappedPresence = mapper.fromMessage(message);
|
||||
assertEquals(Mode.chat, mappedPresence.getMode());
|
||||
assertEquals(Type.available, mappedPresence.getType());
|
||||
assertEquals("Hello", mappedPresence.getStatus());
|
||||
assertEquals(1, mappedPresence.getPriority());
|
||||
// Presence presence = new Presence(Type.available, "Hello", 1, Mode.chat);
|
||||
// Message<?> message = MessageBuilder.withPayload(presence).build();
|
||||
// XmppPresenceMessageMapper mapper = new XmppPresenceMessageMapper();
|
||||
// Presence mappedPresence = mapper.fromMessage(message);
|
||||
// assertEquals(Mode.chat, mappedPresence.getMode());
|
||||
// assertEquals(Type.available, mappedPresence.getType());
|
||||
// assertEquals("Hello", mappedPresence.getStatus());
|
||||
// assertEquals(1, mappedPresence.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFromMessageWithPayloadPresenceType() throws Exception{
|
||||
Message<?> message = MessageBuilder.withPayload(Type.available)
|
||||
.setHeader(XmppHeaders.PRESENCE_FROM, "oleg")
|
||||
.setHeader(XmppHeaders.PRESENCE_MODE, Mode.chat)
|
||||
.setHeader(XmppHeaders.PRESENCE_STATUS, "hello")
|
||||
.setHeader(XmppHeaders.PRESENCE_PRIORITY, 1)
|
||||
.build();
|
||||
XmppPresenceMessageMapper mapper = new XmppPresenceMessageMapper();
|
||||
Presence mappedPresence = mapper.fromMessage(message);
|
||||
assertEquals(Mode.chat, mappedPresence.getMode());
|
||||
assertEquals(Type.available, mappedPresence.getType());
|
||||
assertEquals("hello", mappedPresence.getStatus());
|
||||
assertEquals(1, mappedPresence.getPriority());
|
||||
}
|
||||
@Test
|
||||
public void testFromMessageWithPayloadPresenceTypeAndStringModeType() throws Exception{
|
||||
Message<?> message = MessageBuilder.withPayload(Type.available)
|
||||
.setHeader(XmppHeaders.PRESENCE_FROM, "oleg")
|
||||
.setHeader(XmppHeaders.PRESENCE_MODE, "chat")
|
||||
.setHeader(XmppHeaders.PRESENCE_STATUS, "hello")
|
||||
.setHeader(XmppHeaders.PRESENCE_PRIORITY, 1)
|
||||
.build();
|
||||
XmppPresenceMessageMapper mapper = new XmppPresenceMessageMapper();
|
||||
Presence mappedPresence = mapper.fromMessage(message);
|
||||
assertEquals(Mode.chat, mappedPresence.getMode());
|
||||
assertEquals(Type.available, mappedPresence.getType());
|
||||
assertEquals("hello", mappedPresence.getStatus());
|
||||
assertEquals(1, mappedPresence.getPriority());
|
||||
}
|
||||
// @Test
|
||||
// public void testFromMessageWithPayloadPresenceType() throws Exception{
|
||||
// Message<?> message = MessageBuilder.withPayload(Type.available)
|
||||
// .setHeader(XmppHeaders.PRESENCE_FROM, "oleg")
|
||||
// .setHeader(XmppHeaders.PRESENCE_MODE, Mode.chat)
|
||||
// .setHeader(XmppHeaders.PRESENCE_STATUS, "hello")
|
||||
// .setHeader(XmppHeaders.PRESENCE_PRIORITY, 1)
|
||||
// .build();
|
||||
// XmppPresenceMessageMapper mapper = new XmppPresenceMessageMapper();
|
||||
// Presence mappedPresence = mapper.fromMessage(message);
|
||||
// assertEquals(Mode.chat, mappedPresence.getMode());
|
||||
// assertEquals(Type.available, mappedPresence.getType());
|
||||
// assertEquals("hello", mappedPresence.getStatus());
|
||||
// assertEquals(1, mappedPresence.getPriority());
|
||||
// }
|
||||
// @Test
|
||||
// public void testFromMessageWithPayloadPresenceTypeAndStringModeType() throws Exception{
|
||||
// Message<?> message = MessageBuilder.withPayload(Type.available)
|
||||
// .setHeader(XmppHeaders.PRESENCE_FROM, "oleg")
|
||||
// .setHeader(XmppHeaders.PRESENCE_MODE, "chat")
|
||||
// .setHeader(XmppHeaders.PRESENCE_STATUS, "hello")
|
||||
// .setHeader(XmppHeaders.PRESENCE_PRIORITY, 1)
|
||||
// .build();
|
||||
// XmppPresenceMessageMapper mapper = new XmppPresenceMessageMapper();
|
||||
// Presence mappedPresence = mapper.fromMessage(message);
|
||||
// assertEquals(Mode.chat, mappedPresence.getMode());
|
||||
// assertEquals(Type.available, mappedPresence.getType());
|
||||
// assertEquals("hello", mappedPresence.getStatus());
|
||||
// assertEquals(1, mappedPresence.getPriority());
|
||||
// }
|
||||
|
||||
@Test(expected=MessageMappingException.class)
|
||||
public void testFromMessageWithPayloadPresenceTypeUnsupportedMode() throws Exception{
|
||||
|
||||
Message<?> message = MessageBuilder.withPayload(Type.available)
|
||||
.setHeader(XmppHeaders.PRESENCE_MODE, 1)
|
||||
.build();
|
||||
XmppPresenceMessageMapper mapper = new XmppPresenceMessageMapper();
|
||||
mapper.fromMessage(message);
|
||||
}
|
||||
// @Test(expected=MessageMappingException.class)
|
||||
// public void testFromMessageWithPayloadPresenceTypeUnsupportedMode() throws Exception{
|
||||
//
|
||||
// Message<?> message = MessageBuilder.withPayload(Type.available)
|
||||
// .setHeader(XmppHeaders.PRESENCE_MODE, 1)
|
||||
// .build();
|
||||
// XmppPresenceMessageMapper mapper = new XmppPresenceMessageMapper();
|
||||
// mapper.fromMessage(message);
|
||||
// }
|
||||
|
||||
@Test(expected=MessageMappingException.class)
|
||||
public void testFromMessageWithUnsupportedPayload() throws Exception{
|
||||
Message<?> message = MessageBuilder.withPayload("hello").build();
|
||||
XmppPresenceMessageMapper mapper = new XmppPresenceMessageMapper();
|
||||
mapper.fromMessage(message);
|
||||
}
|
||||
// @Test(expected=MessageMappingException.class)
|
||||
// public void testFromMessageWithUnsupportedPayload() throws Exception{
|
||||
// Message<?> message = MessageBuilder.withPayload("hello").build();
|
||||
// XmppPresenceMessageMapper mapper = new XmppPresenceMessageMapper();
|
||||
// mapper.fromMessage(message);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,24 +1,6 @@
|
||||
#
|
||||
# Copyright 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.
|
||||
#
|
||||
# to be able to run these tests, put this file on your desktop and configure as appropriate
|
||||
user.1.login=user@gmail.com
|
||||
user.2.login=user1@gmail.com
|
||||
|
||||
user.1.login=user2@gmail.com
|
||||
user.1.password=password
|
||||
user.1.host=talk.google.com
|
||||
user.1.service=gmail.com
|
||||
#user.1.sasl.mechanism=PLAIN
|
||||
#user.1.sasl.index=0
|
||||
#user.1.resource=resource
|
||||
#user.1.port=5222
|
||||
user.1.service=gmail.com
|
||||
Reference in New Issue
Block a user