Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Unit tests around rexpro messages.

  • Loading branch information...
commit 3fa045d375cf3f8be62244e3c7a6f6185892b9cf 1 parent c7dd37f
@spmallette spmallette authored
View
4 rexster-console/src/main/java/com/tinkerpop/rexster/console/RexsterConsole.java
@@ -298,8 +298,8 @@ private static ResultAndBindings eval(final String script, final String scriptEn
if (resultMessage instanceof ConsoleScriptResponseMessage) {
final ConsoleScriptResponseMessage responseMessage = (ConsoleScriptResponseMessage) resultMessage;
- bindings = responseMessage.BindingsAsList();
- lines = responseMessage.ConsoleLinesAsList();
+ bindings = responseMessage.bindingsAsList();
+ lines = responseMessage.consoleLinesAsList();
} else if (resultMessage instanceof ErrorResponseMessage) {
final ErrorResponseMessage errorMessage = (ErrorResponseMessage) resultMessage;
lines = new ArrayList() {{
View
6 ...otocol/src/main/java/com/tinkerpop/rexster/protocol/msg/ConsoleScriptResponseMessage.java
@@ -24,8 +24,8 @@
public String[] ConsoleLines;
public byte[] Bindings;
- public List<String> ConsoleLinesAsList() {
- List<String> list = new ArrayList<String>();
+ public List<String> consoleLinesAsList() {
+ final List<String> list = new ArrayList<String>();
for (String line : ConsoleLines) {
list.add(line);
}
@@ -33,7 +33,7 @@
return list;
}
- public List<String> BindingsAsList() {
+ public List<String> bindingsAsList() {
final List<String> bindings = new ArrayList<String>();
final ByteBuffer bb = ByteBuffer.wrap(this.Bindings);
View
2  rexster-protocol/src/main/java/com/tinkerpop/rexster/protocol/msg/MessageUtil.java
@@ -1,7 +1,5 @@
package com.tinkerpop.rexster.protocol.msg;
-import com.tinkerpop.rexster.protocol.RexProSessions;
-
import java.util.List;
import java.util.UUID;
View
61 ...ol/src/test/java/com/tinkerpop/rexster/protocol/msg/ConsoleScriptResponseMessageTest.java
@@ -0,0 +1,61 @@
+package com.tinkerpop.rexster.protocol.msg;
+
+import junit.framework.Assert;
+import org.junit.Test;
+
+import javax.script.Bindings;
+import javax.script.SimpleBindings;
+import java.io.IOError;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class ConsoleScriptResponseMessageTest {
+
+ @Test
+ public void consoleLinesAsListValid() {
+ final ConsoleScriptResponseMessage msg = new ConsoleScriptResponseMessage();
+ msg.ConsoleLines = new String[] { "a", "b", "c" };
+
+ final List<String> lines = msg.consoleLinesAsList();
+ Assert.assertEquals(3, lines.size());
+ Assert.assertEquals("a", lines.get(0));
+ Assert.assertEquals("b", lines.get(1));
+ Assert.assertEquals("c", lines.get(2));
+ }
+
+ @Test
+ public void bindingsAsListValid() throws IOException {
+ final ConsoleScriptResponseMessage msg = new ConsoleScriptResponseMessage();
+ final Bindings b = new SimpleBindings();
+ b.put("a", "aaa");
+ b.put("b", "bbb");
+ b.put("c", 3);
+
+ msg.Bindings = ConsoleScriptResponseMessage.convertBindingsToByteArray(b);
+
+ final List<String> bindingsList = msg.bindingsAsList();
+ Assert.assertEquals(3, bindingsList.size());
+ Assert.assertEquals("a=aaa", bindingsList.get(2));
+ Assert.assertEquals("b=bbb", bindingsList.get(0));
+ Assert.assertEquals("c=3", bindingsList.get(1));
+ }
+
+ @Test
+ public void estimateMessageSize() throws IOException {
+ final ConsoleScriptResponseMessage msg = new ConsoleScriptResponseMessage();
+ msg.ConsoleLines = new String[] { "a", "b", "c" };
+
+ final Bindings b = new SimpleBindings();
+ b.put("a", "aaa");
+ b.put("b", "bbb");
+ b.put("c", 3);
+
+ msg.Bindings = ConsoleScriptResponseMessage.convertBindingsToByteArray(b);
+
+ Assert.assertEquals(64, msg.estimateMessageSize());
+ }
+}
View
18 ...r-protocol/src/test/java/com/tinkerpop/rexster/protocol/msg/ErrorResponseMessageTest.java
@@ -0,0 +1,18 @@
+package com.tinkerpop.rexster.protocol.msg;
+
+import junit.framework.Assert;
+import org.junit.Test;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class ErrorResponseMessageTest {
+
+ @Test
+ public void estimateMessageSize(){
+ final ErrorResponseMessage msg = new ErrorResponseMessage();
+ msg.ErrorMessage = "this was an error";
+
+ Assert.assertEquals(53, msg.estimateMessageSize());
+ }
+}
View
18 ...l/src/test/java/com/tinkerpop/rexster/protocol/msg/GraphSONScriptResponseMessageTest.java
@@ -0,0 +1,18 @@
+package com.tinkerpop.rexster.protocol.msg;
+
+import junit.framework.Assert;
+import org.junit.Test;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class GraphSONScriptResponseMessageTest {
+ @Test
+ public void estimateMessageSize() {
+ final GraphSONScriptResponseMessage msg = new GraphSONScriptResponseMessage();
+ msg.Results = new byte[10];
+ msg.Bindings = new byte[10];
+
+ Assert.assertEquals(56, msg.estimateMessageSize());
+ }
+}
View
53 rexster-protocol/src/test/java/com/tinkerpop/rexster/protocol/msg/MessageUtilTest.java
@@ -0,0 +1,53 @@
+package com.tinkerpop.rexster.protocol.msg;
+
+import com.tinkerpop.rexster.protocol.BitWorks;
+import junit.framework.Assert;
+import org.junit.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class MessageUtilTest {
+ @Test
+ public void createErrorResponse() {
+ byte [] request = "request".getBytes();
+ byte [] session = "session".getBytes();
+ final ErrorResponseMessage msg = MessageUtil.createErrorResponse(request, session,
+ MessageFlag.ERROR_AUTHENTICATION_FAILURE, "error message");
+
+ Assert.assertNotNull(msg);
+ Assert.assertEquals(request, msg.Request);
+ Assert.assertEquals(session, msg.Session);
+ Assert.assertEquals("error message", msg.ErrorMessage);
+ Assert.assertEquals(MessageFlag.ERROR_AUTHENTICATION_FAILURE, msg.Flag);
+ }
+
+ @Test
+ public void createNewSession() {
+ byte [] request = "request".getBytes();
+ final SessionResponseMessage msg = MessageUtil.createNewSession(request, new ArrayList<String>() {{ add("groovy"); }});
+
+ Assert.assertNotNull(msg);
+ Assert.assertEquals(request, msg.Request);
+ Assert.assertEquals(MessageFlag.SESSION_RESPONSE_NO_FLAG, msg.Flag);
+ Assert.assertEquals("groovy", msg.Languages[0]);
+
+ final SessionResponseMessage newMsg = MessageUtil.createNewSession(request, new ArrayList<String>() {{ add("groovy"); }});
+ Assert.assertFalse(Arrays.equals(newMsg.Session, msg.Session));
+ }
+
+ @Test
+ public void createEmptySession() {
+ byte [] request = "request".getBytes();
+ final SessionResponseMessage msg = MessageUtil.createEmptySession(request);
+
+ Assert.assertNotNull(msg);
+ Assert.assertEquals(request, msg.Request);
+ Assert.assertEquals(MessageFlag.SESSION_RESPONSE_NO_FLAG, msg.Flag);
+ Assert.assertEquals(0, msg.Languages.length);
+ Assert.assertTrue(Arrays.equals(BitWorks.convertUUIDToByteArray(RexProMessage.EMPTY_SESSION), msg.Session));
+ }
+}
View
18 ...ol/src/test/java/com/tinkerpop/rexster/protocol/msg/MsgPackScriptResponseMessageTest.java
@@ -0,0 +1,18 @@
+package com.tinkerpop.rexster.protocol.msg;
+
+import junit.framework.Assert;
+import org.junit.Test;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class MsgPackScriptResponseMessageTest {
+ @Test
+ public void estimateMessageSize() {
+ final MsgPackScriptResponseMessage msg = new MsgPackScriptResponseMessage();
+ msg.Results = new byte[10];
+ msg.Bindings = new byte[10];
+
+ Assert.assertEquals(56, msg.estimateMessageSize());
+ }
+}
View
20 ...r-protocol/src/test/java/com/tinkerpop/rexster/protocol/msg/ScriptRequestMessageTest.java
@@ -0,0 +1,20 @@
+package com.tinkerpop.rexster.protocol.msg;
+
+import junit.framework.Assert;
+import org.junit.Test;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class ScriptRequestMessageTest {
+
+ @Test
+ public void estimateMessageSize() {
+ final ScriptRequestMessage msg = new ScriptRequestMessage();
+ msg.Bindings = new byte[10];
+ msg.LanguageName = "groovy";
+ msg.Script = "script";
+
+ Assert.assertEquals(58, msg.estimateMessageSize());
+ }
+}
View
19 ...-protocol/src/test/java/com/tinkerpop/rexster/protocol/msg/SessionRequestMessageTest.java
@@ -0,0 +1,19 @@
+package com.tinkerpop.rexster.protocol.msg;
+
+import junit.framework.Assert;
+import org.junit.Test;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class SessionRequestMessageTest {
+ @Test
+ public void estimateMessageSize() {
+ final SessionRequestMessage msg = new SessionRequestMessage();
+ msg.Channel = SessionRequestMessage.CHANNEL_CONSOLE;
+ msg.Username = "user";
+ msg.Password = "pass";
+
+ Assert.assertEquals(45, msg.estimateMessageSize());
+ }
+}
View
17 ...protocol/src/test/java/com/tinkerpop/rexster/protocol/msg/SessionResponseMessageTest.java
@@ -0,0 +1,17 @@
+package com.tinkerpop.rexster.protocol.msg;
+
+import junit.framework.Assert;
+import org.junit.Test;
+
+/**
+ * @author Stephen Mallette (http://stephen.genoprime.com)
+ */
+public class SessionResponseMessageTest {
+ @Test
+ public void estimateMessageSize() {
+ final SessionResponseMessage msg = new SessionResponseMessage();
+ msg.Languages = new String[]{"groovy"};
+
+ Assert.assertEquals(42, msg.estimateMessageSize());
+ }
+}
Please sign in to comment.
Something went wrong with that request. Please try again.