1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-09-09 10:19:41 +02:00

Apply refinements and fixes to the MAM code

SMACK-625.
This commit is contained in:
Florian Schmaus 2016-07-23 15:45:45 +02:00
parent 189cac072b
commit aeb385a022
21 changed files with 194 additions and 236 deletions

View file

@ -16,8 +16,9 @@
*/
package org.jivesoftware.smackx.mam;
import static org.junit.Assert.assertEquals;
import java.util.List;
import java.util.UUID;
import org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest;
import org.igniterealtime.smack.inttest.SmackIntegrationTest;
@ -30,8 +31,7 @@ import org.jivesoftware.smack.XMPPException.XMPPErrorException;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smackx.forward.packet.Forwarded;
import org.jivesoftware.smackx.mam.MamManager.MamQueryResult;
import org.junit.Assert;
import org.jxmpp.jid.Jid;
import org.jxmpp.jid.EntityBareJid;
public class MamIntegrationTest extends AbstractSmackIntegrationTest {
@ -49,8 +49,19 @@ public class MamIntegrationTest extends AbstractSmackIntegrationTest {
}
private Message getConTwoLastMessageSentFrom(Jid userOne) throws NoResponseException, XMPPErrorException,
NotConnectedException, InterruptedException, NotLoggedInException {
@SmackIntegrationTest
public void mamTest() throws NotConnectedException, InterruptedException, NoResponseException, XMPPErrorException,
NotLoggedInException {
EntityBareJid userOne = conOne.getUser().asEntityBareJid();
EntityBareJid userTwo = conTwo.getUser().asEntityBareJid();
Message message = new Message(userTwo);
String messageId = message.setStanzaId();
String messageBody = "test message";
message.setBody(messageBody);
conOne.sendStanza(message);
int pageSize = 20;
MamQueryResult mamQueryResult = mamManagerConTwo.queryArchive(pageSize, null, null, userOne, null);
@ -59,35 +70,12 @@ public class MamIntegrationTest extends AbstractSmackIntegrationTest {
}
List<Forwarded> forwardedMessages = mamQueryResult.forwardedMessages;
Message messageFromMAM = (Message) forwardedMessages.get(forwardedMessages.size() - 1).getForwardedStanza();
return messageFromMAM;
}
Message mamMessage = (Message) forwardedMessages.get(forwardedMessages.size() - 1).getForwardedStanza();
private Message prepareMessage(Jid to, String messageId, String body) {
Message message = new Message();
message.setTo(to);
message.setStanzaId(messageId);
message.setBody(body);
return message;
}
@SmackIntegrationTest
public void mamTest() throws Exception {
Jid userOne = conOne.getUser().asEntityBareJid();
Jid userTwo = conTwo.getUser().asEntityBareJid();
String messageId = UUID.randomUUID().toString();
String messageBody = "test message";
Message message = prepareMessage(userTwo, messageId, messageBody);
conOne.sendStanza(message);
Message mamMessage = getConTwoLastMessageSentFrom(userOne);
Assert.assertEquals(messageId, mamMessage.getStanzaId());
Assert.assertEquals(messageBody, mamMessage.getBody());
Assert.assertEquals(conOne.getUser(), mamMessage.getFrom());
Assert.assertEquals(userTwo, mamMessage.getTo());
assertEquals(messageId, mamMessage.getStanzaId());
assertEquals(messageBody, mamMessage.getBody());
assertEquals(conOne.getUser(), mamMessage.getFrom());
assertEquals(userTwo, mamMessage.getTo());
}
}

View file

@ -1,21 +0,0 @@
/**
*
* Copyright 2016 Fernando Ramirez
*
* 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.
*/
/**
* Message Archive Management (XEP-0313) integration tests.
*/
package org.jivesoftware.smackx.mam;

View file

@ -0,0 +1 @@
../../../../../../../../smack-experimental/src/main/java/org/jivesoftware/smackx/mam/package-info.java