Permalink
Browse files

Extended test framework to support python. Added first simple pass/fa…

…il test to exercise framework. Fixed bug in JythonVerticle call to vertx_stop.
  • Loading branch information...
sjhorn committed Jun 12, 2012
1 parent 7158a25 commit 6c57e8e608511686fba0d0a53bc0be13480c13fd
View
@@ -17,4 +17,5 @@ src/examples/java/classes
src/examples/java/quux-out
test-results
test-tmp
-
+*.class
+lib/main/cachedir
@@ -68,7 +68,7 @@ public void start() throws Exception {
public void stop() throws Exception {
try {
- py.exec("vertx_stop");
+ py.exec("vertx_stop()");
} catch (org.python.core.PyException e) {
// OK - method is not mandatory :)
}
@@ -0,0 +1,28 @@
+package org.vertx.java.tests.core.buffer;
+
+import org.vertx.java.framework.TestBase;
+
+/**
+ * @author <a href="https://github.com/sjhorn">Scott Horn</a>
+ */
+public class PythonBufferTest extends TestBase {
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ startApp("core/buffer/test_client.py");
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ }
+
+ public void test_something() {
+ startTest(getMethodName());
+ }
+
+ public void test_another() {
+ startTest(getMethodName());
+ }
+}
@@ -174,7 +174,7 @@ protected String startApp(boolean worker, String main, int instances) throws Exc
protected String startApp(boolean worker, String main, JsonObject config, int instances, boolean await) throws Exception {
URL url;
- if (main.endsWith(".js") || main.endsWith(".rb") || main.endsWith(".groovy")) {
+ if (main.endsWith(".js") || main.endsWith(".rb") || main.endsWith(".groovy") || main.endsWith(".py")) {
url = getClass().getClassLoader().getResource(main);
} else {
String classDir = main.replace('.', '/') + ".class";
@@ -0,0 +1,67 @@
+
+import org.vertx.java.deploy.impl.VertxLocator
+import org.vertx.java.framework
+import org.vertx.java.core.Handler
+import java.lang
+
+class TestUtils(object):
+ def __init__(self):
+ self.java_obj = org.vertx.java.framework.TestUtils(org.vertx.java.deploy.impl.VertxLocator.vertx)
+
+ def azzert(self, result, message=None):
+ try:
+ if message:
+ self.java_obj.azzert(result, message)
+ else:
+ self.java_obj.azzert(result)
+ except java.lang.RuntimeException:
+ # Rethrow as a python exception so we see nice python backtrace
+ if message:
+ raise RuntimeError("Assertion Failed %s"% message)
+ else:
+ raise RuntimeError("Assertion Failed ")
+
+ def app_ready(self):
+ self.java_obj.appReady()
+
+ def app_stopped(self):
+ self.java_obj.appStopped()
+
+ def test_complete(self):
+ self.java_obj.testComplete()
+
+ def register(self, test_name, test_method):
+ self.java_obj.register(test_name, TestHandler(test_method))
+
+ def register_all(self, obj):
+ for meth in dir(obj):
+ if meth.startswith("test_"):
+ self.register(meth, getattr(obj, meth))
+
+ def unregister_all(self):
+ self.java_obj.unregisterAll()
+
+ def check_context(self):
+ return self.java_obj.checkContext()
+
+ @staticmethod
+ def gen_buffer(size):
+ j_buff = org.vertx.java.framework.TestUtils.generateRandomBuffer(size)
+ return Buffer(j_buff)
+
+ @staticmethod
+ def random_unicode_string(self, size):
+ return org.vertx.java.framework.TestUtils.randomUnicodeString(size)
+
+ @staticmethod
+ def buffers_equal(buff1, buff2):
+ return org.vertx.java.framework.TestUtils.buffersEqual(buff1._to_java_buffer(), buff2._to_java_buffer())
+
+class TestHandler(org.vertx.java.core.Handler):
+ """ Test handler """
+ def __init__(self, handler):
+ self.handler = handler
+
+ def handle(self, nothing=None):
+ """ hanlder called by test """
+ self.handler()
@@ -0,0 +1,34 @@
+# Copyright 2011-2012 the original author or authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+import vertx
+from test_utils import TestUtils
+
+tu = TestUtils()
+
+class BufferTest(object):
+ def test_something(self):
+ tu.azzert(True, "Worked")
+ tu.test_complete()
+
+ def test_another(self):
+ tu.azzert(False, "Didnt work")
+ tu.test_complete()
+
+def vertx_stop():
+ tu.unregister_all()
+ tu.app_stopped()
+
+tu.register_all(BufferTest())
+tu.app_ready()

0 comments on commit 6c57e8e

Please sign in to comment.