updates to unit tests
This commit is contained in:
parent
8d0d3adcf9
commit
eed8db7340
|
@ -6,9 +6,9 @@ import org.eclipse.jetty.util.log.Log;
|
|||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.websocket.api.PolicyViolationException;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.protocol.CloseInfo;
|
||||
import org.eclipse.jetty.websocket.protocol.OpCode;
|
||||
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
|
||||
import org.eclipse.jetty.websocket.util.CloseUtil;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
|
@ -153,7 +153,8 @@ public class FrameGenerator
|
|||
|
||||
if (frame.getOpCode() == OpCode.CLOSE)
|
||||
{
|
||||
CloseUtil.assertValidPayload(frame);
|
||||
// validate the close
|
||||
new CloseInfo(frame.getPayloadData(),true);
|
||||
}
|
||||
// copy payload
|
||||
buffer.put(frame.getPayloadData());
|
||||
|
|
|
@ -71,11 +71,21 @@ public class FrameBuilder
|
|||
return new FrameBuilder(new WebSocketFrame(OpCode.PING));
|
||||
}
|
||||
|
||||
public static FrameBuilder ping(String message)
|
||||
{
|
||||
return new FrameBuilder(new WebSocketFrame(OpCode.PING)).payload(message.getBytes(StringUtil.__UTF8_CHARSET));
|
||||
}
|
||||
|
||||
public static FrameBuilder pong()
|
||||
{
|
||||
return new FrameBuilder(new WebSocketFrame(OpCode.PONG));
|
||||
}
|
||||
|
||||
public static FrameBuilder pong(String message)
|
||||
{
|
||||
return new FrameBuilder(new WebSocketFrame(OpCode.PONG)).payload(message.getBytes(StringUtil.__UTF8_CHARSET));
|
||||
}
|
||||
|
||||
public static FrameBuilder text()
|
||||
{
|
||||
return new FrameBuilder(new WebSocketFrame(OpCode.TEXT));
|
||||
|
@ -83,7 +93,7 @@ public class FrameBuilder
|
|||
|
||||
public static FrameBuilder text(String text)
|
||||
{
|
||||
return new FrameBuilder(new WebSocketFrame(OpCode.TEXT)).payload(text.getBytes());
|
||||
return new FrameBuilder(new WebSocketFrame(OpCode.TEXT)).payload(text.getBytes(StringUtil.__UTF8_CHARSET));
|
||||
}
|
||||
|
||||
private WebSocketFrame frame;
|
||||
|
|
|
@ -12,6 +12,12 @@ public class CloseUtil
|
|||
public static void assertValidPayload(WebSocketFrame frame)
|
||||
{
|
||||
byte payload[] = frame.getPayloadData();
|
||||
|
||||
if (payload.length < 2)
|
||||
{
|
||||
return; // no status code
|
||||
}
|
||||
|
||||
int statusCode = getStatusCode(payload);
|
||||
|
||||
// Validate value
|
||||
|
@ -43,10 +49,6 @@ public class CloseUtil
|
|||
|
||||
public static int getStatusCode(byte[] payload)
|
||||
{
|
||||
if (payload.length < 2)
|
||||
{
|
||||
return 0; // no status code
|
||||
}
|
||||
|
||||
int statusCode = 0;
|
||||
ByteBuffer bb = ByteBuffer.wrap(payload);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.eclipse.jetty.websocket.ab;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
|
@ -8,10 +8,12 @@ import org.eclipse.jetty.websocket.ByteBufferAssert;
|
|||
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketException;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.PingFrame;
|
||||
import org.eclipse.jetty.websocket.generator.Generator;
|
||||
import org.eclipse.jetty.websocket.parser.FrameParseCapture;
|
||||
import org.eclipse.jetty.websocket.parser.Parser;
|
||||
import org.eclipse.jetty.websocket.protocol.FrameBuilder;
|
||||
import org.eclipse.jetty.websocket.protocol.OpCode;
|
||||
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -29,7 +31,7 @@ public class TestABCase2
|
|||
bytes[i] = Integer.valueOf(Integer.toOctalString(i)).byteValue();
|
||||
}
|
||||
|
||||
PingFrame pingFrame = new PingFrame(bytes);
|
||||
WebSocketFrame pingFrame = FrameBuilder.ping().payload(bytes).asFrame();
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(bytes.length + 32);
|
||||
|
@ -57,7 +59,7 @@ public class TestABCase2
|
|||
{
|
||||
byte[] bytes = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
|
||||
|
||||
PingFrame pingFrame = new PingFrame(bytes);
|
||||
WebSocketFrame pingFrame = FrameBuilder.ping().payload(bytes).asFrame();
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(32);
|
||||
|
@ -84,7 +86,7 @@ public class TestABCase2
|
|||
@Test
|
||||
public void testGenerateEmptyPingCase2_1()
|
||||
{
|
||||
PingFrame pingFrame = new PingFrame();
|
||||
WebSocketFrame pingFrame = FrameBuilder.ping().asFrame();
|
||||
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
|
@ -108,7 +110,7 @@ public class TestABCase2
|
|||
String message = "Hello, world!";
|
||||
byte[] messageBytes = message.getBytes();
|
||||
|
||||
PingFrame pingFrame = new PingFrame(messageBytes);
|
||||
WebSocketFrame pingFrame = FrameBuilder.text(message).asFrame();
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(32);
|
||||
|
@ -141,7 +143,7 @@ public class TestABCase2
|
|||
bytes[i] = 0x00;
|
||||
}
|
||||
|
||||
new PingFrame(bytes);
|
||||
FrameBuilder.ping().payload(bytes);
|
||||
}
|
||||
|
||||
@Test( expected=WebSocketException.class )
|
||||
|
@ -154,8 +156,10 @@ public class TestABCase2
|
|||
bytes[i] = 0x00;
|
||||
}
|
||||
|
||||
PingFrame pingFrame = new PingFrame();
|
||||
pingFrame.setPayload(ByteBuffer.allocate(bytes.length + 32).put(bytes));
|
||||
WebSocketFrame pingFrame = FrameBuilder.ping().payload(bytes).asFrame();
|
||||
|
||||
Generator generator = new Generator(WebSocketPolicy.newServerPolicy());
|
||||
generator.generate(ByteBuffer.allocate(bytes.length + 32),pingFrame);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -186,11 +190,11 @@ public class TestABCase2
|
|||
parser.parse(expected);
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(PingFrame.class,1);
|
||||
capture.assertHasFrame(OpCode.PING,1);
|
||||
|
||||
PingFrame pActual = (PingFrame)capture.getFrames().get(0);
|
||||
WebSocketFrame pActual = capture.getFrames().get(0);
|
||||
Assert.assertThat("PingFrame.payloadLength",pActual.getPayloadLength(),is(bytes.length));
|
||||
ByteBufferAssert.assertSize("PingFrame.payload",bytes.length,pActual.getPayload());
|
||||
Assert.assertEquals("PingFrame.payload",bytes.length,pActual.getPayloadLength());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -216,12 +220,11 @@ public class TestABCase2
|
|||
parser.parse(expected);
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(PingFrame.class,1);
|
||||
capture.assertHasFrame(OpCode.PING,1);
|
||||
|
||||
PingFrame pActual = (PingFrame)capture.getFrames().get(0);
|
||||
WebSocketFrame pActual = capture.getFrames().get(0);
|
||||
Assert.assertThat("PingFrame.payloadLength",pActual.getPayloadLength(),is(bytes.length));
|
||||
ByteBufferAssert.assertSize("PingFrame.payload",bytes.length,pActual.getPayload());
|
||||
|
||||
Assert.assertEquals("PingFrame.payload",bytes.length,pActual.getPayloadLength());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -240,11 +243,11 @@ public class TestABCase2
|
|||
parser.parse(expected);
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(PingFrame.class,1);
|
||||
capture.assertHasFrame(OpCode.PING,1);
|
||||
|
||||
PingFrame pActual = (PingFrame)capture.getFrames().get(0);
|
||||
WebSocketFrame pActual = capture.getFrames().get(0);
|
||||
Assert.assertThat("PingFrame.payloadLength",pActual.getPayloadLength(),is(0));
|
||||
ByteBufferAssert.assertSize("PingFrame.payload",0,pActual.getPayload());
|
||||
Assert.assertEquals("PingFrame.payload",0,pActual.getPayloadLength());
|
||||
|
||||
}
|
||||
|
||||
|
@ -272,11 +275,11 @@ public class TestABCase2
|
|||
parser.parse(expected);
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(PingFrame.class,1);
|
||||
capture.assertHasFrame(OpCode.PING,1);
|
||||
|
||||
PingFrame pActual = (PingFrame)capture.getFrames().get(0);
|
||||
WebSocketFrame pActual = capture.getFrames().get(0);
|
||||
Assert.assertThat("PingFrame.payloadLength",pActual.getPayloadLength(),is(message.length()));
|
||||
ByteBufferAssert.assertSize("PingFrame.payload",message.length(),pActual.getPayload());
|
||||
Assert.assertEquals("PingFrame.payload",message.length(),pActual.getPayloadLength());
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,81 +1,65 @@
|
|||
package org.eclipse.jetty.websocket.ab;
|
||||
|
||||
import org.eclipse.jetty.websocket.frames.CloseFrame;
|
||||
import org.eclipse.jetty.websocket.frames.PingFrame;
|
||||
import org.eclipse.jetty.websocket.frames.PongFrame;
|
||||
import org.junit.Test;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jetty.websocket.api.PolicyViolationException;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.generator.Generator;
|
||||
import org.eclipse.jetty.websocket.protocol.FrameBuilder;
|
||||
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.runners.Parameterized.Parameters;
|
||||
|
||||
@RunWith(value = Parameterized.class)
|
||||
public class TestABCase3
|
||||
{
|
||||
@Test( expected=IllegalArgumentException.class )
|
||||
public void testGenerateRSV1PingFrame()
|
||||
{
|
||||
PingFrame pingFrame = new PingFrame();
|
||||
|
||||
pingFrame.setRsv1(true);
|
||||
@Parameters
|
||||
public static Collection<WebSocketFrame[]> data()
|
||||
{
|
||||
List<WebSocketFrame[]> data = new ArrayList<>();
|
||||
// @formatter:off
|
||||
data.add(new WebSocketFrame[]
|
||||
{ FrameBuilder.ping().rsv1(true).asFrame() });
|
||||
data.add(new WebSocketFrame[]
|
||||
{ FrameBuilder.ping().rsv2(true).asFrame() });
|
||||
data.add(new WebSocketFrame[]
|
||||
{ FrameBuilder.ping().rsv3(true).asFrame() });
|
||||
data.add(new WebSocketFrame[]
|
||||
{ FrameBuilder.pong().rsv1(true).asFrame() });
|
||||
data.add(new WebSocketFrame[]
|
||||
{ FrameBuilder.pong().rsv2(true).asFrame() });
|
||||
data.add(new WebSocketFrame[]
|
||||
{ FrameBuilder.pong().rsv3(true).asFrame() });
|
||||
data.add(new WebSocketFrame[]
|
||||
{ FrameBuilder.close().rsv1(true).asFrame() });
|
||||
data.add(new WebSocketFrame[]
|
||||
{ FrameBuilder.close().rsv2(true).asFrame() });
|
||||
data.add(new WebSocketFrame[]
|
||||
{ FrameBuilder.close().rsv3(true).asFrame() });
|
||||
// @formatter:on
|
||||
return data;
|
||||
}
|
||||
|
||||
@Test( expected=IllegalArgumentException.class )
|
||||
public void testGenerateRSV2PingFrame()
|
||||
{
|
||||
PingFrame pingFrame = new PingFrame();
|
||||
private WebSocketFrame invalidFrame;
|
||||
|
||||
pingFrame.setRsv2(true);
|
||||
public TestABCase3(WebSocketFrame invalidFrame)
|
||||
{
|
||||
this.invalidFrame = invalidFrame;
|
||||
}
|
||||
|
||||
@Test( expected=IllegalArgumentException.class )
|
||||
public void testGenerateRSV3PingFrame()
|
||||
{
|
||||
PingFrame pingFrame = new PingFrame();
|
||||
|
||||
pingFrame.setRsv3(true);
|
||||
}
|
||||
|
||||
@Test( expected=IllegalArgumentException.class )
|
||||
public void testGenerateRSV1PongFrame()
|
||||
{
|
||||
PongFrame pongFrame = new PongFrame();
|
||||
|
||||
pongFrame.setRsv1(true);
|
||||
}
|
||||
|
||||
@Test( expected=IllegalArgumentException.class )
|
||||
public void testGenerateRSV2PongFrame()
|
||||
{
|
||||
PongFrame pongFrame = new PongFrame();
|
||||
|
||||
pongFrame.setRsv2(true);
|
||||
}
|
||||
|
||||
@Test( expected=IllegalArgumentException.class )
|
||||
public void testGenerateRSV3PongFrame()
|
||||
{
|
||||
PongFrame pongFrame = new PongFrame();
|
||||
|
||||
pongFrame.setRsv3(true);
|
||||
}
|
||||
|
||||
@Test( expected=IllegalArgumentException.class )
|
||||
@Test(expected = PolicyViolationException.class)
|
||||
public void testGenerateRSV1CloseFrame()
|
||||
{
|
||||
CloseFrame closeFrame = new CloseFrame();
|
||||
Generator generator = new Generator(WebSocketPolicy.newServerPolicy());
|
||||
|
||||
closeFrame.setRsv1(true);
|
||||
generator.generate(ByteBuffer.allocate(32),invalidFrame);
|
||||
}
|
||||
|
||||
@Test( expected=IllegalArgumentException.class )
|
||||
public void testGenerateRSV2CloseFrame()
|
||||
{
|
||||
CloseFrame closeFrame = new CloseFrame();
|
||||
|
||||
closeFrame.setRsv2(true);
|
||||
}
|
||||
|
||||
@Test( expected=IllegalArgumentException.class )
|
||||
public void testGenerateRSV3CloseFrame()
|
||||
{
|
||||
CloseFrame closeFrame = new CloseFrame();
|
||||
|
||||
closeFrame.setRsv3(true);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package org.eclipse.jetty.websocket.ab;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
|
@ -9,10 +9,12 @@ import org.eclipse.jetty.websocket.api.ProtocolException;
|
|||
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketException;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.CloseFrame;
|
||||
import org.eclipse.jetty.websocket.generator.Generator;
|
||||
import org.eclipse.jetty.websocket.parser.FrameParseCapture;
|
||||
import org.eclipse.jetty.websocket.parser.Parser;
|
||||
import org.eclipse.jetty.websocket.protocol.FrameBuilder;
|
||||
import org.eclipse.jetty.websocket.protocol.OpCode;
|
||||
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -23,8 +25,8 @@ public class TestABCase7_3
|
|||
@Test (expected = WebSocketException.class)
|
||||
public void testGenerate1BytePayloadCloseCase7_3_2()
|
||||
{
|
||||
CloseFrame closeFrame = new CloseFrame();
|
||||
closeFrame.setPayload(new byte[] {0x00});
|
||||
WebSocketFrame closeFrame = FrameBuilder.close().payload(new byte[]
|
||||
{ 0x00 }).asFrame();
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(32);
|
||||
|
@ -34,7 +36,7 @@ public class TestABCase7_3
|
|||
@Test
|
||||
public void testGenerateCloseWithStatusCase7_3_3()
|
||||
{
|
||||
CloseFrame closeFrame = new CloseFrame(1000);
|
||||
WebSocketFrame closeFrame = FrameBuilder.close(1000).asFrame();
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(32);
|
||||
|
@ -63,7 +65,7 @@ public class TestABCase7_3
|
|||
|
||||
byte[] messageBytes = message.toString().getBytes();
|
||||
|
||||
CloseFrame closeFrame = new CloseFrame(1000, message.toString());
|
||||
WebSocketFrame closeFrame = FrameBuilder.close(1000,message.toString()).asFrame();
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(132);
|
||||
|
@ -99,8 +101,11 @@ public class TestABCase7_3
|
|||
|
||||
byte[] messageBytes = message.toString().getBytes();
|
||||
|
||||
CloseFrame closeFrame = new CloseFrame(1000, message.toString());
|
||||
WebSocketFrame closeFrame = FrameBuilder.close(1000,message.toString()).asFrame();
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(32);
|
||||
generator.generate(actual,closeFrame);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -109,7 +114,7 @@ public class TestABCase7_3
|
|||
String message = "bad cough";
|
||||
byte[] messageBytes = message.getBytes();
|
||||
|
||||
CloseFrame closeFrame = new CloseFrame(1000, message);
|
||||
WebSocketFrame closeFrame = FrameBuilder.close(1000,message.toString()).asFrame();
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(32);
|
||||
|
@ -135,7 +140,7 @@ public class TestABCase7_3
|
|||
@Test
|
||||
public void testGenerateEmptyCloseCase7_3_1()
|
||||
{
|
||||
CloseFrame closeFrame = new CloseFrame();
|
||||
WebSocketFrame closeFrame = FrameBuilder.close().asFrame();
|
||||
|
||||
Generator generator = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(32);
|
||||
|
@ -191,11 +196,10 @@ public class TestABCase7_3
|
|||
parser.parse(expected);
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(CloseFrame.class,1);
|
||||
capture.assertHasFrame(OpCode.CLOSE,1);
|
||||
|
||||
CloseFrame pActual = (CloseFrame)capture.getFrames().get(0);
|
||||
WebSocketFrame pActual = capture.getFrames().get(0);
|
||||
Assert.assertThat("CloseFrame.payloadLength",pActual.getPayloadLength(),is(2));
|
||||
ByteBufferAssert.assertSize("CloseFrame.payload",2,pActual.getPayload());
|
||||
|
||||
}
|
||||
|
||||
|
@ -230,11 +234,10 @@ public class TestABCase7_3
|
|||
parser.parse(expected);
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(CloseFrame.class,1);
|
||||
capture.assertHasFrame(OpCode.CLOSE,1);
|
||||
|
||||
CloseFrame pActual = (CloseFrame)capture.getFrames().get(0);
|
||||
WebSocketFrame pActual = capture.getFrames().get(0);
|
||||
Assert.assertThat("CloseFrame.payloadLength",pActual.getPayloadLength(),is(125));
|
||||
ByteBufferAssert.assertSize("CloseFrame.payload", 125,pActual.getPayload());
|
||||
|
||||
}
|
||||
|
||||
|
@ -297,11 +300,10 @@ public class TestABCase7_3
|
|||
parser.parse(expected);
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(CloseFrame.class,1);
|
||||
capture.assertHasFrame(OpCode.CLOSE,1);
|
||||
|
||||
CloseFrame pActual = (CloseFrame)capture.getFrames().get(0);
|
||||
WebSocketFrame pActual = capture.getFrames().get(0);
|
||||
Assert.assertThat("CloseFrame.payloadLength",pActual.getPayloadLength(),is(messageBytes.length + 2));
|
||||
ByteBufferAssert.assertSize("CloseFrame.payload",messageBytes.length + 2,pActual.getPayload());
|
||||
|
||||
}
|
||||
|
||||
|
@ -321,11 +323,10 @@ public class TestABCase7_3
|
|||
parser.parse(expected);
|
||||
|
||||
capture.assertNoErrors();
|
||||
capture.assertHasFrame(CloseFrame.class,1);
|
||||
capture.assertHasFrame(OpCode.CLOSE,1);
|
||||
|
||||
CloseFrame pActual = (CloseFrame)capture.getFrames().get(0);
|
||||
WebSocketFrame pActual = capture.getFrames().get(0);
|
||||
Assert.assertThat("CloseFrame.payloadLength",pActual.getPayloadLength(),is(0));
|
||||
ByteBufferAssert.assertSize("CloseFrame.payload",0,pActual.getPayload());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
package org.eclipse.jetty.websocket.generator;
|
||||
|
||||
import junit.framework.Assert;
|
||||
|
||||
import org.eclipse.jetty.websocket.frames.CloseFrame;
|
||||
import org.eclipse.jetty.websocket.protocol.OpCode;
|
||||
import org.junit.Test;
|
||||
|
||||
public class CloseFrameGeneratorTest
|
||||
{
|
||||
@Test
|
||||
public void testGenerator() throws Exception
|
||||
{
|
||||
CloseFrame close = new CloseFrame();
|
||||
|
||||
Assert.assertEquals(OpCode.CLOSE,close.getOpCode());
|
||||
}
|
||||
}
|
|
@ -3,12 +3,10 @@ package org.eclipse.jetty.websocket.generator;
|
|||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.eclipse.jetty.util.StringUtil;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.websocket.ByteBufferAssert;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketBehavior;
|
||||
import org.eclipse.jetty.websocket.api.WebSocketPolicy;
|
||||
import org.eclipse.jetty.websocket.frames.PingFrame;
|
||||
import org.eclipse.jetty.websocket.frames.PongFrame;
|
||||
import org.eclipse.jetty.websocket.protocol.FrameBuilder;
|
||||
import org.eclipse.jetty.websocket.protocol.WebSocketFrame;
|
||||
import org.junit.Test;
|
||||
|
@ -54,17 +52,11 @@ public class RFC6455ExamplesGeneratorTest
|
|||
@Test
|
||||
public void testSingleMaskedPongRequest()
|
||||
{
|
||||
PongFrame pong = new PongFrame();
|
||||
pong.setMask(new byte[]
|
||||
{ 0x37, (byte)0xfa, 0x21, 0x3d });
|
||||
|
||||
byte msg[] = "Hello".getBytes(StringUtil.__UTF8_CHARSET);
|
||||
ByteBuffer payload = ByteBuffer.allocate(msg.length);
|
||||
payload.put(msg);
|
||||
pong.setPayload(payload);
|
||||
WebSocketFrame pong = FrameBuilder.pong("Hello").mask(new byte[]
|
||||
{ 0x37, (byte)0xfa, 0x21, 0x3d }).asFrame();
|
||||
|
||||
WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
|
||||
PongFrameGenerator gen = new PongFrameGenerator(policy);
|
||||
Generator gen = new Generator(policy);
|
||||
|
||||
ByteBuffer actual = ByteBuffer.allocate(32);
|
||||
gen.generate(actual,pong);
|
||||
|
@ -118,7 +110,7 @@ public class RFC6455ExamplesGeneratorTest
|
|||
{
|
||||
payload.put((byte)0x44);
|
||||
}
|
||||
binary.setPayload(payload);
|
||||
binary.setPayload(BufferUtil.toArray(payload));
|
||||
|
||||
WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
|
||||
Generator gen = new Generator(policy);
|
||||
|
@ -155,7 +147,7 @@ public class RFC6455ExamplesGeneratorTest
|
|||
{
|
||||
payload.put((byte)0x44);
|
||||
}
|
||||
binary.setPayload(payload);
|
||||
binary.setPayload(BufferUtil.toArray(payload));
|
||||
|
||||
WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
|
||||
Generator gen = new Generator(policy);
|
||||
|
@ -197,16 +189,11 @@ public class RFC6455ExamplesGeneratorTest
|
|||
@Test
|
||||
public void testSingleUnmaskedPingRequest() throws Exception
|
||||
{
|
||||
PingFrame ping = new PingFrame();
|
||||
|
||||
byte msg[] = "Hello".getBytes(StringUtil.__UTF8_CHARSET);
|
||||
ByteBuffer payload = ByteBuffer.allocate(msg.length);
|
||||
payload.put(msg);
|
||||
ping.setPayload(payload);
|
||||
WebSocketFrame ping = FrameBuilder.ping("Hello").asFrame();
|
||||
|
||||
WebSocketPolicy policy = WebSocketPolicy.newServerPolicy();
|
||||
|
||||
PingFrameGenerator gen = new PingFrameGenerator(policy);
|
||||
Generator gen = new Generator(policy);
|
||||
ByteBuffer actual = ByteBuffer.allocate(32);
|
||||
gen.generate(actual,ping);
|
||||
actual.flip(); // make readable
|
||||
|
|
Loading…
Reference in New Issue