Java Code Examples for com.squareup.okhttp.HttpUrl#toString()
The following examples show how to use
com.squareup.okhttp.HttpUrl#toString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LastUpdatedManager.java From dhis2-android-dashboard with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void put(Session session) { isNull(session, "Session object must not be null"); HttpUrl serverUrl = session.getServerUrl(); Credentials credentials = session.getCredentials(); String url = null; String username = null; String password = null; if (serverUrl != null) { url = serverUrl.toString(); } if (credentials != null) { username = credentials.getUsername(); password = credentials.getPassword(); } putString(SERVER_URI, url); putString(USERNAME, username); putString(PASSWORD, password); }
Example 2
Source File: BaseRoboTest.java From mobile-sdk-android with Apache License 2.0 | 6 votes |
@Before public void setup() { Robolectric.getBackgroundThreadScheduler().reset(); Robolectric.getForegroundThreadScheduler().reset(); ShadowLog.stream = System.out; activity = Robolectric.buildActivity(MockMainActivity.class).create().start().resume().visible().get(); shadowOf(activity).grantPermissions("android.permission.INTERNET"); server= new MockWebServer(); try { server.start(); HttpUrl url= server.url("/"); UTConstants.REQUEST_BASE_URL_UT = url.toString(); System.out.println(UTConstants.REQUEST_BASE_URL_UT); ShadowSettings.setTestURL(url.toString()); } catch (IOException e) { System.out.print("IOException"); } bgScheduler = Robolectric.getBackgroundThreadScheduler(); uiScheduler = Robolectric.getForegroundThreadScheduler(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); bgScheduler.pause(); uiScheduler.pause(); }
Example 3
Source File: BaseRoboTest.java From mobile-sdk-android with Apache License 2.0 | 6 votes |
@Before public void setup() { SDKSettings.setExternalExecutor(null); Robolectric.getBackgroundThreadScheduler().reset(); Robolectric.getForegroundThreadScheduler().reset(); ShadowLog.stream = System.out; activity = Robolectric.buildActivity(MockMainActivity.class).create().start().resume().visible().get(); shadowOf(activity).grantPermissions("android.permission.INTERNET"); server= new MockWebServer(); try { server.start(); HttpUrl url= server.url("/"); UTConstants.REQUEST_BASE_URL_UT = url.toString(); System.out.println(UTConstants.REQUEST_BASE_URL_UT); ShadowSettings.setTestURL(url.toString()); TestResponsesUT.setTestURL(url.toString()); } catch (IOException e) { System.out.print("IOException"); } bgScheduler = Robolectric.getBackgroundThreadScheduler(); uiScheduler = Robolectric.getForegroundThreadScheduler(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); bgScheduler.pause(); uiScheduler.pause(); }
Example 4
Source File: MicrosoftCalendarExportTest.java From data-transfer-project with Apache License 2.0 | 5 votes |
@Test public void testExport() throws Exception { server.enqueue(new MockResponse().setBody(CALENDARS_RESPONSE)); server.enqueue(new MockResponse().setBody(CALENDAR1_EVENTS_RESPONSE)); server.enqueue(new MockResponse().setBody(CALENDAR2_EVENTS_RESPONSE)); server.start(); HttpUrl baseUrl = server.url(""); MicrosoftCalendarExporter exporter = new MicrosoftCalendarExporter(baseUrl.toString(), client, mapper, transformerService); ExportResult<CalendarContainerResource> resource = exporter .export(UUID.randomUUID(), token, Optional.empty()); CalendarContainerResource calendarResource = resource.getExportedData(); Assert.assertEquals(2, calendarResource.getCalendars().size()); Assert.assertFalse( calendarResource .getCalendars() .stream() .anyMatch(c -> "Calendar1".equals(c.getId()) && "Calendar2".equals(c.getId()))); Assert.assertEquals(2, calendarResource.getEvents().size()); Assert.assertFalse( calendarResource .getEvents() .stream() .anyMatch( e -> "Test Appointment 1".equals(e.getTitle()) && "Test Appointment 2".equals(e.getTitle()))); }
Example 5
Source File: NativeRequestTest.java From mobile-sdk-android with Apache License 2.0 | 4 votes |
@Test public void testNativeCSRResponseLogImpresionsClicksProperly() { final HashMap<String, Boolean> logs = new HashMap<>(); logs.put("impression", false); logs.put("click", false); logs.put("request_url", false); logs.put("response_url", false); HttpUrl impression = server.url("/impression"); HttpUrl click = server.url("/click"); final HttpUrl request_url = server.url("/request_url"); final HttpUrl response_url = server.url("/response_url"); final MockResponse impbusResponse = new MockResponse().setResponseCode(200).setBody(TestResponsesUT.csrNativeSuccesfulWithMockTrackers(impression.toString(), click.toString(), request_url.toString(), response_url.toString())); final Dispatcher dispatcher = new Dispatcher() { @Override public MockResponse dispatch(RecordedRequest request) throws InterruptedException { String path = request.getPath(); if ("/".equals(path)) { return impbusResponse; } else if ("/impression".equals(path)) { logs.put("impresssion", true); return new MockResponse().setResponseCode(200); } else if ("/click".equals(path)) { logs.put("click", true); return new MockResponse().setResponseCode(200); } else if ("/request_url".equals(path)) { logs.put("request_url", true); return new MockResponse().setResponseCode(200); } else if (path != null && path.startsWith("/response_url")) { logs.put("response_url", true); return new MockResponse().setResponseCode(200); } return new MockResponse().setResponseCode(404); } }; server.setDispatcher(dispatcher); HttpUrl impbus = server.url("/"); UTConstants.REQUEST_BASE_URL_UT = impbus.toString(); NativeAdRequestListener listener = new NativeAdRequestListener() { @Override public void onAdLoaded(NativeAdResponse response) { nativeAdResponse = response; ((MockFBNativeBannerAdResponse) response).logImpression(); ((MockFBNativeBannerAdResponse) response).clickAd(); } @Override public void onAdFailed(ResultCode errorcode, ANAdResponseInfo adResponseInfo) { } }; adRequest.setListener(listener); adRequest.loadAd(); waitForTasks(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); waitForTasks(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); assertNotNull(nativeAdResponse); assertTrue(nativeAdResponse instanceof MockFBNativeBannerAdResponse); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); waitForTasks(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); assertTrue(logs.get("impresssion")); assertTrue(logs.get("click")); assertTrue(logs.get("response_url")); }