Package com.calclab.emite.im.roster

Source Code of com.calclab.emite.im.roster.RosterItemTests

/*
* ((e)) emite: A pure Google Web Toolkit XMPP library
* Copyright (c) 2008-2011 The Emite development team
*
* This file is part of Emite.
*
* Emite is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Emite is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with Emite.  If not, see <http://www.gnu.org/licenses/>.
*/

package com.calclab.emite.im.roster;

import static com.calclab.emite.core.XmppURI.uri;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.junit.Test;

import com.calclab.emite.base.xml.XMLBuilder;
import com.calclab.emite.core.stanzas.Presence;
import com.calclab.emite.im.roster.RosterItem;
import com.calclab.emite.xtesting.matchers.EmiteAsserts;

public class RosterItemTests {

  @Test
  public void shouldConvertToStanza() {
    final RosterItem item = new RosterItem(uri("name@domain/RESOURCE"), null, "TheName", null);
    item.addToGroup("group1");
    item.addToGroup("group2");
    EmiteAsserts.assertPacketLike("<item jid='name@domain' name='TheName'>" + "<group>group1</group><group>group2</group></item>",
        item.addStanzaTo(XMLBuilder.create("all").getXML()));
  }

  @Test
  public void shouldIgnoreEmptyGroups() {
    final RosterItem item = new RosterItem(uri("name@domain/RESOURCE"), null, "TheName", null);
    item.addToGroup(null);
    item.addToGroup(" ");
    assertEquals(0, item.getGroups().size());
  }

  @Test
  public void shouldParseStanza() {
    final RosterItem item = RosterItem.parse(XMLBuilder.fromXML("<item jid='romeo@example.net' ask='subscribe' name='R' subscription='both'>"
        + "<group>Friends</group><group>X</group></item>"));
    assertEquals("R", item.getName());
    assertEquals("R", item.getName());
    assertEquals(Presence.Type.subscribe, item.getAsk());
    assertEquals(2, item.getGroups().size());
    assertTrue(item.getGroups().contains("Friends"));
    assertTrue(item.getGroups().contains("X"));
  }

}
TOP

Related Classes of com.calclab.emite.im.roster.RosterItemTests

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.