use of it.niedermann.owncloud.notes.shared.model.OcsResponse in project nextcloud-notes by stefan-niedermann.
the class CapabilitiesClientTest method testGetCapabilities.
@Test
public void testGetCapabilities() throws Throwable {
// noinspection unchecked
final ParsedResponse<OcsResponse<Capabilities>> responseMock = mock(ParsedResponse.class);
final OcsResponse<Capabilities> mockOcs = new OcsResponse<>();
mockOcs.ocs = new OcsResponse.OcsWrapper<>();
mockOcs.ocs.data = new Capabilities();
mockOcs.ocs.data.setApiVersion("[1.0]");
when(responseMock.getResponse()).thenReturn(mockOcs);
when(responseMock.getHeaders()).thenReturn(Map.of("ETag", "1234"));
when(ocsAPI.getCapabilities(any())).thenReturn(Observable.just(responseMock));
final var capabilities = CapabilitiesClient.getCapabilities(ApplicationProvider.getApplicationContext(), ssoAccount, null, apiProvider);
assertEquals("[1.0]", capabilities.getApiVersion());
assertEquals("ETag should be read correctly from response but wasn't.", "1234", capabilities.getETag());
when(ocsAPI.getCapabilities(any())).thenReturn(Observable.error(new RuntimeException()));
assertThrows(RuntimeException.class, () -> CapabilitiesClient.getCapabilities(ApplicationProvider.getApplicationContext(), ssoAccount, null, apiProvider));
when(ocsAPI.getCapabilities(any())).thenReturn(Observable.error(new RuntimeException(new NetworkErrorException())));
assertThrows("Should unwrap exception cause if possible", NetworkErrorException.class, () -> CapabilitiesClient.getCapabilities(ApplicationProvider.getApplicationContext(), ssoAccount, null, apiProvider));
}
use of it.niedermann.owncloud.notes.shared.model.OcsResponse in project nextcloud-notes by stefan-niedermann.
the class CapabilitiesClientTest method testGetDisplayName.
@SuppressWarnings("unchecked")
@Test
public void testGetDisplayName() throws IOException {
final var mockOcs = new OcsResponse<OcsUser>();
mockOcs.ocs = new OcsResponse.OcsWrapper<>();
mockOcs.ocs.data = new OcsUser();
mockOcs.ocs.data.displayName = "Peter";
final var responseMock = Response.success(mockOcs);
final var callMock = mock(Call.class);
when(ocsAPI.getUser(any())).thenReturn(callMock);
when(callMock.execute()).thenReturn(responseMock);
assertEquals("Peter", CapabilitiesClient.getDisplayName(ApplicationProvider.getApplicationContext(), ssoAccount, apiProvider));
when(callMock.execute()).thenThrow(new RuntimeException() {
@Override
public void printStackTrace() {
// Do not spam console, this will be printed.
}
});
assertNull(CapabilitiesClient.getDisplayName(ApplicationProvider.getApplicationContext(), ssoAccount, apiProvider));
}
Aggregations