Examples of LeafNode


Examples of org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.model.LeafNode

        String iqStanzaID = stanza.getAttributeValue("id");
        StanzaBuilder sb = StanzaBuilder.createIQStanza(serverJID, sender, IQStanzaType.RESULT, iqStanzaID);
        sb.startInnerElement("pubsub", NamespaceURIs.XEP0060_PUBSUB_OWNER);

        String nodeName = extractNodeName(stanza);
        LeafNode node = root.find(nodeName);

        if(node == null) {
            return errorStanzaGenerator.generateNoNodeErrorStanza(sender, serverJID, stanza);
        }

        if(!node.isAuthorized(sender, PubSubPrivilege.MANAGE_AFFILIATIONS)) {
            return errorStanzaGenerator.generateInsufficientPrivilegesErrorStanza(sender, serverJID, stanza);
        }


        XMLElement affiliationElement = null;
        try {
            if(stanza.getFirstInnerElement().getFirstInnerElement().getInnerElements().size() != 1) {
                return errorStanzaGenerator.generateNotAcceptableErrorStanza(serverJID, sender, stanza);
            }

            affiliationElement = stanza.getFirstInnerElement().getFirstInnerElement().getFirstInnerElement();

            Entity userJID = null;
            try {
                userJID = EntityImpl.parse(affiliationElement.getAttributeValue("jid"));
            } catch (EntityFormatException e) {
                return errorStanzaGenerator.generateJIDMalformedErrorStanza(serverJID, sender, stanza); // TODO not defined in the standard(?)
            }

            PubSubAffiliation newAffiliation = PubSubAffiliation.get(affiliationElement.getAttributeValue("affiliation"));
            node.setAffiliation(userJID, newAffiliation);
        } catch(LastOwnerResignedException e) {
            // if the last owner tries to resign.
            return errorStanzaGenerator.generateNotAcceptableErrorStanza(serverJID, sender, stanza);
        } catch(Throwable t) { // possible null-pointer
            return errorStanzaGenerator.generateBadRequestErrorStanza(serverJID, sender, stanza); // TODO not defined in the standard(?)
View Full Code Here

Examples of org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.model.LeafNode

        return new PubSubOwnerDeleteNodeHandler(serviceConfiguration);
    }

    public void testDelete() throws Exception {
        String testNode = "test";
        LeafNode node = new LeafNode(serviceConfiguration, testNode, client);
        root.add(node);
       
        node.subscribe("someid", client); // make the owner subscriber
        node.subscribe("otherid1", new EntityImpl("yoda", "starwars.com", "spaceship"));
        node.subscribe("otherid2", new EntityImpl("r2d2", "starwars.com", "desert"));
        node.subscribe("otherid3", new EntityImpl("anakin", "starwars.com", "deathstar"));
       
        assertNotNull(root.find(testNode));
        // make sure we have 4 subscribers
        assertEquals(4, node.countSubscriptions());
       
        AbstractStanzaGenerator sg = getDefaultStanzaGenerator();
        Stanza stanza = sg.getStanza(client, pubsubService, "id123", testNode);
        ResponseStanzaContainer result = sendStanza(stanza, true);
        assertTrue(result.hasResponse());
        IQStanza response = new IQStanza(result.getResponseStanza());
        assertEquals(IQStanzaType.RESULT.value(),response.getType());

        assertEquals("id123", response.getAttributeValue("id")); // IDs must match
       
        LeafNode n = root.find(testNode);
        assertNull(n);
       
        // check that the subscribers got a notification
        assertEquals(4, relay.getCountRelayed());
    }
View Full Code Here

Examples of org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.model.LeafNode

        assertEquals(4, relay.getCountRelayed());
    }
   
    public void testDeleteNotAuth() throws Exception {
        String testNode = "test";
        root.add(new LeafNode(serviceConfiguration, testNode, client));
       
        assertNotNull(root.find(testNode));
        Entity clientNotAuthorized = new EntityImpl("darthvader", "deathstar.tld", null);
       
        AbstractStanzaGenerator sg = getDefaultStanzaGenerator();
        Stanza stanza = sg.getStanza(clientNotAuthorized, pubsubService, "id123", testNode);
        ResponseStanzaContainer result = sendStanza(stanza, true);
        assertTrue(result.hasResponse());
        IQStanza response = new IQStanza(result.getResponseStanza());
        assertEquals(IQStanzaType.ERROR.value(),response.getType());

        assertEquals("id123", response.getAttributeValue("id")); // IDs must match
       
        XMLElement error = response.getInnerElementsNamed("error").get(0); //jump directly to the error part
        assertEquals("error", error.getName());
        assertEquals("auth", error.getAttributeValue("type"));
       
        List<XMLElement> errorContent = error.getInnerElements();
        assertEquals(1, errorContent.size());
        assertEquals("forbidden", errorContent.get(0).getName());
        assertEquals(NamespaceURIs.URN_IETF_PARAMS_XML_NS_XMPP_STANZAS, errorContent.get(0).getNamespaceURI());
       
        LeafNode n = root.find(testNode);
        assertNotNull(n); // still there
    }
