2015-03-24 23:52:56 +01:00
|
|
|
/**
|
|
|
|
*
|
2020-04-04 13:03:31 +02:00
|
|
|
* Copyright 2015-2020 Florian Schmaus
|
2015-03-24 23:52:56 +01:00
|
|
|
*
|
|
|
|
* 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.jivesoftware.smack;
|
|
|
|
|
2017-06-14 17:12:43 +02:00
|
|
|
import static org.jivesoftware.smackx.jiveproperties.JivePropertiesManager.addProperty;
|
|
|
|
import static org.jivesoftware.smackx.jiveproperties.JivePropertiesManager.getProperty;
|
2020-04-12 21:54:18 +02:00
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
2015-03-24 23:52:56 +01:00
|
|
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
import org.jivesoftware.smack.chat.ChatManagerListener;
|
|
|
|
import org.jivesoftware.smack.filter.ThreadFilter;
|
|
|
|
import org.jivesoftware.smack.packet.Message;
|
2019-10-24 15:45:08 +02:00
|
|
|
import org.jivesoftware.smack.packet.MessageBuilder;
|
|
|
|
import org.jivesoftware.smack.packet.StanzaBuilder;
|
|
|
|
|
2015-03-24 23:52:56 +01:00
|
|
|
import org.jivesoftware.smackx.jiveproperties.JivePropertiesManager;
|
2017-06-14 17:12:43 +02:00
|
|
|
|
|
|
|
import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest;
|
|
|
|
import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
|
2020-04-12 21:54:18 +02:00
|
|
|
import org.igniterealtime.smack.inttest.annotations.AfterClass;
|
|
|
|
import org.igniterealtime.smack.inttest.annotations.BeforeClass;
|
|
|
|
import org.igniterealtime.smack.inttest.annotations.SmackIntegrationTest;
|
2015-03-24 23:52:56 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests for Chat Manager and for Chat Manager Listener.
|
2018-05-09 23:06:12 +02:00
|
|
|
*
|
2015-03-24 23:52:56 +01:00
|
|
|
* @author Stawicki Adam
|
|
|
|
*/
|
|
|
|
public class ChatTest extends AbstractSmackIntegrationTest {
|
|
|
|
|
2017-01-11 19:35:55 +01:00
|
|
|
@SuppressWarnings("deprecation")
|
|
|
|
private final org.jivesoftware.smack.chat.ChatManager chatManagerOne;
|
2015-03-24 23:52:56 +01:00
|
|
|
private boolean invoked;
|
|
|
|
|
2017-01-11 19:35:55 +01:00
|
|
|
@SuppressWarnings("deprecation")
|
2020-04-04 13:03:31 +02:00
|
|
|
public ChatTest(SmackIntegrationTestEnvironment environment) {
|
2015-03-24 23:52:56 +01:00
|
|
|
super(environment);
|
2017-01-11 19:35:55 +01:00
|
|
|
chatManagerOne = org.jivesoftware.smack.chat.ChatManager.getInstanceFor(conOne);
|
2015-03-24 23:52:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@BeforeClass
|
2016-12-19 14:35:09 +01:00
|
|
|
public void setUp() {
|
2015-03-24 23:52:56 +01:00
|
|
|
JivePropertiesManager.setJavaObjectEnabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@AfterClass
|
2016-12-19 14:35:09 +01:00
|
|
|
public void tearDown() {
|
2015-03-24 23:52:56 +01:00
|
|
|
JivePropertiesManager.setJavaObjectEnabled(false);
|
|
|
|
}
|
|
|
|
|
2017-01-11 19:35:55 +01:00
|
|
|
@SuppressWarnings("deprecation")
|
2015-03-24 23:52:56 +01:00
|
|
|
@SmackIntegrationTest
|
2017-12-13 23:10:11 +01:00
|
|
|
public void testProperties() throws Exception {
|
2017-01-11 19:35:55 +01:00
|
|
|
org.jivesoftware.smack.chat.Chat newChat = chatManagerOne.createChat(conTwo.getUser());
|
2017-01-03 11:12:34 +01:00
|
|
|
StanzaCollector collector = conTwo.createStanzaCollector(new ThreadFilter(newChat.getThreadID()));
|
2015-03-24 23:52:56 +01:00
|
|
|
|
2019-10-24 15:45:08 +02:00
|
|
|
MessageBuilder messageBuilder = StanzaBuilder.buildMessage();
|
2015-03-24 23:52:56 +01:00
|
|
|
|
2019-10-24 15:45:08 +02:00
|
|
|
messageBuilder.setSubject("Subject of the chat");
|
|
|
|
messageBuilder.setBody("Body of the chat");
|
|
|
|
addProperty(messageBuilder, "favoriteColor", "red");
|
|
|
|
addProperty(messageBuilder, "age", 30);
|
|
|
|
addProperty(messageBuilder, "distance", 30f);
|
|
|
|
addProperty(messageBuilder, "weight", 30d);
|
|
|
|
addProperty(messageBuilder, "male", true);
|
|
|
|
addProperty(messageBuilder, "birthdate", new Date());
|
2015-03-24 23:52:56 +01:00
|
|
|
|
2019-10-24 15:45:08 +02:00
|
|
|
Message msg = messageBuilder.build();
|
2015-03-24 23:52:56 +01:00
|
|
|
newChat.sendMessage(msg);
|
|
|
|
|
2017-12-13 23:10:11 +01:00
|
|
|
Message msg2 = collector.nextResult(2000);
|
2020-04-12 21:54:18 +02:00
|
|
|
assertNotNull(msg2, "No message was received");
|
|
|
|
assertEquals(msg.getSubject(), msg2.getSubject(), "Subjects are different");
|
|
|
|
assertEquals(msg.getBody(), msg2.getBody(), "Bodies are different");
|
2015-03-24 23:52:56 +01:00
|
|
|
assertEquals(
|
|
|
|
getProperty(msg, "favoriteColor"),
|
2020-04-12 21:54:18 +02:00
|
|
|
getProperty(msg2, "favoriteColor"),
|
|
|
|
"favoriteColors are different");
|
2015-03-24 23:52:56 +01:00
|
|
|
assertEquals(
|
2018-05-09 23:06:12 +02:00
|
|
|
getProperty(msg, "age"),
|
2020-04-12 21:54:18 +02:00
|
|
|
getProperty(msg2, "age"),
|
|
|
|
"ages are different");
|
2015-03-24 23:52:56 +01:00
|
|
|
assertEquals(
|
2018-05-09 23:06:12 +02:00
|
|
|
getProperty(msg, "distance"),
|
2020-04-12 21:54:18 +02:00
|
|
|
getProperty(msg2, "distance"),
|
|
|
|
"distances are different");
|
2015-03-24 23:52:56 +01:00
|
|
|
assertEquals(
|
2018-05-09 23:06:12 +02:00
|
|
|
getProperty(msg, "weight"),
|
2020-04-12 21:54:18 +02:00
|
|
|
getProperty(msg2, "weight"),
|
|
|
|
"weights are different");
|
2015-03-24 23:52:56 +01:00
|
|
|
assertEquals(
|
2018-05-09 23:06:12 +02:00
|
|
|
getProperty(msg, "male"),
|
2020-04-12 21:54:18 +02:00
|
|
|
getProperty(msg2, "male"),
|
|
|
|
"males are different");
|
2015-03-24 23:52:56 +01:00
|
|
|
assertEquals(
|
2018-05-09 23:06:12 +02:00
|
|
|
getProperty(msg, "birthdate"),
|
2020-04-12 21:54:18 +02:00
|
|
|
getProperty(msg2, "birthdate"),
|
|
|
|
"birthdates are different");
|
2015-03-24 23:52:56 +01:00
|
|
|
}
|
|
|
|
|
2017-01-11 19:35:55 +01:00
|
|
|
@SuppressWarnings("deprecation")
|
2015-03-24 23:52:56 +01:00
|
|
|
@SmackIntegrationTest
|
|
|
|
public void chatManagerTest() {
|
|
|
|
ChatManagerListener listener = new ChatManagerListener() {
|
|
|
|
|
|
|
|
@Override
|
2017-01-11 19:35:55 +01:00
|
|
|
public void chatCreated(org.jivesoftware.smack.chat.Chat chat, boolean createdLocally) {
|
2015-03-24 23:52:56 +01:00
|
|
|
invoked = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
try {
|
|
|
|
chatManagerOne.addChatListener(listener);
|
|
|
|
chatManagerOne.createChat(conTwo.getUser());
|
|
|
|
|
2020-04-12 21:54:18 +02:00
|
|
|
assertTrue(invoked, "TestChatManagerListener wasn't invoked");
|
2015-03-24 23:52:56 +01:00
|
|
|
}
|
|
|
|
finally {
|
|
|
|
chatManagerOne.removeChatListener(listener);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|