INT-1580 cleaned up Roster endpoint, added tests

This commit is contained in:
Oleg Zhurakousky
2010-11-03 23:20:05 -04:00
parent 50d97f12cc
commit b1e1aa2460
21 changed files with 117 additions and 78 deletions

View File

@@ -1,19 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<beans:beans
xmlns="http://www.springframework.org/schema/integration"
xmlns:beans="http://www.springframework.org/schema/beans"
@@ -30,8 +15,7 @@
<channel id="input"/>
<channel id="output"/>
<xmpp:header-enricher input-channel="input" output-channel="output">
<xmpp:presence-from value="test@example.org"/>
<xmpp:presence-mode value="available"/>

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.integration.xmpp.messages;
package org.springframework.integration.xmpp.ignore;
import org.junit.Ignore;
import org.junit.Test;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.integration.xmpp.messages;
package org.springframework.integration.xmpp.ignore;
import org.junit.Ignore;
import org.junit.Test;

View File

@@ -1,15 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ 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.
-->
<beans:beans xmlns="http://www.springframework.org/schema/integration"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
@@ -26,12 +15,8 @@
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:property name="location">
<beans:bean class="org.springframework.core.io.FileSystemResource">
<beans:constructor-arg value="#{ systemProperties['user.home'] }/Desktop/test.properties"/>
</beans:bean>
</beans:property>
<beans:bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<beans:property name="location" value="classpath:test.properties"/>
</beans:bean>
<beans:bean id="xmppRosterEventConsumer" class="org.springframework.integration.xmpp.presence.XmppRosterEventConsumer"/>
@@ -41,10 +26,6 @@
user="${user.1.login}"
password="${user.1.password}"
host="${user.1.host}"
port="${user.1.port}"
resource="${user.1.resource}"
sasl-mechanism-supported="${user.1.sasl.mechanism}"
sasl-mechanism-supported-index="${user.1.sasl.index}"
service-name="${user.1.service}"
/>

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.integration.xmpp.presence;
package org.springframework.integration.xmpp.ignore;
import org.junit.Ignore;
import org.junit.Test;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.integration.xmpp.messages;
package org.springframework.integration.xmpp.ignore;
import org.junit.Ignore;
import org.junit.Test;

View File

@@ -14,11 +14,12 @@
* limitations under the License.
*/
package org.springframework.integration.xmpp.presence;
package org.springframework.integration.xmpp.ignore;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.integration.xmpp.presence.XmppRosterEventMessageSendingHandler;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.integration.xmpp.presence;
package org.springframework.integration.xmpp.ignore;
import org.junit.Ignore;
import org.junit.Test;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.integration.xmpp.messages;
package org.springframework.integration.xmpp.ignore;
import org.jivesoftware.smack.packet.Message;
import org.springframework.integration.annotation.ServiceActivator;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.integration.xmpp.messages;
package org.springframework.integration.xmpp.ignore;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.integration.xmpp.presence;
package org.springframework.integration.xmpp.ignore;
import org.apache.commons.lang.StringUtils;
import org.springframework.integration.Message;

View File

@@ -14,7 +14,7 @@
* limitations under the License.
*/
package org.springframework.integration.xmpp.presence;
package org.springframework.integration.xmpp.ignore;
import org.apache.commons.lang.StringUtils;
import org.jivesoftware.smack.packet.Presence;
@@ -25,7 +25,7 @@ import org.springframework.integration.xmpp.XmppHeaders;
/**
* This is used in
* {@link org.springframework.integration.xmpp.presence.OutboundXmppRosterEventsEndpointTests}
* {@link org.springframework.integration.xmpp.ignore.OutboundXmppRosterEventsEndpointTests}
* to produce fake status / presence updates.
*
* @author Josh Long

View File

@@ -0,0 +1,77 @@
/*
* 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.presence;
import static junit.framework.Assert.assertEquals;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.util.HashSet;
import java.util.Set;
import org.jivesoftware.smack.Roster;
import org.jivesoftware.smack.RosterListener;
import org.jivesoftware.smack.XMPPConnection;
import org.junit.Test;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
/**
* @author Oleg Zhurakousky
*
*/
public class XmppRosterEventMessageDrivenEndpointTests {
@Test
public void testEndpointLifecycle(){
final Set<RosterListener> rosterSet = new HashSet<RosterListener>();
XMPPConnection connection = mock(XMPPConnection.class);
Roster roster = mock(Roster.class);
when(connection.getRoster()).thenReturn(roster);
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
rosterSet.add((RosterListener) invocation.getArguments()[0]);
return null;
}
}).when(roster).addRosterListener(Mockito.any(RosterListener.class));
doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
rosterSet.remove((RosterListener) invocation.getArguments()[0]);
return null;
}
}).when(roster).removeRosterListener(Mockito.any(RosterListener.class));
XmppRosterEventMessageDrivenEndpoint rosterEndpoint = new XmppRosterEventMessageDrivenEndpoint();
rosterEndpoint.setXmppConnection(connection);
rosterEndpoint.afterPropertiesSet();
assertEquals(0, rosterSet.size());
rosterEndpoint.start();
assertEquals(1, rosterSet.size());
rosterEndpoint.stop();
assertEquals(0, rosterSet.size());
}
@Test(expected=IllegalArgumentException.class)
public void testNonInitializedFailure(){
XmppRosterEventMessageDrivenEndpoint rosterEndpoint = new XmppRosterEventMessageDrivenEndpoint();
rosterEndpoint.start();
}
}

View File

@@ -14,11 +14,11 @@
# limitations under the License.
#
# to be able to run these tests, put this file on your desktop and configure as appropriate
user.2.login=springintegration.eip@gmail.com
user.2.password=spr1ng1p
user.2.host=talk.google.com
user.2.service=gmail.com
#user.2.sasl.mechanism=PLAIN
#user.2.sasl.index=0
#user.2.resource=resource
#user.2.port=5222
user.1.login=user@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