continue; packetUnavailable.setFrom(JidCreate.fullFrom(bareUserJid, resource)); try { presencePacketListener.processStanza(packetUnavailable);
@Test(expected = IllegalArgumentException.class) public void transportCandidateIllegalPortTest() throws XmppStringprepException { FullJid jid = JidCreate.fullFrom("test@test.test/test"); @SuppressWarnings("unused") JingleS5BTransportCandidate candidate = new JingleS5BTransportCandidate( "cid", "host", jid, -5555, 30, JingleS5BTransportCandidate.Type.proxy); }
@Test(expected = IllegalArgumentException.class) public void transportCandidateIllegalPriorityTest() throws XmppStringprepException { FullJid jid = JidCreate.fullFrom("test@test.test/test"); @SuppressWarnings("unused") JingleS5BTransportCandidate candidate = new JingleS5BTransportCandidate( "cid", "host", jid, 5555, -30, JingleS5BTransportCandidate.Type.proxy); }
@Test public void candidateFromStreamHostTest() throws XmppStringprepException { FullJid jid = JidCreate.fullFrom("test@test.test/test"); String host = "host.address"; int port = 1234; Bytestream.StreamHost streamHost = new Bytestream.StreamHost(jid, host, port); JingleS5BTransportCandidate candidate = new JingleS5BTransportCandidate(streamHost, 2000, JingleS5BTransportCandidate.Type.direct); assertEquals(2000, candidate.getPriority()); assertEquals(jid, candidate.getJid()); assertEquals(host, candidate.getHost()); assertEquals(port, candidate.getPort()); assertEquals(streamHost.toXML(null).toString(), candidate.getStreamHost().toXML(null).toString()); }
@Test public void parserTest() throws XmppStringprepException { String sessionId = "testSessionId"; Jingle.Builder builder = Jingle.getBuilder(); builder.setSessionId(sessionId); builder.setAction(JingleAction.session_initiate); FullJid romeo = JidCreate.fullFrom("romeo@montague.lit/orchard"); FullJid juliet = JidCreate.fullFrom("juliet@capulet.lit/balcony"); builder.setInitiator(romeo); builder.setResponder(juliet); Jingle jingle = builder.build(); assertNotNull(jingle); assertEquals(romeo, jingle.getInitiator()); assertEquals(juliet, jingle.getResponder()); assertEquals(jingle.getAction(), JingleAction.session_initiate); assertEquals(sessionId, jingle.getSid()); String xml = "<jingle xmlns='urn:xmpp:jingle:1' " + "initiator='romeo@montague.lit/orchard' " + "responder='juliet@capulet.lit/balcony' " + "action='session-initiate' " + "sid='" + sessionId + "'>" + "</jingle>"; assertTrue(jingle.toXML(null).toString().contains(xml)); } }
@Test public void sessionInitiateTest() throws XmppStringprepException { FullJid romeo = connection.getUser().asFullJidOrThrow(); FullJid juliet = JidCreate.fullFrom("juliet@capulet.example/yn0cl4bnw0yr3vym");
/** * {@inheritDoc} */ @Override public EntityFullJid getFocusJid() { return JidCreate.fullFrom(roomName, focusUserName); }
/** * Get a {@link FullJid} from a given {@link CharSequence} or {@code null} if the input does not represent a JID. * * @param cs the input {@link CharSequence} * @return a JID or {@code null} */ public static FullJid fullFromOrNull(CharSequence cs) { try { return fullFrom(cs); } catch (XmppStringprepException e) { return null; } }
/** * Get a {@link FullJid} representing the given CharSequence. * * @param jid a CharSequence representing a JID. * @return a full JID representing the given CharSequence. * @throws XmppStringprepException if an error occurs. */ public static FullJid fullFrom(CharSequence jid) throws XmppStringprepException { return fullFrom(jid.toString()); }
/** * Like {@link #fullFrom(CharSequence)} but does throw an unchecked {@link IllegalArgumentException} instead of a * {@link XmppStringprepException}. * * @param cs the character sequence which should be transformed to a {@link FullJid} * @return the {@link FullJid} if no exception occurs * @throws IllegalArgumentException if the given input is not a valid JID * @see #fullFrom(CharSequence) * @since 0.6.2 */ public static FullJid fullFromOrThrowUnchecked(CharSequence cs) { try { return fullFrom(cs); } catch (XmppStringprepException e) { throw new IllegalArgumentException(e); } }
/** * Get a {@link FullJid} constructed from the given parts. * * @param localpart the optional localpart. * @param domainpart the domainpart. * @param resource the resourcepart. * @return a full JID. */ public static FullJid fullFrom(Localpart localpart, Domainpart domainpart, Resourcepart resource) { return fullFrom(entityBareFrom(localpart, domainpart), resource); }
/** * Get a {@link FullJid} constructed from the given parts. * * @param localpart a optional localpart. * @param domainBareJid a domain bare JID. * @param resource a resourcepart * @return a full JID. */ public static FullJid fullFrom(Localpart localpart, DomainBareJid domainBareJid, Resourcepart resource) { return fullFrom(localpart, domainBareJid.getDomain(), resource); }
continue; packetUnavailable.setFrom(JidCreate.fullFrom(bareUserJid, resource)); try { presencePacketListener.processStanza(packetUnavailable);
/** * Get a {@link FullJid} representing the given String. * * @param jid the JID's String. * @return a full JID representing the input String. * @throws XmppStringprepException if an error occurs. */ public static FullJid fullFrom(String jid) throws XmppStringprepException { FullJid fullJid = FULLJID_CACHE.lookup(jid); if (fullJid != null) { return fullJid; } String localpart = XmppStringUtils.parseLocalpart(jid); String domainpart = XmppStringUtils.parseDomain(jid); String resource = XmppStringUtils.parseResource(jid); try { fullJid = fullFrom(localpart, domainpart, resource); } catch (XmppStringprepException e) { throw new XmppStringprepException(jid, e); } FULLJID_CACHE.put(jid, fullJid); return fullJid; }