use of com.stanfy.enroscar.rest.response.handler.StringContentHandler in project enroscar by stanfy.
the class ContentHandlerTest method gotErrorShourldReadErrorStream.
@Test
public void gotErrorShourldReadErrorStream() throws Exception {
assertThat(ResponseCache.getDefault()).isNull();
scheduleBadMethodResponse();
URLConnection connection = makeConnection(new MyRequestBuilder<String>(Robolectric.application) {
}.setUrl(getWebServer().getUrl("/error").toString()).setOperationType(OperationType.SIMPLE_GET));
boolean failed = false;
try {
read(connection);
} catch (final IOException e) {
failed = true;
}
getWebServer().takeRequest();
assertThat(failed).isTrue();
final String expected = scheduleBadMethodResponse();
// send request once more
connection = makeConnection(new MyRequestBuilder<String>(Robolectric.application) {
{
setRequestContentHandler(StringContentHandler.BEAN_NAME);
}
}.setUrl(getWebServer().getUrl("/error").toString()).setOperationType(OperationType.SIMPLE_GET));
final StringContentHandler contentHandler = BeansManager.get(getApplication()).getContainer().getBean(StringContentHandler.BEAN_NAME, StringContentHandler.class);
// we should test base behavior
assertThat(contentHandler).isInstanceOf(BaseContentHandler.class);
final String response = (String) contentHandler.getContent(connection);
getWebServer().takeRequest();
final HttpURLConnection http = (HttpURLConnection) UrlConnectionWrapper.unwrap(connection);
assertThat(http.getResponseCode()).isEqualTo(HttpURLConnection.HTTP_BAD_METHOD);
assertThat(response).isEqualTo(expected);
}
use of com.stanfy.enroscar.rest.response.handler.StringContentHandler in project enroscar by stanfy.
the class RemoteServerApiConfigurationTest method configureBean.
@Before
public void configureBean() {
BeansManager manager = BeansManager.get(Robolectric.application);
manager.edit().put("defaultCacheBeanName", new DummyResponseCache()).put("defaultContentHandlerName", new StringContentHandler(Robolectric.application)).put(RemoteServerApiConfiguration.class).commit();
RemoteServerApiConfiguration config = manager.getContainer().getBean(RemoteServerApiConfiguration.class);
config.setDefaultCacheBeanName("defaultCacheBeanName");
config.setDefaultContentHandlerName("defaultContentHandlerName");
}
Aggregations