Skip to content

Commit 742b992

Browse files
author
Lloyd Watkin
committed
Finish node config result parsing code
1 parent be752ef commit 742b992

2 files changed

Lines changed: 73 additions & 2 deletions

File tree

  • src
    • main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/result
    • test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/result

src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/result/Configuration.java

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package org.buddycloud.channelserver.packetprocessor.iq.namespace.pubsub.result;
22

3+
import java.util.HashMap;
34
import java.util.List;
45

56
import org.apache.log4j.Logger;
67
import org.buddycloud.channelserver.channel.ChannelManager;
8+
import org.buddycloud.channelserver.channel.node.configuration.NodeConfigurationException;
9+
import org.buddycloud.channelserver.channel.node.configuration.field.Owner;
710
import org.buddycloud.channelserver.db.exception.NodeStoreException;
811
import org.buddycloud.channelserver.packetprocessor.iq.namespace.pubsub.PubSubElementProcessorAbstract;
912
import org.buddycloud.channelserver.pubsub.model.NodeSubscription;
@@ -12,12 +15,12 @@
1215
import org.dom4j.Element;
1316
import org.xmpp.packet.IQ;
1417
import org.xmpp.packet.JID;
18+
import org.xmpp.packet.PacketError;
1519

1620
public class Configuration extends PubSubElementProcessorAbstract {
1721

1822
private IQ request;
19-
private boolean ownerRequest;
20-
private String lastNode = "";
23+
Element configure;
2124

2225
private static final Logger logger = Logger
2326
.getLogger(Configuration.class);
@@ -36,7 +39,32 @@ public void process(Element elm, JID actorJID, IQ reqIQ, Element rsm)
3639
+ "from other buddycloud servers");
3740
return;
3841
}
42+
43+
configure = request.getChildElement().element("configure");
44+
node = configure.attributeValue("node");
45+
if (0 == node.length()) return;
46+
47+
if (false == channelManager.nodeExists(node)) {
48+
channelManager.addRemoteNode(node);
49+
}
50+
setNodeConfiguration();
51+
}
52+
53+
private void setNodeConfiguration() throws Exception {
54+
try {
55+
getNodeConfigurationHelper().parse(request);
56+
updateNodeConfiguration(getNodeConfigurationHelper()
57+
.getValues());
58+
} catch (NodeConfigurationException e) {
59+
logger.error("Node configuration exception", e);
60+
} catch (NodeStoreException e) {
61+
logger.error("Data Store Exception", e);
62+
}
63+
}
3964

65+
private void updateNodeConfiguration(HashMap<String, String> configuration)
66+
throws Exception {
67+
channelManager.setNodeConf(node, configuration);
4068
}
4169

4270
@Override

src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/result/ConfigurationTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,47 @@ public void testPassingNotConfigureAsElementNameReturnsFalse() {
5050
Element element = new BaseElement("not-configure");
5151
Assert.assertFalse(confResult.accept(element));
5252
}
53+
54+
@Test(expected = NullPointerException.class)
55+
public void testInvalidStanzaThrowsException() throws Exception {
56+
57+
IQ result = toIq("<iq type=\"result\" id=\"subscriptions1\" "
58+
+ "from=\"channels.shakespeare.lit\" "
59+
+ "to=\"channels.denmark.lit\">"
60+
+ "<pubsub xmlns=\"http://jabber.org/protocol/pubsub#owner\" />"
61+
+ "</iq>");
62+
63+
confResult.process(element, jid, result, null);
64+
}
65+
66+
@Test
67+
public void testEmptyNodeValueCausesNoAction() throws Exception {
68+
IQ result = toIq("<iq type=\"result\" id=\"subscriptions1\" "
69+
+ "from=\"channels.shakespeare.lit\" "
70+
+ "to=\"channels.denmark.lit\">"
71+
+ "<pubsub xmlns=\"http://jabber.org/protocol/pubsub#owner\">"
72+
+ "<configure node=\"\" />" + "</pubsub>" + "</iq>");
73+
74+
confResult.process(element, jid, result, null);
75+
76+
Mockito.verify(channelManager, Mockito.times(0)).nodeExists(
77+
Mockito.anyString());
78+
}
79+
80+
@Test
81+
public void testIfNodeIsUnknownThenItIsAddedToDatabase() throws Exception {
82+
IQ result = toIq("<iq type=\"result\" id=\"subscriptions1\" "
83+
+ "from=\"channels.shakespeare.lit\" "
84+
+ "to=\"channels.denmark.lit\">"
85+
+ "<pubsub xmlns=\"http://jabber.org/protocol/pubsub#owner\">"
86+
+ "<configure node=\"some-node\" />" + "</pubsub>" + "</iq>");
87+
88+
confResult.process(element, jid, result, null);
89+
90+
Mockito.when(channelManager.nodeExists(Mockito.anyString())).thenReturn(false);
91+
Mockito.verify(channelManager, Mockito.times(1)).nodeExists(
92+
Mockito.anyString());
93+
Mockito.verify(channelManager, Mockito.times(1)).addRemoteNode(
94+
Mockito.anyString());
95+
}
5396
}

0 commit comments

Comments
 (0)