jabsorb
Java to JavaScript Object Request Broker

I'm a testing newbie who's been using JSON-RPC-Java for a while (and is intending to move to Jabsorb), trying out some of the ideas described in Johannes Link's book "Unit Testing in Java-- How Tests Drive the Code", a book on the test first approach to development, i.e. write a test, write code to pass it, write another test, etc.


public class SomeClassTest extends TestCase
{
        private Client jabsorb;
        private Object sc;

public SomeClassTest() throws URISyntaxException
{
        // Create Jabsorb Java client
        jabsorb=new Client(new HTTPSession(new URI("http://myhost:8080/MyWebApp/JSON-RPC")));
}


public void testConnect() throws Exception
{
try 
{
jabsorb.invoke(sc, ISomeClass.class.getMethod("connect", connectParamTypes), 
                                connectParams);
fail("exception expected");
}
catch(Exception e){ /* expected */ }
}
}

protected void setUp() throws URISyntaxException, JSONException, MalformedURLException, IOException, ProtocolException
        {
                // Load object test reset JSP page
                URL url = new URL("http://myhost:8080/MyWebApp/TestResetSomeObject.jsp");
                HttpURLConnection testReset = (HttpURLConnection) url.openConnection();
                testReset.setRequestMethod("GET");
                testReset.connect();
                
// Get the returned document; 
                InputStream wis = testReset.getInputStream();
                byte[] bbuf=new byte[512];
                while(wis.read(bbuf) != -1);
                wis.close();
                sc=jabsorb.openProxy("sc", ISomeClass.class);
        }
        protected void tearDown() 
        {
                jabsorb.closeProxy(sc);
        }
}

TODO: Add ISomeClass

<?xml version="1.0" encoding="UTF-8" ?>
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
<jsp:directive.page import="org.jabsorb.JSONRPCBridge"/>
    <jsp:directive.page session="true" language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" />
    <jsp:text>
        <![CDATA[ <?xml version="1.0" encoding="UTF-8" ?> ]]>
    </jsp:text>
    <jsp:text>
        <![CDATA[ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> ]]>
    </jsp:text>
        <jsp:useBean id="sc" scope="request" class="org.example.SomeClass" /> 
    <jsp:scriptlet>
                
                JSONRPCBridge jrb=JSONRPCBridge.getGlobalBridge();
                if(jrb.lookupObject("sc") != null)
                        jrb.unregisterObject("sc");
                jrb.registerObject("sc", sc);
        </jsp:scriptlet>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>
                Unit test experiments
        </title>
</head>
<body>
Page loaded OK.
</body>
</html>
</jsp:root>