Skip to content

Commit a1351f4

Browse files
author
Lloyd Watkin
committed
Add a test to ensure that "in reply to" ID is saved to database (as local ID type)
1 parent 2280175 commit a1351f4

File tree

2 files changed

+36
-13
lines changed
  • src
    • main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set
    • test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set

2 files changed

+36
-13
lines changed

src/main/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/Publish.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ public void process(Element elm, JID actorJID, IQ reqIQ, Element rsm)
104104
saveNodeItem();
105105
sendResponseStanza();
106106
sendNotifications();
107-
107+
108108
} catch (NodeStoreException e) {
109109
setErrorCondition(PacketError.Type.wait,
110110
PacketError.Condition.internal_server_error);
@@ -127,9 +127,10 @@ private void extractItemDetails() throws InterruptedException {
127127
if (null == inReplyToElement) {
128128
return;
129129
}
130-
inReplyTo = inReplyToElement.attributeValue("ref");
130+
inReplyTo = GlobalItemIDImpl.toLocalId(inReplyToElement
131+
.attributeValue("ref"));
131132
}
132-
133+
133134
public void setEntryValidator(ValidateEntry validator) {
134135
this.validator = validator;
135136
}
@@ -141,11 +142,12 @@ private ValidateEntry getEntryValidator() {
141142
return this.validator;
142143
}
143144

144-
private void sendInvalidEntryResponse()
145-
throws InterruptedException {
146-
LOGGER.info("Entry is not valid: '" + entryContent.getErrorMessage() + "'.");
145+
private void sendInvalidEntryResponse() throws InterruptedException {
146+
LOGGER.info("Entry is not valid: '" + entryContent.getErrorMessage()
147+
+ "'.");
147148
createExtendedErrorReply(PacketError.Type.modify,
148-
PacketError.Condition.bad_request, entryContent.getErrorMessage());
149+
PacketError.Condition.bad_request,
150+
entryContent.getErrorMessage());
149151
outQueue.put(response);
150152
}
151153

@@ -229,7 +231,8 @@ private boolean checkNode() throws InterruptedException, NodeStoreException {
229231
if ((node == null) || (true == node.equals(""))) {
230232
response.setType(Type.error);
231233

232-
Element badRequest = new DOMElement(PacketError.Condition.bad_request.toXMPP(),
234+
Element badRequest = new DOMElement(
235+
PacketError.Condition.bad_request.toXMPP(),
233236
new org.dom4j.Namespace("", JabberPubsub.NS_XMPP_STANZAS));
234237

235238
Element nodeIdRequired = new DOMElement(NODE_ID_REQUIRED,
@@ -250,8 +253,7 @@ private boolean checkNode() throws InterruptedException, NodeStoreException {
250253
isLocalNode = channelManager.isLocalNode(node);
251254
} catch (IllegalArgumentException e) {
252255
response.setType(Type.error);
253-
PacketError pe = new PacketError(
254-
PacketError.Condition.bad_request,
256+
PacketError pe = new PacketError(PacketError.Condition.bad_request,
255257
PacketError.Type.modify);
256258
response.setError(pe);
257259
LOGGER.error(e);

src/test/java/org/buddycloud/channelserver/packetprocessor/iq/namespace/pubsub/set/PublishTest.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.dom4j.tree.BaseElement;
2525
import org.junit.Before;
2626
import org.junit.Test;
27+
import org.mockito.ArgumentCaptor;
2728
import org.mockito.Mockito;
2829
import org.xmpp.packet.IQ;
2930
import org.xmpp.packet.JID;
@@ -89,9 +90,7 @@ public void setUp() throws Exception {
8990

9091
Mockito.when(validateEntry.isValid()).thenReturn(true);
9192

92-
Mockito.when(
93-
validateEntry.getPayload()).thenReturn(
94-
entry);
93+
Mockito.when(validateEntry.getPayload()).thenReturn(entry);
9594

9695
}
9796

@@ -391,4 +390,26 @@ public void sendsOutExpectedNotifications() throws Exception {
391390
Assert.assertEquals(new JID("user2@server1"), notification.getTo());
392391

393392
}
393+
394+
@Test
395+
public void inReplyToIdIsSavedToDatabase() throws Exception {
396+
IQ request = readStanzaAsIq("/iq/pubsub/publish/reply.stanza");
397+
Mockito.when(validateEntry.getPayload()).thenReturn(
398+
request.getChildElement().element("publish").element("item")
399+
.element("entry"));
400+
401+
publish.process(element, jid, request, null);
402+
403+
Assert.assertEquals(IQ.Type.result, ((IQ) queue.poll()).getType());
404+
405+
ArgumentCaptor<NodeItemImpl> argument = ArgumentCaptor
406+
.forClass(NodeItemImpl.class);
407+
408+
Mockito.verify(channelManager, Mockito.times(1)).addNodeItem(
409+
argument.capture());
410+
411+
Assert.assertEquals("fc362eb42085f017ed9ccd9c4004b095", argument
412+
.getValue().getInReplyTo());
413+
Assert.assertEquals(node, argument.getValue().getNodeId());
414+
}
394415
}

0 commit comments

Comments
 (0)