use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.
the class MultiUserChatIntegrationTest method mucTest.
@SmackIntegrationTest
public void mucTest() throws TimeoutException, Exception {
EntityBareJid mucAddress = JidCreate.entityBareFrom(Localpart.from("smack-inttest-" + randomString), mucService.getDomain());
MultiUserChat mucAsSeenByOne = mucManagerOne.getMultiUserChat(mucAddress);
MultiUserChat mucAsSeenByTwo = mucManagerTwo.getMultiUserChat(mucAddress);
final String mucMessage = "Smack Integration Test MUC Test Message " + randomString;
final ResultSyncPoint<String, Exception> resultSyncPoint = new ResultSyncPoint<>();
mucAsSeenByTwo.addMessageListener(new MessageListener() {
@Override
public void processMessage(Message message) {
String body = message.getBody();
if (mucMessage.equals(body)) {
resultSyncPoint.signal(body);
}
}
});
MucCreateConfigFormHandle handle = mucAsSeenByOne.createOrJoin(Resourcepart.from("one-" + randomString));
if (handle != null) {
handle.makeInstant();
}
mucAsSeenByTwo.join(Resourcepart.from("two-" + randomString));
mucAsSeenByOne.sendMessage(mucMessage);
resultSyncPoint.waitForResult(timeout);
mucAsSeenByOne.leave();
mucAsSeenByTwo.leave();
}
use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.
the class ParserUtils method getEntityJidAttribute.
public static EntityJid getEntityJidAttribute(XmlPullParser parser, String name) throws XmppStringprepException {
final String jidString = parser.getAttributeValue("", name);
if (jidString == null) {
return null;
}
Jid jid = JidCreate.from(jidString);
if (!jid.hasLocalpart())
return null;
EntityFullJid fullJid = jid.asEntityFullJidIfPossible();
if (fullJid != null) {
return fullJid;
}
EntityBareJid bareJid = jid.asEntityBareJidIfPossible();
return bareJid;
}
use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.
the class DigestMd5SaslTest method runTest.
protected void runTest(boolean useAuthzid) throws NotConnectedException, SmackException, InterruptedException, XmppStringprepException, UnsupportedEncodingException {
EntityBareJid authzid = null;
if (useAuthzid) {
authzid = JidCreate.entityBareFrom("shazbat@xmpp.org");
}
saslMechanism.authenticate("florian", "irrelevant", JidCreate.domainBareFrom("xmpp.org"), "secret", authzid, null);
byte[] response = saslMechanism.evaluateChallenge(challengeBytes);
String responseString = new String(response, StringUtils.UTF8);
String[] responseParts = responseString.split(",");
Map<String, String> responsePairs = new HashMap<String, String>();
for (String part : responseParts) {
String[] keyValue = part.split("=");
assertTrue(keyValue.length == 2);
String key = keyValue[0];
String value = keyValue[1].replace("\"", "");
responsePairs.put(key, value);
}
if (useAuthzid) {
assertMapValue("authzid", "shazbat@xmpp.org", responsePairs);
} else {
assert (!responsePairs.containsKey("authzid"));
}
assertMapValue("username", "florian", responsePairs);
assertMapValue("realm", "xmpp.org", responsePairs);
assertMapValue("digest-uri", "xmpp/xmpp.org", responsePairs);
assertMapValue("qop", "auth", responsePairs);
}
use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.
the class IntTestUtil method registerAccountViaAdmin.
// public static UsernameAndPassword registerAccountViaAdmin(XMPPTCPConnection connection) throws XmppStringprepException, NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
// return registerAccountViaAdmin(connection, StringUtils.insecureRandomString(12),
// StringUtils.insecureRandomString(12));
// }
public static UsernameAndPassword registerAccountViaAdmin(XMPPTCPConnection connection, String username, String password, String adminAccountUsername, String adminAccountPassword) throws InterruptedException, XMPPException, SmackException, IOException {
connection.login(adminAccountUsername, adminAccountPassword);
ServiceAdministrationManager adminManager = ServiceAdministrationManager.getInstanceFor(connection);
EntityBareJid userJid = JidCreate.entityBareFrom(Localpart.from(username), connection.getServiceName());
adminManager.addUser(userJid, password);
connection.disconnect();
connection.connect();
return new UsernameAndPassword(username, password);
}
use of org.jxmpp.jid.EntityBareJid in project Smack by igniterealtime.
the class MamIntegrationTest method mamTest.
@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);
while (!mamQueryResult.mamFin.isComplete()) {
mamQueryResult = mamManagerConTwo.pageNext(mamQueryResult, pageSize);
}
List<Forwarded> forwardedMessages = mamQueryResult.forwardedMessages;
Message mamMessage = (Message) forwardedMessages.get(forwardedMessages.size() - 1).getForwardedStanza();
assertEquals(messageId, mamMessage.getStanzaId());
assertEquals(messageBody, mamMessage.getBody());
assertEquals(conOne.getUser(), mamMessage.getFrom());
assertEquals(userTwo, mamMessage.getTo());
}
Aggregations