/**
* Tests that requests to create and destroy sessions work as expected
*/
@Test
public void testSessionRequestAndResponse() throws Exception {
final RexsterClient client = getClient();
//create a session
final SessionRequestMessage outMsg = new SessionRequestMessage();
outMsg.setRequestAsUUID(UUID.randomUUID());
RexProMessage inMsg = client.execute(outMsg);
Assert.assertNotNull(inMsg.Session);
Assert.assertTrue(inMsg instanceof SessionResponseMessage);
UUID sessionKey = BitWorks.convertByteArrayToUUID(inMsg.Session);
//kill said session
final SessionRequestMessage deathMsg = new SessionRequestMessage();
deathMsg.Session = BitWorks.convertUUIDToByteArray(sessionKey);
deathMsg.setRequestAsUUID(UUID.randomUUID());
deathMsg.metaSetKillSession(true);
inMsg = client.execute(deathMsg);
Assert.assertNotNull(inMsg.Session);
Assert.assertTrue(inMsg instanceof SessionResponseMessage);
//try to use the killed session
final ScriptRequestMessage scriptMessage = new ScriptRequestMessage();
scriptMessage.Script = "5";
scriptMessage.LanguageName = "groovy";
scriptMessage.metaSetInSession(true);
scriptMessage.setRequestAsUUID(UUID.randomUUID());
scriptMessage.Session = BitWorks.convertUUIDToByteArray(sessionKey);
inMsg = client.execute(scriptMessage);
Assert.assertTrue(inMsg instanceof ErrorResponseMessage);
Assert.assertEquals(((ErrorResponseMessage) inMsg).metaGetFlag(), ErrorResponseMessage.INVALID_SESSION_ERROR);
}