forked from mrniko/netty-socketio
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request mrniko#678 from Skipua/bugfix/cross-namespace-broa…
…dcast Fix cross-namespace broadcast happens on single ns
- Loading branch information
Showing
3 changed files
with
85 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/test/java/com/corundumstudio/socketio/protocol/PacketTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package com.corundumstudio.socketio.protocol; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotSame; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertSame; | ||
|
||
import io.netty.buffer.Unpooled; | ||
import org.junit.Test; | ||
|
||
public class PacketTest { | ||
|
||
@Test | ||
public void packetCopyIsCreatedWhenNamespaceDiffers() { | ||
Packet oldPacket = createPacket(); | ||
|
||
String newNs = "new"; | ||
Packet newPacket = oldPacket.withNsp(newNs); | ||
assertEquals(newNs, newPacket.getNsp()); | ||
assertPacketCopied(oldPacket, newPacket); | ||
} | ||
|
||
@Test | ||
public void packetCopyIsCreatedWhenNewNamespaceDiffersAndIsNull() { | ||
Packet packet = createPacket(); | ||
Packet newPacket = packet.withNsp(null); | ||
assertNull(newPacket.getNsp()); | ||
assertPacketCopied(packet, newPacket); | ||
} | ||
|
||
@Test | ||
public void originalPacketReturnedIfNamespaceIsTheSame() { | ||
Packet packet = new Packet(PacketType.MESSAGE); | ||
assertSame(packet, packet.withNsp("")); | ||
} | ||
|
||
private void assertPacketCopied(Packet oldPacket, Packet newPacket) { | ||
assertNotSame(newPacket, oldPacket); | ||
assertEquals(oldPacket.getName(), newPacket.getName()); | ||
assertEquals(oldPacket.getType(), newPacket.getType()); | ||
assertEquals(oldPacket.getSubType(), newPacket.getSubType()); | ||
assertEquals(oldPacket.getAckId(), newPacket.getAckId()); | ||
assertEquals(oldPacket.getAttachments().size(), newPacket.getAttachments().size()); | ||
assertSame(oldPacket.getAttachments(), newPacket.getAttachments()); | ||
assertEquals(oldPacket.getData(), newPacket.getData()); | ||
assertSame(oldPacket.getDataSource(), newPacket.getDataSource()); | ||
} | ||
|
||
private Packet createPacket() { | ||
Packet packet = new Packet(PacketType.MESSAGE); | ||
packet.setSubType(PacketType.EVENT); | ||
packet.setName("packetName"); | ||
packet.setData("data"); | ||
packet.setAckId(1L); | ||
packet.setNsp("old"); | ||
packet.setDataSource(Unpooled.wrappedBuffer(new byte[]{10})); | ||
packet.initAttachments(1); | ||
packet.addAttachment(Unpooled.wrappedBuffer(new byte[]{20})); | ||
return packet; | ||
} | ||
} |