2012-10-04 4 views
1

누군가이 httpunit 테스트 사례가 "잘못된 파일 설명자"가있는 wc.getResponse에서 계속 실패하는 이유를 설명해 줄 수 있습니까? 추측으로 is.close()를 추가하고 실패 전후로 이동했지만 아무런 효과가 없었습니다. 이 테스트는 Dropwizard 앱에 요청을 보냅니다.httpunit PutMethodWebRequest가 IOException을 throw합니다. 잘못된 파일 설명자

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(); 
} 
+0

그리고이 컨텍스트에서 "잘못된 파일 설명자"는 무엇을 의미합니까? – Bradjcox

+0

httpunit 개발자 FAQ 을 확인하여 1.7.2 릴리스가 작동하는지 확인하는 것이 좋습니다. rev1099를 확인하십시오 https://sourceforge.net/mailarchive/forum.php?thread_name=5051BBF6.70700%40bitplan.com&forum_name=httpunit-develop –

답변

0

응답이 없습니까? 그래서 나는 이것을 배웠던 것에 기초하여 나 자신을 시험 할 것입니다.

Httpunit은 내가 할 수있는 한 내가 사용하는 오래된 익숙한 도구입니다. 그러나 그것은 2 년이 넘게 업데이트되지 않았으므로 @PUT 요청에 대한 지원을 수집합니다.

그래서 Jersey-client로 변환되었습니다.

@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; 
} 

이 의도적으로 JAX-RS를 JSON 문자열에서 콩의 자동 구성을 피할 수 : 투쟁의 무리 후에 나는 일을 보인다 코드와 상처.

+0

왜 당신이 의도적으로 귀하의 엔티티를 마샬링에서 잭슨 등을 사용하지 않으시겠습니까? InputStream에서 Jackson의 작업을하면 조명기의 오류를 줄일 수 있습니다. –

관련 문제