2018-04-04 15:41:59 +02:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
* Copyright 2018 Paul Schaub
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
2018-04-07 23:42:46 +02:00
|
|
|
package org.jivesoftware.smack.chat2;
|
2018-04-04 15:41:59 +02:00
|
|
|
|
|
|
|
import org.jivesoftware.smack.packet.Message;
|
2019-10-25 13:57:18 +02:00
|
|
|
import org.jivesoftware.smack.packet.MessageBuilder;
|
2018-04-04 15:41:59 +02:00
|
|
|
import org.jivesoftware.smack.util.StringUtils;
|
|
|
|
|
|
|
|
import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
|
2020-04-12 21:54:18 +02:00
|
|
|
import org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest;
|
2018-04-04 15:41:59 +02:00
|
|
|
import org.igniterealtime.smack.inttest.util.SimpleResultSyncPoint;
|
|
|
|
import org.jxmpp.jid.EntityBareJid;
|
|
|
|
|
2018-04-07 23:42:46 +02:00
|
|
|
public class OutgoingMessageListenerIntegrationTest extends AbstractChatIntegrationTest {
|
2018-04-04 15:41:59 +02:00
|
|
|
|
2020-04-04 13:03:31 +02:00
|
|
|
public OutgoingMessageListenerIntegrationTest(SmackIntegrationTestEnvironment environment) {
|
2018-04-04 15:41:59 +02:00
|
|
|
super(environment);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SmackIntegrationTest
|
|
|
|
public void outgoingMessageListenerTest() throws Exception {
|
|
|
|
final String body = StringUtils.randomString(16);
|
|
|
|
final SimpleResultSyncPoint syncPoint = new SimpleResultSyncPoint();
|
|
|
|
final OutgoingChatMessageListener listener = new OutgoingChatMessageListener() {
|
|
|
|
@Override
|
2019-10-25 13:57:18 +02:00
|
|
|
public void newOutgoingMessage(EntityBareJid to, MessageBuilder messageBuilder, Chat chat) {
|
|
|
|
Message message = messageBuilder.build();
|
2018-04-04 15:41:59 +02:00
|
|
|
if (message.getBody().equals(body)) {
|
|
|
|
syncPoint.signal();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
EntityBareJid peer = conTwo.getUser().asEntityBareJid();
|
|
|
|
|
|
|
|
try {
|
|
|
|
chatManagerOne.addOutgoingListener(listener);
|
|
|
|
Chat chat = chatManagerOne.chatWith(peer);
|
|
|
|
chat.send(body);
|
2018-04-07 23:42:46 +02:00
|
|
|
syncPoint.waitForResult(timeout);
|
2018-04-04 15:41:59 +02:00
|
|
|
}
|
|
|
|
finally {
|
|
|
|
chatManagerOne.removeOutgoingListener(listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|