From 4fed53ce850b9a6db4f505a8a1bf4140ae7d7d39 Mon Sep 17 00:00:00 2001 From: Jesse McConnell Date: Tue, 10 Jul 2012 14:13:09 -0500 Subject: [PATCH] test improvement --- .../jetty/websocket/generator/Generator.java | 7 +++++- .../jetty/websocket/ab/TestABCase1_1.java | 16 +++++++------ .../jetty/websocket/ab/TestABCase1_2.java | 23 ++++++++----------- 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/generator/Generator.java b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/generator/Generator.java index 209c674b084..ab9b5dd5932 100644 --- a/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/generator/Generator.java +++ b/jetty-websocket/websocket-core/src/main/java/org/eclipse/jetty/websocket/generator/Generator.java @@ -145,7 +145,12 @@ public class Generator */ if (frame.getOpCode() == OpCode.CLOSE) { - new CloseInfo(frame.getPayload(),true); + + ByteBuffer payload = frame.getPayload(); + if (payload != null) + { + new CloseInfo(payload,true); + } } } diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/ab/TestABCase1_1.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/ab/TestABCase1_1.java index 3ddf6057f98..10f5f97d00c 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/ab/TestABCase1_1.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/ab/TestABCase1_1.java @@ -11,6 +11,7 @@ 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.OpCode; +import org.eclipse.jetty.websocket.protocol.UnitGenerator; import org.eclipse.jetty.websocket.protocol.WebSocketFrame; import org.junit.Assert; import org.junit.Test; @@ -36,7 +37,7 @@ public class TestABCase1_1 WebSocketFrame textFrame = WebSocketFrame.text(builder.toString()); - Generator generator = new Generator(policy); + Generator generator = new UnitGenerator(); ByteBuffer actual = generator.generate(textFrame); ByteBuffer expected = ByteBuffer.allocate(length + 5); @@ -74,7 +75,7 @@ public class TestABCase1_1 WebSocketFrame textFrame = WebSocketFrame.text(builder.toString()); - Generator generator = new Generator(policy); + Generator generator = new UnitGenerator(); ByteBuffer actual = generator.generate(textFrame); ByteBuffer expected = ByteBuffer.allocate(length + 5); @@ -116,7 +117,7 @@ public class TestABCase1_1 WebSocketFrame textFrame = WebSocketFrame.text(builder.toString()); - Generator generator = new Generator(policy); + Generator generator = new UnitGenerator(); ByteBuffer actual = generator.generate(textFrame); ByteBuffer expected = ByteBuffer.allocate(length + 5); @@ -158,7 +159,7 @@ public class TestABCase1_1 WebSocketFrame textFrame = WebSocketFrame.text(builder.toString()); - Generator generator = new Generator(policy); + Generator generator = new UnitGenerator(); ByteBuffer actual = generator.generate(textFrame); ByteBuffer expected = ByteBuffer.allocate(length + 5); @@ -200,7 +201,8 @@ public class TestABCase1_1 WebSocketFrame textFrame = WebSocketFrame.text(builder.toString()); - Generator generator = new Generator(policy); + Generator generator = new UnitGenerator(); + ByteBuffer actual = generator.generate(textFrame); ByteBuffer expected = ByteBuffer.allocate(length + 5); @@ -240,7 +242,7 @@ public class TestABCase1_1 WebSocketFrame textFrame = WebSocketFrame.text(builder.toString()); - Generator generator = new Generator(policy); + Generator generator = new UnitGenerator(); ByteBuffer actual = generator.generate(textFrame); ByteBuffer expected = ByteBuffer.allocate(length + 11); @@ -271,7 +273,7 @@ public class TestABCase1_1 { WebSocketFrame textFrame = WebSocketFrame.text(""); - Generator generator = new Generator(policy); + Generator generator = new UnitGenerator(); ByteBuffer actual = generator.generate(textFrame); ByteBuffer expected = ByteBuffer.allocate(5); diff --git a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/ab/TestABCase1_2.java b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/ab/TestABCase1_2.java index 12dd4d181e6..045f2566d55 100644 --- a/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/ab/TestABCase1_2.java +++ b/jetty-websocket/websocket-core/src/test/java/org/eclipse/jetty/websocket/ab/TestABCase1_2.java @@ -12,6 +12,7 @@ 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.OpCode; +import org.eclipse.jetty.websocket.protocol.UnitGenerator; import org.eclipse.jetty.websocket.protocol.WebSocketFrame; import org.junit.Assert; import org.junit.Test; @@ -39,7 +40,7 @@ public class TestABCase1_2 WebSocketFrame binaryFrame = WebSocketFrame.binary(BufferUtil.toArray(bb)); - Generator generator = new Generator(policy); + Generator generator = new UnitGenerator(); ByteBuffer actual = generator.generate(binaryFrame); @@ -57,7 +58,7 @@ public class TestABCase1_2 expected.put("*".getBytes()); } - actual.flip(); + // BufferUtil.flipToFlush(actual,0); expected.flip(); ByteBufferAssert.assertEquals("buffers do not match",expected,actual); @@ -80,7 +81,7 @@ public class TestABCase1_2 WebSocketFrame binaryFrame = WebSocketFrame.binary(BufferUtil.toArray(bb)); - Generator generator = new Generator(policy); + Generator generator = new UnitGenerator(); ByteBuffer actual = generator.generate(binaryFrame); ByteBuffer expected = ByteBuffer.allocate(length + 5); @@ -101,7 +102,6 @@ public class TestABCase1_2 expected.put("*".getBytes()); } - actual.flip(); expected.flip(); ByteBufferAssert.assertEquals("buffers do not match",expected,actual); @@ -125,7 +125,7 @@ public class TestABCase1_2 WebSocketFrame binaryFrame = WebSocketFrame.binary(BufferUtil.toArray(bb)); - Generator generator = new Generator(policy); + Generator generator = new UnitGenerator(); ByteBuffer actual = generator.generate(binaryFrame); ByteBuffer expected = ByteBuffer.allocate(length + 5); @@ -146,7 +146,6 @@ public class TestABCase1_2 expected.put("*".getBytes()); } - actual.flip(); expected.flip(); ByteBufferAssert.assertEquals("buffers do not match",expected,actual); @@ -169,7 +168,7 @@ public class TestABCase1_2 bb.flip(); WebSocketFrame binaryFrame = WebSocketFrame.binary(BufferUtil.toArray(bb)); - Generator generator = new Generator(policy); + Generator generator = new UnitGenerator(); ByteBuffer actual = generator.generate(binaryFrame); ByteBuffer expected = ByteBuffer.allocate(length + 5); @@ -190,7 +189,6 @@ public class TestABCase1_2 expected.put("*".getBytes()); } - actual.flip(); expected.flip(); ByteBufferAssert.assertEquals("buffers do not match",expected,actual); @@ -214,7 +212,7 @@ public class TestABCase1_2 WebSocketFrame binaryFrame = WebSocketFrame.binary(BufferUtil.toArray(bb)); - Generator generator = new Generator(policy); + Generator generator = new UnitGenerator(); ByteBuffer actual = generator.generate(binaryFrame); ByteBuffer expected = ByteBuffer.allocate(length + 5); @@ -232,7 +230,6 @@ public class TestABCase1_2 expected.put("*".getBytes()); } - actual.flip(); expected.flip(); ByteBufferAssert.assertEquals("buffers do not match",expected,actual); @@ -256,7 +253,7 @@ public class TestABCase1_2 WebSocketFrame binaryFrame = WebSocketFrame.binary(BufferUtil.toArray(bb)); - Generator generator = new Generator(policy); + Generator generator = new UnitGenerator(); ByteBuffer actual = generator.generate(binaryFrame); ByteBuffer expected = ByteBuffer.allocate(length + 11); @@ -275,7 +272,6 @@ public class TestABCase1_2 expected.put("*".getBytes()); } - actual.flip(); expected.flip(); ByteBufferAssert.assertEquals("buffers do not match",expected,actual); @@ -287,7 +283,7 @@ public class TestABCase1_2 { WebSocketFrame binaryFrame = WebSocketFrame.binary(new byte[] {}); - Generator generator = new Generator(policy); + Generator generator = new UnitGenerator(); ByteBuffer actual = generator.generate(binaryFrame); ByteBuffer expected = ByteBuffer.allocate(5); @@ -295,7 +291,6 @@ public class TestABCase1_2 expected.put(new byte[] { (byte)0x82, (byte)0x00 }); - actual.flip(); expected.flip(); ByteBufferAssert.assertEquals("buffers do not match",expected,actual);