MySQLStringBinlogProtocolValue implements MySQLBinlogProtocolValue { @Override public Serializable read(final MySQLBinlogColumnDef columnDef, final MySQLPacketPayload payload) { switch (MySQLColumnType.valueOf(columnDef.getColumnMeta() >> 8)) { case MYSQL_TYPE_ENUM: return readEnumValue(columnDef.getColumnMeta() & 0xff, payload); case MYSQL_TYPE_SET: return payload.getByteBuf().readByte(); case MYSQL_TYPE_STRING: return payload.readStringFix(payload.getByteBuf().readUnsignedByte()); default: throw new UnsupportedOperationException(""); } }  @Override Serializable read(final MySQLBinlogColumnDef columnDef, final MySQLPacketPayload payload);  }
@Test public void assertReadEnumValueWithMeta1() { columnDef.setColumnMeta((MySQLColumnType.MYSQL_TYPE_ENUM.getValue() << 8) + 1); when(payload.readInt1()).thenReturn(1); assertThat(new MySQLStringBinlogProtocolValue().read(columnDef, payload), is(1)); }
@Test public void assertReadEnumValueWithMeta2() { columnDef.setColumnMeta((MySQLColumnType.MYSQL_TYPE_ENUM.getValue() << 8) + 2); when(payload.readInt2()).thenReturn(32767); assertThat(new MySQLStringBinlogProtocolValue().read(columnDef, payload), is(32767)); }
@Test(expected = UnsupportedOperationException.class) public void assertReadEnumValueWithMetaFailure() { columnDef.setColumnMeta((MySQLColumnType.MYSQL_TYPE_ENUM.getValue() << 8) + 3); new MySQLStringBinlogProtocolValue().read(columnDef, payload); }
@Test public void assertReadSetValue() { columnDef.setColumnMeta(MySQLColumnType.MYSQL_TYPE_SET.getValue() << 8); when(payload.getByteBuf()).thenReturn(byteBuf); when(byteBuf.readByte()).thenReturn((byte) 0xff); assertThat(new MySQLStringBinlogProtocolValue().read(columnDef, payload), is((byte) 0xff)); }
@Test public void assertReadStringValue() { String expected = "test_value"; columnDef.setColumnMeta(MySQLColumnType.MYSQL_TYPE_STRING.getValue() << 8); when(payload.getByteBuf()).thenReturn(byteBuf); when(byteBuf.readUnsignedByte()).thenReturn((short) expected.length()); when(payload.readStringFix(expected.length())).thenReturn(expected); assertThat(new MySQLStringBinlogProtocolValue().read(columnDef, payload), is(expected)); }
@Test(expected = UnsupportedOperationException.class) public void assertReadValueWithUnknownType() { columnDef.setColumnMeta(MySQLColumnType.MYSQL_TYPE_VAR_STRING.getValue() << 8); new MySQLStringBinlogProtocolValue().read(columnDef, payload); }