MySQLHandshakePacket implements MySQLPacket { @Override public int getSequenceId() { return 0; } MySQLHandshakePacket(final int connectionId, final MySQLAuthPluginData authPluginData);  MySQLHandshakePacket(final MySQLPacketPayload payload); void setAuthPluginName(final MySQLAuthenticationMethod mysqlAuthenticationMethod); @Override void write(final MySQLPacketPayload payload); @Override int getSequenceId();  }
@Test public void assertNewWithPayload() { when(payload.readInt1()).thenReturn(0, MySQLServerInfo.PROTOCOL_VERSION, MySQLServerInfo.CHARSET, 0); when(payload.readStringNul()).thenReturn(MySQLServerInfo.getServerVersion()); when(payload.readStringNulByBytes()).thenReturn(part1, part2); when(payload.readInt4()).thenReturn(1000); when(payload.readInt2()).thenReturn( MySQLCapabilityFlag.calculateHandshakeCapabilityFlagsLower(), MySQLStatusFlag.SERVER_STATUS_AUTOCOMMIT.getValue(), MySQLCapabilityFlag.calculateHandshakeCapabilityFlagsUpper()); MySQLHandshakePacket actual = new MySQLHandshakePacket(payload); assertThat(actual.getSequenceId(), is(0)); assertThat(actual.getServerVersion(), is(MySQLServerInfo.getServerVersion())); assertThat(actual.getCapabilityFlagsLower(), is(MySQLCapabilityFlag.calculateHandshakeCapabilityFlagsLower())); assertThat(actual.getConnectionId(), is(1000)); assertThat(actual.getCharacterSet(), is(MySQLServerInfo.CHARSET)); assertThat(actual.getStatusFlag(), is(MySQLStatusFlag.SERVER_STATUS_AUTOCOMMIT)); assertThat(actual.getCapabilityFlagsUpper(), is(MySQLCapabilityFlag.calculateHandshakeCapabilityFlagsUpper())); assertThat(actual.getAuthPluginData().getAuthPluginDataPart1(), is(part1)); assertThat(actual.getAuthPluginData().getAuthPluginDataPart2(), is(part2)); verify(payload).skipReserved(10); }
@Test public void assertNewWithClientPluginAuthPayload() { when(payload.readInt1()).thenReturn(0, MySQLServerInfo.PROTOCOL_VERSION, MySQLServerInfo.CHARSET, 0); when(payload.readStringNul()).thenReturn(MySQLServerInfo.getServerVersion(), MySQLAuthenticationMethod.SECURE_PASSWORD_AUTHENTICATION.getMethodName()); when(payload.readStringNulByBytes()).thenReturn(part1, part2); when(payload.readInt4()).thenReturn(1000); when(payload.readInt2()).thenReturn( MySQLCapabilityFlag.calculateHandshakeCapabilityFlagsLower(), MySQLStatusFlag.SERVER_STATUS_AUTOCOMMIT.getValue(), MySQLCapabilityFlag.CLIENT_PLUGIN_AUTH.getValue() >> 16); MySQLHandshakePacket actual = new MySQLHandshakePacket(payload); assertThat(actual.getSequenceId(), is(0)); assertThat(actual.getServerVersion(), is(MySQLServerInfo.getServerVersion())); assertThat(actual.getCapabilityFlagsLower(), is(MySQLCapabilityFlag.calculateHandshakeCapabilityFlagsLower())); assertThat(actual.getConnectionId(), is(1000)); assertThat(actual.getCharacterSet(), is(MySQLServerInfo.CHARSET)); assertThat(actual.getStatusFlag(), is(MySQLStatusFlag.SERVER_STATUS_AUTOCOMMIT)); assertThat(actual.getCapabilityFlagsUpper(), is(MySQLCapabilityFlag.CLIENT_PLUGIN_AUTH.getValue() >> 16)); assertThat(actual.getAuthPluginData().getAuthPluginDataPart1(), is(part1)); assertThat(actual.getAuthPluginData().getAuthPluginDataPart2(), is(part2)); verify(payload).skipReserved(10); assertThat(actual.getAuthPluginName(), is(MySQLAuthenticationMethod.SECURE_PASSWORD_AUTHENTICATION.getMethodName())); }