* Test of {@link ErrorMessageFactory} for correct translation into POJO
*/
@Test
- public void test() {
- ByteBuf bb = BufferHelper.buildBuffer("00 04 00 03 01 02 03 04");
- ErrorMessage builtByFactory = BufferHelper.decodeV13(ErrorMessageFactory.getInstance(), bb);
+ public void testWithoutData() {
+ ByteBuf bb = BufferHelper.buildBuffer("00 01 00 02");
+ ErrorMessage builtByFactory = BufferHelper.decodeV13(
+ ErrorMessageFactory.getInstance(), bb);
+
+ BufferHelper.checkHeaderV13(builtByFactory);
+ Assert.assertEquals("Wrong type", 1, builtByFactory.getType().intValue());
+ Assert.assertEquals("Wrong code", 2, builtByFactory.getCode().intValue());
+ Assert.assertEquals("Wrong type string", "BADREQUEST", builtByFactory.getTypeString());
+ Assert.assertEquals("Wrong code string", "BADMULTIPART", builtByFactory.getCodeString());
+ Assert.assertNull("Data is not null", builtByFactory.getData());
+ }
+
+ /**
+ * Test of {@link ErrorMessageFactory} for correct translation into POJO
+ */
+ @Test
+ public void testWithData() {
+ ByteBuf bb = BufferHelper.buildBuffer("00 00 00 01 00 01 02 03");
+ ErrorMessage builtByFactory = BufferHelper.decodeV13(
+ ErrorMessageFactory.getInstance(), bb);
+
+ BufferHelper.checkHeaderV13(builtByFactory);
+ Assert.assertEquals("Wrong type", 0, builtByFactory.getType().intValue());
+ Assert.assertEquals("Wrong code", 1, builtByFactory.getCode().intValue());
+ Assert.assertEquals("Wrong type string", "HELLOFAILED", builtByFactory.getTypeString());
+ Assert.assertEquals("Wrong code string", "EPERM", builtByFactory.getCodeString());
+ Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x01, 0x02, 0x03}, builtByFactory.getData());
+ }
+
+ /**
+ * Test of {@link ErrorMessageFactory} for correct translation into POJO
+ */
+ @Test
+ public void testWithIncorrectTypeEnum() {
+ ByteBuf bb = BufferHelper.buildBuffer("00 20 00 05 00 01 02 03");
+ ErrorMessage builtByFactory = BufferHelper.decodeV13(
+ ErrorMessageFactory.getInstance(), bb);
+
+ BufferHelper.checkHeaderV13(builtByFactory);
+ Assert.assertEquals("Wrong type", 32, builtByFactory.getType().intValue());
+ Assert.assertEquals("Wrong code", 5, builtByFactory.getCode().intValue());
+ Assert.assertEquals("Wrong type string", "UNKNOWN_TYPE", builtByFactory.getTypeString());
+ Assert.assertEquals("Wrong code string", "UNKNOWN_CODE", builtByFactory.getCodeString());
+ Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x01, 0x02, 0x03}, builtByFactory.getData());
+ }
+
+ /**
+ * Test of {@link ErrorMessageFactory} for correct translation into POJO
+ */
+ @Test
+ public void testWithIncorrectCodeEnum() {
+ ByteBuf bb = BufferHelper.buildBuffer("00 03 00 10 00 01 02 03");
+ ErrorMessage builtByFactory = BufferHelper.decodeV13(
+ ErrorMessageFactory.getInstance(), bb);
+
BufferHelper.checkHeaderV13(builtByFactory);
-
- Assert.assertEquals("Wrong type", 4, builtByFactory.getType().intValue());
- Assert.assertEquals("Wrong code", 3, builtByFactory.getCode().intValue());
- Assert.assertEquals("Wrong type", "BADMATCH", builtByFactory.getTypeString());
- Assert.assertEquals("Wrong code", "BADDLADDRMASK", builtByFactory.getCodeString());
- Assert.assertArrayEquals("Wrong body", new byte[]{0x01, 0x02, 0x03, 0x04}, builtByFactory.getData());
+ Assert.assertEquals("Wrong type", 3, builtByFactory.getType().intValue());
+ Assert.assertEquals("Wrong code", 16, builtByFactory.getCode().intValue());
+ Assert.assertEquals("Wrong type string", "BADINSTRUCTION", builtByFactory.getTypeString());
+ Assert.assertEquals("Wrong code string", "UNKNOWN_CODE", builtByFactory.getCodeString());
+ Assert.assertArrayEquals("Wrong data", new byte[]{0x00, 0x01, 0x02, 0x03}, builtByFactory.getData());
}
}