INT-1554 more polishing and tests

This commit is contained in:
Oleg Zhurakousky
2010-11-05 12:07:51 -04:00
parent 5946cb048b
commit cba2658063
11 changed files with 95 additions and 38 deletions

View File

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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 http://www.springframework.org/schema/integration/spring-integration-2.0.xsd
http://www.springframework.org/schema/integration/xmpp http://www.springframework.org/schema/integration/xmpp/spring-integration-xmpp-2.0.xsd"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-xmpp="http://www.springframework.org/schema/integration/xmpp">
<bean id="testConnection" class="org.mockito.Mockito" factory-method="mock">
<constructor-arg value="org.jivesoftware.smack.XMPPConnection"/>
</bean>
<int-xmpp:roster-event-inbound-channel-adapter channel="outChannel"
xmpp-connection="testConnection" auto-startup="false"/>
<int:channel id="outChannel"/>
</beans>

View File

@@ -0,0 +1,32 @@
/*
* 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.xmpp.config;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author Oleg Zhurakousky
*
*/
public class XmppRosterEventMessageDrivenEndpointParserTests {
@Test
public void testXmppRosterEventMessageDrivenEndpointParser(){
new ClassPathXmlApplicationContext("XmppRosterEventMessageDrivenEndpointParserTests-context.xml", this.getClass());
// no assertion needed. THe fact that no exception was thrown satisfies this test
}
}

View File

@@ -18,23 +18,23 @@
http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool-3.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd">
<context:component-scan base-package="org.springframework.integration.xmpp"/>
<context:property-placeholder location="classpath:test.properties"/>
<channel id="xmppInbound"/>
<xmpp:xmpp-connection
id="testConnection"
user="${user.2.login}"
password="${user.2.password}"
host="${user.2.host}"
service-name="${user.2.service}"
/>
user="${user.1.login}"
password="${user.1.password}"
host="${user.1.host}"
service-name="${user.1.service}"/>
<xmpp:message-inbound-channel-adapter channel="xmppInbound" xmpp-connection="testConnection"
extract-payload="false"/>
<service-activator input-channel="xmppInbound" ref="xmppMessageConsumer"/>
<beans:bean id="xmppMessageConsumer" class="org.springframework.integration.xmpp.ignore.XmppMessageConsumer"/>
</beans:beans>

View File

@@ -19,7 +19,7 @@
<beans:property name="location" value="classpath:test.properties"/>
</beans:bean>
<beans:bean id="xmppRosterEventConsumer" class="org.springframework.integration.xmpp.presence.XmppRosterEventConsumer"/>
<beans:bean id="xmppRosterEventConsumer" class="org.springframework.integration.xmpp.ignore.XmppRosterEventConsumer"/>
<xmpp:xmpp-connection
id="testConnection"

View File

@@ -12,27 +12,20 @@
http://www.springframework.org/schema/tool http://www.springframework.org/schema/tool/spring-tool-3.0.xsd
http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang-3.0.xsd">
<context:component-scan base-package="org.springframework.integration.xmpp"/>
<context:property-placeholder location="classpath:test.properties" ignore-unresolvable="true"/>
<context:property-placeholder location="classpath:test.properties"/>
<beans:bean id="xmppProducer"
class="org.springframework.integration.xmpp.messages.XmppMessageProducer"
p:recipient="${recipient.address}"/>
class="org.springframework.integration.xmpp.ignore.XmppMessageProducer"
p:recipient="${user.2.login}"/>
<poller default="true">
<interval-trigger fixed-rate="true" interval="10" time-unit="SECONDS"/>
</poller>
<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}"/>
<inbound-channel-adapter ref="xmppProducer" channel="outboundChannel"/>

View File

@@ -35,7 +35,7 @@ public class OutboundXmppEndpointTests {
@Test
@Ignore
public void run() throws Exception {
Thread.sleep(10 * 1000);
Thread.sleep(10 * 1000*100);
}
}

View File

@@ -20,7 +20,9 @@ import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.jivesoftware.smack.Roster;
@@ -81,7 +83,7 @@ public class XmppRosterEventMessageDrivenEndpointTests {
}
@Test
public void testPresenceChangeEvent(){
public void testRosterPresenceChangeEvent(){
XMPPConnection connection = mock(XMPPConnection.class);
Roster roster = mock(Roster.class);
when(connection.getRoster()).thenReturn(roster);
@@ -96,4 +98,21 @@ public class XmppRosterEventMessageDrivenEndpointTests {
Message<?> message = channel.receive(10);
assertEquals(presence, message.getPayload());
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testRosterEntriesEvents(){
XMPPConnection connection = mock(XMPPConnection.class);
Roster roster = mock(Roster.class);
when(connection.getRoster()).thenReturn(roster);
XmppRosterEventMessageDrivenEndpoint rosterEndpoint = new XmppRosterEventMessageDrivenEndpoint(connection);
QueueChannel channel = new QueueChannel();
rosterEndpoint.setRequestChannel(channel);
rosterEndpoint.afterPropertiesSet();
rosterEndpoint.start();
RosterListener rosterListener = (RosterListener) TestUtils.getPropertyValue(rosterEndpoint, "rosterListener");
List entries = Arrays.asList(new String[]{"many", "moe", "jack"});
rosterListener.entriesUpdated(entries);
Message<?> message = channel.receive(10);
assertEquals(entries, message.getPayload());
}
}

View File

@@ -1,6 +1,6 @@
user.2.login=user1@gmail.com
user.2.login=user2@gmail.com
user.1.login=user2@gmail.com
user.1.password=password
user.1.login=suser1@gmail.com
user.1.password=foo
user.1.host=talk.google.com
user.1.service=gmail.com