Search in sources :

Example 1 with OpenRosaFormSource

use of org.odk.collect.android.openrosa.OpenRosaFormSource in project collect by opendatakit.

the class OpenRosaFormSourceTest method fetchFormList_whenThereIsAnSSLException_throwsSecurityErrorFormApiException.

@Test
public void fetchFormList_whenThereIsAnSSLException_throwsSecurityErrorFormApiException() throws Exception {
    OpenRosaFormSource formListApi = new OpenRosaFormSource("http://blah.com", httpInterface, webCredentialsUtils, responseParser);
    try {
        when(httpInterface.executeGetRequest(any(), any(), any())).thenThrow(SSLException.class);
        formListApi.fetchFormList();
        fail("No exception thrown!");
    } catch (FormSourceException.SecurityError e) {
        assertThat(e.getServerUrl(), is("http://blah.com"));
    }
}
Also used : FormSourceException(org.odk.collect.forms.FormSourceException) OpenRosaFormSource(org.odk.collect.android.openrosa.OpenRosaFormSource) Test(org.junit.Test)

Example 2 with OpenRosaFormSource

use of org.odk.collect.android.openrosa.OpenRosaFormSource in project collect by opendatakit.

the class OpenRosaFormSourceTest method fetchMediaFile_whenThereIsAServerError_throwsServerError.

@Test
public void fetchMediaFile_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.fetchMediaFile("http://blah.com/mediaFile");
        fail("No exception thrown!");
    } catch (FormSourceException.ServerError e) {
        assertThat(e.getStatusCode(), is(500));
        assertThat(e.getServerUrl(), is("http://blah.com"));
    }
}
Also used : FormSourceException(org.odk.collect.forms.FormSourceException) HashMap(java.util.HashMap) OpenRosaFormSource(org.odk.collect.android.openrosa.OpenRosaFormSource) HttpGetResult(org.odk.collect.android.openrosa.HttpGetResult) Test(org.junit.Test)

Example 3 with OpenRosaFormSource

use of org.odk.collect.android.openrosa.OpenRosaFormSource in project collect by opendatakit.

the class OpenRosaFormSourceTest method fetchFormList_whenThereIsAServerError_throwsServerError.

@Test
public void fetchFormList_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.fetchFormList();
        fail("No exception thrown!");
    } catch (FormSourceException.ServerError e) {
        assertThat(e.getStatusCode(), is(500));
        assertThat(e.getServerUrl(), is("http://blah.com"));
    }
}
Also used : FormSourceException(org.odk.collect.forms.FormSourceException) HashMap(java.util.HashMap) OpenRosaFormSource(org.odk.collect.android.openrosa.OpenRosaFormSource) HttpGetResult(org.odk.collect.android.openrosa.HttpGetResult) Test(org.junit.Test)

Example 4 with OpenRosaFormSource

use of org.odk.collect.android.openrosa.OpenRosaFormSource in project collect by opendatakit.

the class OpenRosaFormSourceTest method fetchManifest_whenNotOpenRosaResponse_throwsParseError.

@Test
public void fetchManifest_whenNotOpenRosaResponse_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<>(), "hash", 200));
        formListApi.fetchManifest("http://blah.com/manifest");
        fail("No exception thrown!");
    } catch (FormSourceException.ParseError e) {
        assertThat(e.getServerUrl(), is("http://blah.com"));
    }
}
Also used : FormSourceException(org.odk.collect.forms.FormSourceException) ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) OpenRosaFormSource(org.odk.collect.android.openrosa.OpenRosaFormSource) HttpGetResult(org.odk.collect.android.openrosa.HttpGetResult) Test(org.junit.Test)

Example 5 with OpenRosaFormSource

use of org.odk.collect.android.openrosa.OpenRosaFormSource in project collect by opendatakit.

the class OpenRosaFormSourceTest method fetchFormList_removesTrailingSlashesFromUrl.

@Test
public void fetchFormList_removesTrailingSlashesFromUrl() throws Exception {
    OpenRosaFormSource formListApi = new OpenRosaFormSource("http://blah.com///", httpInterface, webCredentialsUtils, responseParser);
    when(httpInterface.executeGetRequest(any(), any(), any())).thenReturn(new HttpGetResult(new ByteArrayInputStream(RESPONSE.getBytes()), new HashMap<String, String>() {

        {
            put(OpenRosaConstants.VERSION_HEADER, "1.0");
        }
    }, "", 200));
    formListApi.fetchFormList();
    verify(httpInterface).executeGetRequest(eq(new URI("http://blah.com/formList")), any(), any());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) HashMap(java.util.HashMap) OpenRosaFormSource(org.odk.collect.android.openrosa.OpenRosaFormSource) HttpGetResult(org.odk.collect.android.openrosa.HttpGetResult) URI(java.net.URI) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)14 OpenRosaFormSource (org.odk.collect.android.openrosa.OpenRosaFormSource)14 FormSourceException (org.odk.collect.forms.FormSourceException)13 HashMap (java.util.HashMap)10 HttpGetResult (org.odk.collect.android.openrosa.HttpGetResult)10 ByteArrayInputStream (java.io.ByteArrayInputStream)5 URI (java.net.URI)1