View Full Code Here

Examples of org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.model.LeafNode

            // error condition 1 (6.1.3)
            return errorStanzaGenerator.generateJIDDontMatchErrorStanza(sender, serverJID, stanza);
        }

        String nodeName = extractNodeName(stanza);
        LeafNode node = root.find(nodeName);

        if(node == null) {
            // no such node (error condition 11 (6.1.3))
            return errorStanzaGenerator.generateNoNodeErrorStanza(sender, serverJID, stanza);
        }

        String id = idGenerator.create();
        node.subscribe(id, subJID);

        buildSuccessStanza(sb, nodeName, strSubJID, id);

        sb.endInnerElement(); // pubsub
        return new IQStanza(sb.build());
View Full Code Here

Examples of org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.model.LeafNode

    /**
     * Delete the node specified by nodeName.
     */
    public void deleteNode(String nodeName) {
        LeafNode n = findNode(nodeName);
        n.delete();
        this.nodes.remove(nodeName);
    }
View Full Code Here

Examples of org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.model.LeafNode

    @Override
    public void setUp() throws Exception {
        super.setUp();
       
        n1 = new LeafNode(serviceConfiguration, "Node1", "Node 1 used for testing purposes", client);
        n2 = new LeafNode(serviceConfiguration, "Node2", "Node 2 used for testing purposes", client);
        n3 = new LeafNode(serviceConfiguration, "Node3", "Node 3 used for testing purposes", client);
       
        root.add(n1);
        root.add(n2);
        root.add(n3);
    }
View Full Code Here

Examples of org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.model.LeafNode

    protected LeafNode node = null;

    @Override
    public void setUp() throws Exception {
        super.setUp();
        node = new LeafNode(serviceConfiguration, "news", "Node used for testing purposes", client);
        root.add(node);
    }
View Full Code Here

Examples of org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.model.LeafNode

    public void setUp() throws Exception {
        super.setUp();
        Entity client2 = new EntityImpl("user1", "vysper.org", null);
        Entity client3 = new EntityImpl("user2", "vysper.org", null);

        n1 = new LeafNode(serviceConfiguration, "Node1", "Node 1 used for testing purposes", client);
        n1.setAffiliation(client2, PubSubAffiliation.OWNER);
        n1.setAffiliation(client3, PubSubAffiliation.OWNER);

        root.add(n1);
    }
View Full Code Here

Examples of org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.model.LeafNode

        // since we have no nodes, there should be no items.
        assertEquals(0, inner.size());
    }
   
    public void testSomeItems() throws Exception {
        root.add(new LeafNode(serviceConfiguration, "news", "News", client));
        root.add(new LeafNode(serviceConfiguration, "blogs", "Blogs", client));
       
        DefaultDiscoInfoStanzaGenerator sg = (DefaultDiscoInfoStanzaGenerator)getDefaultStanzaGenerator();
        Stanza stanza = sg.getStanza(client, pubsubService.getBareJID(), "id123");

        ResponseStanzaContainer result = sendStanza(stanza, true);
View Full Code Here

Examples of org.apache.vysper.xmpp.modules.extension.xep0060_pubsub.model.LeafNode

        assertNotNull(news);
        assertNotNull(blogs);
    }
   
    public void testNodeItemsNone() throws Exception {
        root.add(new LeafNode(serviceConfiguration, "news", "News", client));
       
        DefaultDiscoInfoStanzaGenerator sg = (DefaultDiscoInfoStanzaGenerator)getDefaultStanzaGenerator();
        Stanza stanza = sg.getStanza(client, pubsubService.getBareJID(), "id123", "news");

        ResponseStanzaContainer result = sendStanza(stanza, true);
View Full Code Here
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.