Search in sources :

Example 11 with EntityBareJid

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();
}
Also used : Message(org.jivesoftware.smack.packet.Message) ResultSyncPoint(org.igniterealtime.smack.inttest.util.ResultSyncPoint) MessageListener(org.jivesoftware.smack.MessageListener) EntityBareJid(org.jxmpp.jid.EntityBareJid) MucCreateConfigFormHandle(org.jivesoftware.smackx.muc.MultiUserChat.MucCreateConfigFormHandle) TestNotPossibleException(org.igniterealtime.smack.inttest.TestNotPossibleException) NotConnectedException(org.jivesoftware.smack.SmackException.NotConnectedException) TimeoutException(java.util.concurrent.TimeoutException) XMPPErrorException(org.jivesoftware.smack.XMPPException.XMPPErrorException) NoResponseException(org.jivesoftware.smack.SmackException.NoResponseException) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest)

Example 12 with EntityBareJid

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;
}
Also used : Jid(org.jxmpp.jid.Jid) EntityJid(org.jxmpp.jid.EntityJid) EntityFullJid(org.jxmpp.jid.EntityFullJid) EntityBareJid(org.jxmpp.jid.EntityBareJid) EntityFullJid(org.jxmpp.jid.EntityFullJid) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Example 13 with EntityBareJid

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);
}
Also used : HashMap(java.util.HashMap) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Example 14 with EntityBareJid

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);
}
Also used : ServiceAdministrationManager(org.jivesoftware.smackx.admin.ServiceAdministrationManager) EntityBareJid(org.jxmpp.jid.EntityBareJid)

Example 15 with EntityBareJid

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());
}
Also used : Message(org.jivesoftware.smack.packet.Message) Forwarded(org.jivesoftware.smackx.forward.packet.Forwarded) MamQueryResult(org.jivesoftware.smackx.mam.MamManager.MamQueryResult) EntityBareJid(org.jxmpp.jid.EntityBareJid) AbstractSmackIntegrationTest(org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest) SmackIntegrationTest(org.igniterealtime.smack.inttest.SmackIntegrationTest)

Aggregations

EntityBareJid (org.jxmpp.jid.EntityBareJid)15 EntityFullJid (org.jxmpp.jid.EntityFullJid)3 Jid (org.jxmpp.jid.Jid)3 ArrayList (java.util.ArrayList)2 AbstractSmackIntegrationTest (org.igniterealtime.smack.inttest.AbstractSmackIntegrationTest)2 SmackIntegrationTest (org.igniterealtime.smack.inttest.SmackIntegrationTest)2 SmackException (org.jivesoftware.smack.SmackException)2 NoResponseException (org.jivesoftware.smack.SmackException.NoResponseException)2 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)2 XMPPErrorException (org.jivesoftware.smack.XMPPException.XMPPErrorException)2 Message (org.jivesoftware.smack.packet.Message)2 ServiceAdministrationManager (org.jivesoftware.smackx.admin.ServiceAdministrationManager)2 EntityJid (org.jxmpp.jid.EntityJid)2 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 TimeoutException (java.util.concurrent.TimeoutException)1 TestNotPossibleException (org.igniterealtime.smack.inttest.TestNotPossibleException)1 ResultSyncPoint (org.igniterealtime.smack.inttest.util.ResultSyncPoint)1 MessageListener (org.jivesoftware.smack.MessageListener)1 XMPPException (org.jivesoftware.smack.XMPPException)1