use of org.odk.collect.android.openrosa.OpenRosaFormSource in project collect by opendatakit.
the class OpenRosaFormSourceTest method fetchManifest_whenThereIsAnUnknownHostException_throwsUnreachableFormApiException.
@Test
public void fetchManifest_whenThereIsAnUnknownHostException_throwsUnreachableFormApiException() throws Exception {
OpenRosaFormSource formListApi = new OpenRosaFormSource("http://blah.com", httpInterface, webCredentialsUtils, responseParser);
try {
when(httpInterface.executeGetRequest(any(), any(), any())).thenThrow(UnknownHostException.class);
formListApi.fetchManifest("http://blah.com/manifest");
fail("No exception thrown!");
} catch (FormSourceException.Unreachable e) {
assertThat(e.getServerUrl(), is("http://blah.com"));
}
}
use of org.odk.collect.android.openrosa.OpenRosaFormSource in project collect by opendatakit.
the class OpenRosaFormSourceTest method fetchForm_whenThereIsAServerError_throwsServerError.
@Test
public void fetchForm_whenThereIsAServerError_throwsServerError() throws Exception {
OpenRosaFormSource formListApi = new OpenRosaFormSource("http://blah.com", httpInterface, webCredentialsUtils, responseParser);
try {
when(httpInterface.executeGetRequest(any(), any(), any())).thenReturn(new HttpGetResult(null, new HashMap<>(), "hash", 500));
formListApi.fetchForm("http://blah.com/form");
fail("No exception thrown!");
} catch (FormSourceException.ServerError e) {
assertThat(e.getStatusCode(), is(500));
assertThat(e.getServerUrl(), is("http://blah.com"));
}
}
use of org.odk.collect.android.openrosa.OpenRosaFormSource in project collect by opendatakit.
the class OpenRosaFormSourceTest method fetchFormList_whenThereIsAnUnknownHostException_throwsUnreachableFormApiException.
@Test
public void fetchFormList_whenThereIsAnUnknownHostException_throwsUnreachableFormApiException() throws Exception {
OpenRosaFormSource formListApi = new OpenRosaFormSource("http://blah.com", httpInterface, webCredentialsUtils, responseParser);
try {
when(httpInterface.executeGetRequest(any(), any(), any())).thenThrow(UnknownHostException.class);
formListApi.fetchFormList();
fail("No exception thrown!");
} catch (FormSourceException.Unreachable e) {
assertThat(e.getServerUrl(), is("http://blah.com"));
}
}
use of org.odk.collect.android.openrosa.OpenRosaFormSource in project collect by opendatakit.
the class OpenRosaFormSourceTest method fetchFormList_whenOpenRosaResponse_whenParserFails_throwsParseError.
@Test
public void fetchFormList_whenOpenRosaResponse_whenParserFails_throwsParseError() throws Exception {
OpenRosaFormSource formListApi = new OpenRosaFormSource("http://blah.com", httpInterface, webCredentialsUtils, responseParser);
try {
when(httpInterface.executeGetRequest(any(), any(), any())).thenReturn(new HttpGetResult(new ByteArrayInputStream("<xml></xml>".getBytes()), new HashMap<String, String>() {
{
put(OpenRosaConstants.VERSION_HEADER, "1.0");
}
}, "hash", 200));
when(responseParser.parseFormList(any())).thenReturn(null);
formListApi.fetchFormList();
fail("No exception thrown!");
} catch (FormSourceException.ParseError e) {
assertThat(e.getServerUrl(), is("http://blah.com"));
}
}
Aggregations