1

Could someone explain why this httpunit test case keeps failing in wc.getResponse with "bad file descriptor". I added the is.close() as a guess and moved it before and after the failure but that had no effect. This tests put requests to a Dropwizard app.

    public class TestCircuitRequests
{
    static WebConversation wc = new WebConversation();
    static String url = "http://localhost:8888/funl/circuit/test.circuit1";

@Test
public void testPut() throws Exception
{
    InputStream is = new FileInputStream("src/test/resources/TestCircuit.json");
    WebRequest rq = new PutMethodWebRequest(url, is, "application/json");

    wc.setAuthentication("FUNL", "foo", "bar");
    WebResponse response = wc.getResponse(rq);
    is.close();
}
Bradjcox
  • 1,509
  • 1
  • 18
  • 30
  • And what does "bad file descriptor" mean in this context anyway? – Bradjcox Oct 04 '12 at 10:49
  • you might want to check the httpunit developer FAQ to see that the 1.7.2 release is in the works. Please check rev1099 https://sourceforge.net/mailarchive/forum.php?thread_name=5051BBF6.70700%40bitplan.com&forum_name=httpunit-develop – Wolfgang Fahl Oct 15 '12 at 23:01

1 Answers1

0

No responses? So I'll try myself based on what I learned fighting this.

Httpunit is an old familiar tool that I'd use if I could. But it hasn't been updated in more than two years, so I gather its support for @PUT requests isn't right.

So I converted to Jersey-client instead. After a bunch of struggling I wound up with this code which does seem to work:

    @Test
public void testPut() throws Exception
{
    InputStream is = new FileInputStream("src/test/resources/TestCircuit.json");
    String circuit = StreamUtil.readFully(is);
    is.close();

    Authenticator.setDefault(new MyAuthenticator());
    ClientConfig config = new DefaultClientConfig();
    Client client = Client.create(config);
    com.sun.jersey.api.client.WebResource service = client.resource(url);

    Builder builder = service.accept(MediaType.APPLICATION_JSON);
    builder.entity(circuit, MediaType.APPLICATION_JSON);
    builder.put(String.class, circuit);
    return;
}

This intentionally avoids JAX-RS automatic construction of beans from JSON strings.

Bradjcox
  • 1,509
  • 1
  • 18
  • 30
  • Why would you want to intentionally avoid using Jackson etc from marshalling your entity? Having Jackson work on the InputStream reduces errors in your fixtures. – Gary Dec 20 '12 at 09:17