target
stringlengths 20
113k
| src_fm
stringlengths 11
86.3k
| src_fm_fc
stringlengths 21
86.4k
| src_fm_fc_co
stringlengths 30
86.4k
| src_fm_fc_ms
stringlengths 42
86.8k
| src_fm_fc_ms_ff
stringlengths 43
86.8k
|
---|---|---|---|---|---|
@Test @SuppressWarnings("deprecation") public void onTooManyRedirects() { final Message cancelMsg = Mockito.mock(Message.class); final Message continueMsg = Mockito.mock(Message.class); debugClient.onTooManyRedirects(webView, cancelMsg, continueMsg); verifyLogger().onTooManyRedirects(webView, cancelMsg, continueMsg); verifyWrappedClient().onTooManyRedirects(webView, cancelMsg, continueMsg); } | @Override @Deprecated @SuppressWarnings("deprecation") public void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg) { logger.onTooManyRedirects(view, cancelMsg, continueMsg); client.onTooManyRedirects(view, cancelMsg, continueMsg); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override @Deprecated @SuppressWarnings("deprecation") public void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg) { logger.onTooManyRedirects(view, cancelMsg, continueMsg); client.onTooManyRedirects(view, cancelMsg, continueMsg); } } | DebugWebViewClient extends WebViewClient implements LogControl { @Override @Deprecated @SuppressWarnings("deprecation") public void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg) { logger.onTooManyRedirects(view, cancelMsg, continueMsg); client.onTooManyRedirects(view, cancelMsg, continueMsg); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override @Deprecated @SuppressWarnings("deprecation") public void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg) { logger.onTooManyRedirects(view, cancelMsg, continueMsg); client.onTooManyRedirects(view, cancelMsg, continueMsg); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override @Deprecated @SuppressWarnings("deprecation") public void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg) { logger.onTooManyRedirects(view, cancelMsg, continueMsg); client.onTooManyRedirects(view, cancelMsg, continueMsg); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onReceivedHttpAuthRequest() { final HttpAuthHandler handler = Mockito.mock(HttpAuthHandler.class); final String host = "foo"; final String realm = "bar"; debugClient.onReceivedHttpAuthRequest(webView, handler, host, realm); verifyLogger().onReceivedHttpAuthRequest(webView, handler, host, realm); verifyWrappedClient().onReceivedHttpAuthRequest(webView, handler, host, realm); } | @Override public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) { logger.onReceivedHttpAuthRequest(view, handler, host, realm); client.onReceivedHttpAuthRequest(view, handler, host, realm); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) { logger.onReceivedHttpAuthRequest(view, handler, host, realm); client.onReceivedHttpAuthRequest(view, handler, host, realm); } } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) { logger.onReceivedHttpAuthRequest(view, handler, host, realm); client.onReceivedHttpAuthRequest(view, handler, host, realm); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) { logger.onReceivedHttpAuthRequest(view, handler, host, realm); client.onReceivedHttpAuthRequest(view, handler, host, realm); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) { logger.onReceivedHttpAuthRequest(view, handler, host, realm); client.onReceivedHttpAuthRequest(view, handler, host, realm); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onPageStarted() { final String url = "foo"; final Bitmap bitmap = Mockito.mock(Bitmap.class); debugClient.onPageStarted(webView, url, bitmap); verifyLogger().onPageStarted(webView, url, bitmap); verifyWrappedClient().onPageStarted(webView, url, bitmap); } | @Override public void onPageStarted(WebView view, String url, Bitmap facIcon) { logger.onPageStarted(view, url, facIcon); client.onPageStarted(view, url, facIcon); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onPageStarted(WebView view, String url, Bitmap facIcon) { logger.onPageStarted(view, url, facIcon); client.onPageStarted(view, url, facIcon); } } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onPageStarted(WebView view, String url, Bitmap facIcon) { logger.onPageStarted(view, url, facIcon); client.onPageStarted(view, url, facIcon); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onPageStarted(WebView view, String url, Bitmap facIcon) { logger.onPageStarted(view, url, facIcon); client.onPageStarted(view, url, facIcon); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onPageStarted(WebView view, String url, Bitmap facIcon) { logger.onPageStarted(view, url, facIcon); client.onPageStarted(view, url, facIcon); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onPageFinished() { final String url = "foo"; debugClient.onPageFinished(webView, url); verifyLogger().onPageFinished(webView, url); verifyWrappedClient().onPageFinished(webView, url); } | @Override public void onPageFinished(WebView view, String url) { logger.onPageFinished(view, url); client.onPageFinished(view, url); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onPageFinished(WebView view, String url) { logger.onPageFinished(view, url); client.onPageFinished(view, url); } } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onPageFinished(WebView view, String url) { logger.onPageFinished(view, url); client.onPageFinished(view, url); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onPageFinished(WebView view, String url) { logger.onPageFinished(view, url); client.onPageFinished(view, url); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onPageFinished(WebView view, String url) { logger.onPageFinished(view, url); client.onPageFinished(view, url); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onReceivedClientCertRequest() { final ClientCertRequest request = Mockito.mock(ClientCertRequest.class); debugClient.onReceivedClientCertRequest(webView, request); verifyLogger().onReceivedClientCertRequest(webView, request); verifyWrappedClient().onReceivedClientCertRequest(webView, request); } | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override public void onReceivedClientCertRequest(WebView view, ClientCertRequest request) { logger.onReceivedClientCertRequest(view, request); client.onReceivedClientCertRequest(view, request); } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override public void onReceivedClientCertRequest(WebView view, ClientCertRequest request) { logger.onReceivedClientCertRequest(view, request); client.onReceivedClientCertRequest(view, request); } } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override public void onReceivedClientCertRequest(WebView view, ClientCertRequest request) { logger.onReceivedClientCertRequest(view, request); client.onReceivedClientCertRequest(view, request); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override public void onReceivedClientCertRequest(WebView view, ClientCertRequest request) { logger.onReceivedClientCertRequest(view, request); client.onReceivedClientCertRequest(view, request); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override public void onReceivedClientCertRequest(WebView view, ClientCertRequest request) { logger.onReceivedClientCertRequest(view, request); client.onReceivedClientCertRequest(view, request); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onFormResubmission() { final Message dontResend = Mockito.mock(Message.class); final Message resend = Mockito.mock(Message.class); debugClient.onFormResubmission(webView, dontResend, resend); verifyLogger().onFormResubmission(webView, dontResend, resend); verifyWrappedClient().onFormResubmission(webView, dontResend, resend); } | @Override public void onFormResubmission(final WebView view, final Message dontResend, final Message resend) { logger.onFormResubmission(view, dontResend, resend); client.onFormResubmission(view, dontResend, resend); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onFormResubmission(final WebView view, final Message dontResend, final Message resend) { logger.onFormResubmission(view, dontResend, resend); client.onFormResubmission(view, dontResend, resend); } } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onFormResubmission(final WebView view, final Message dontResend, final Message resend) { logger.onFormResubmission(view, dontResend, resend); client.onFormResubmission(view, dontResend, resend); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onFormResubmission(final WebView view, final Message dontResend, final Message resend) { logger.onFormResubmission(view, dontResend, resend); client.onFormResubmission(view, dontResend, resend); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onFormResubmission(final WebView view, final Message dontResend, final Message resend) { logger.onFormResubmission(view, dontResend, resend); client.onFormResubmission(view, dontResend, resend); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void doUpdateVisitedHistory() { final String url = "foo"; final boolean reload = true; debugClient.doUpdateVisitedHistory(webView, url, reload); verifyLogger().doUpdateVisitedHistory(webView, url, reload); verifyWrappedClient().doUpdateVisitedHistory(webView, url, reload); } | @Override public void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload) { logger.doUpdateVisitedHistory(view, url, isReload); client.doUpdateVisitedHistory(view, url, isReload); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload) { logger.doUpdateVisitedHistory(view, url, isReload); client.doUpdateVisitedHistory(view, url, isReload); } } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload) { logger.doUpdateVisitedHistory(view, url, isReload); client.doUpdateVisitedHistory(view, url, isReload); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload) { logger.doUpdateVisitedHistory(view, url, isReload); client.doUpdateVisitedHistory(view, url, isReload); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload) { logger.doUpdateVisitedHistory(view, url, isReload); client.doUpdateVisitedHistory(view, url, isReload); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void shouldOverrideKeyEvent() { final KeyEvent keyEvent = Mockito.mock(KeyEvent.class); final boolean retVal = debugClient.shouldOverrideKeyEvent(webView, keyEvent); verifyLogger().shouldOverrideKeyEvent(webView, keyEvent, retVal); verifyWrappedClient().shouldOverrideKeyEvent(webView, keyEvent); } | @Override public boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event) { final boolean retVal = client.shouldOverrideKeyEvent(view, event); logger.shouldOverrideKeyEvent(view, event, retVal); return retVal; } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event) { final boolean retVal = client.shouldOverrideKeyEvent(view, event); logger.shouldOverrideKeyEvent(view, event, retVal); return retVal; } } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event) { final boolean retVal = client.shouldOverrideKeyEvent(view, event); logger.shouldOverrideKeyEvent(view, event, retVal); return retVal; } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event) { final boolean retVal = client.shouldOverrideKeyEvent(view, event); logger.shouldOverrideKeyEvent(view, event, retVal); return retVal; } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event) { final boolean retVal = client.shouldOverrideKeyEvent(view, event); logger.shouldOverrideKeyEvent(view, event, retVal); return retVal; } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onUnhandledKeyEvent() { final KeyEvent keyEvent = Mockito.mock(KeyEvent.class); debugClient.onUnhandledKeyEvent(webView, keyEvent); verifyLogger().onUnhandledKeyEvent(webView, keyEvent); verifyWrappedClient().onUnhandledKeyEvent(webView, keyEvent); } | @Override public void onUnhandledKeyEvent(final WebView view, final KeyEvent event) { logger.onUnhandledKeyEvent(view, event); client.onUnhandledKeyEvent(view, event); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onUnhandledKeyEvent(final WebView view, final KeyEvent event) { logger.onUnhandledKeyEvent(view, event); client.onUnhandledKeyEvent(view, event); } } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onUnhandledKeyEvent(final WebView view, final KeyEvent event) { logger.onUnhandledKeyEvent(view, event); client.onUnhandledKeyEvent(view, event); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onUnhandledKeyEvent(final WebView view, final KeyEvent event) { logger.onUnhandledKeyEvent(view, event); client.onUnhandledKeyEvent(view, event); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onUnhandledKeyEvent(final WebView view, final KeyEvent event) { logger.onUnhandledKeyEvent(view, event); client.onUnhandledKeyEvent(view, event); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onScaleChanged() { final float oldScale = 1.0f; final float newScale = 2.0f; debugClient.onScaleChanged(webView, oldScale, newScale); verifyLogger().onScaleChanged(webView, oldScale, newScale); verifyWrappedClient().onScaleChanged(webView, oldScale, newScale); } | @Override public void onScaleChanged(final WebView view, final float oldScale, final float newScale) { logger.onScaleChanged(view, oldScale, newScale); client.onScaleChanged(view, oldScale, newScale); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onScaleChanged(final WebView view, final float oldScale, final float newScale) { logger.onScaleChanged(view, oldScale, newScale); client.onScaleChanged(view, oldScale, newScale); } } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onScaleChanged(final WebView view, final float oldScale, final float newScale) { logger.onScaleChanged(view, oldScale, newScale); client.onScaleChanged(view, oldScale, newScale); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onScaleChanged(final WebView view, final float oldScale, final float newScale) { logger.onScaleChanged(view, oldScale, newScale); client.onScaleChanged(view, oldScale, newScale); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onScaleChanged(final WebView view, final float oldScale, final float newScale) { logger.onScaleChanged(view, oldScale, newScale); client.onScaleChanged(view, oldScale, newScale); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onReceivedError_api23() { final WebResourceRequest request = Mockito.mock(WebResourceRequest.class); final WebResourceError error = Mockito.mock(WebResourceError.class); debugClient.onReceivedError(webView, request, error); verifyLogger().onReceivedError(webView, request, error); verifyWrappedClient().onReceivedError(webView, request, error); } | @RequiresApi(api = Build.VERSION_CODES.M) @Override public void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error) { logger.onReceivedError(view, request, error); client.onReceivedError(view, request, error); } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.M) @Override public void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error) { logger.onReceivedError(view, request, error); client.onReceivedError(view, request, error); } } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.M) @Override public void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error) { logger.onReceivedError(view, request, error); client.onReceivedError(view, request, error); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.M) @Override public void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error) { logger.onReceivedError(view, request, error); client.onReceivedError(view, request, error); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.M) @Override public void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error) { logger.onReceivedError(view, request, error); client.onReceivedError(view, request, error); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onReceivedLoginRequest() { final String realm = "realm"; final String account = "account"; final String args = "args"; debugClient.onReceivedLoginRequest(webView, realm, account, args); verifyLogger().onReceivedLoginRequest(webView, realm, account, args); verifyWrappedClient().onReceivedLoginRequest(webView, realm, account, args); } | @Override public void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args) { logger.onReceivedLoginRequest(view, realm, account, args); client.onReceivedLoginRequest(view, realm, account, args); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args) { logger.onReceivedLoginRequest(view, realm, account, args); client.onReceivedLoginRequest(view, realm, account, args); } } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args) { logger.onReceivedLoginRequest(view, realm, account, args); client.onReceivedLoginRequest(view, realm, account, args); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args) { logger.onReceivedLoginRequest(view, realm, account, args); client.onReceivedLoginRequest(view, realm, account, args); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args) { logger.onReceivedLoginRequest(view, realm, account, args); client.onReceivedLoginRequest(view, realm, account, args); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onRenderProcessGone() { final RenderProcessGoneDetail detail = Mockito.mock(RenderProcessGoneDetail.class); final boolean retVal = debugClient.onRenderProcessGone(webView, detail); verifyLogger().onRenderProcessGone(webView, detail, retVal); verifyWrappedClient().onRenderProcessGone(webView, detail); } | @RequiresApi(api = Build.VERSION_CODES.O) @Override public boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail) { final boolean retVal = client.onRenderProcessGone(view, detail); logger.onRenderProcessGone(view, detail, retVal); return retVal; } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.O) @Override public boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail) { final boolean retVal = client.onRenderProcessGone(view, detail); logger.onRenderProcessGone(view, detail, retVal); return retVal; } } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.O) @Override public boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail) { final boolean retVal = client.onRenderProcessGone(view, detail); logger.onRenderProcessGone(view, detail, retVal); return retVal; } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.O) @Override public boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail) { final boolean retVal = client.onRenderProcessGone(view, detail); logger.onRenderProcessGone(view, detail, retVal); return retVal; } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.O) @Override public boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail) { final boolean retVal = client.onRenderProcessGone(view, detail); logger.onRenderProcessGone(view, detail, retVal); return retVal; } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onSafeBrowsingHit() { final WebResourceRequest request = Mockito.mock(WebResourceRequest.class); final SafeBrowsingResponse callback = Mockito.mock(SafeBrowsingResponse.class); final int threatType = -1; debugClient.onSafeBrowsingHit(webView, request, threatType, callback); verifyLogger().onSafeBrowsingHit(webView, request, threatType, callback); verifyWrappedClient().onSafeBrowsingHit(webView, request, threatType, callback); } | @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override public void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback) { logger.onSafeBrowsingHit(view, request, threatType, callback); client.onSafeBrowsingHit(view, request, threatType, callback); } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override public void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback) { logger.onSafeBrowsingHit(view, request, threatType, callback); client.onSafeBrowsingHit(view, request, threatType, callback); } } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override public void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback) { logger.onSafeBrowsingHit(view, request, threatType, callback); client.onSafeBrowsingHit(view, request, threatType, callback); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override public void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback) { logger.onSafeBrowsingHit(view, request, threatType, callback); client.onSafeBrowsingHit(view, request, threatType, callback); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override public void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback) { logger.onSafeBrowsingHit(view, request, threatType, callback); client.onSafeBrowsingHit(view, request, threatType, callback); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onReceivedError() { final int code = 500; final String message = "foo"; final String url = "bar"; logger.setLoggingEnabled(false); logger.onReceivedError(webView, code, message, url); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.onReceivedError(webView, code, message, url); verifyLogEngine().logError(Mockito.anyString()); } | @RequiresApi(api = Build.VERSION_CODES.M) public void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error) { if (loggingEnabled) { final Uri url = request.getUrl(); final String method = request.getMethod(); final int code = error.getErrorCode(); logger.logError(String.format(LOCALE, "%s onReceivedError() 1/3 CALL : %d %s %s", SPACE, code, method, url)); logger.logError(String.format(LOCALE, "%s onReceivedError() 2/3 REQ HEADERS: %s", SPACE, request.getRequestHeaders())); logger.logError(String.format(LOCALE, "%s onReceivedError() 3/3 ERR DESC : %s", SPACE, error.getDescription())); } } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.M) public void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error) { if (loggingEnabled) { final Uri url = request.getUrl(); final String method = request.getMethod(); final int code = error.getErrorCode(); logger.logError(String.format(LOCALE, "%s onReceivedError() 1/3 CALL : %d %s %s", SPACE, code, method, url)); logger.logError(String.format(LOCALE, "%s onReceivedError() 2/3 REQ HEADERS: %s", SPACE, request.getRequestHeaders())); logger.logError(String.format(LOCALE, "%s onReceivedError() 3/3 ERR DESC : %s", SPACE, error.getDescription())); } } } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.M) public void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error) { if (loggingEnabled) { final Uri url = request.getUrl(); final String method = request.getMethod(); final int code = error.getErrorCode(); logger.logError(String.format(LOCALE, "%s onReceivedError() 1/3 CALL : %d %s %s", SPACE, code, method, url)); logger.logError(String.format(LOCALE, "%s onReceivedError() 2/3 REQ HEADERS: %s", SPACE, request.getRequestHeaders())); logger.logError(String.format(LOCALE, "%s onReceivedError() 3/3 ERR DESC : %s", SPACE, error.getDescription())); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.M) public void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error) { if (loggingEnabled) { final Uri url = request.getUrl(); final String method = request.getMethod(); final int code = error.getErrorCode(); logger.logError(String.format(LOCALE, "%s onReceivedError() 1/3 CALL : %d %s %s", SPACE, code, method, url)); logger.logError(String.format(LOCALE, "%s onReceivedError() 2/3 REQ HEADERS: %s", SPACE, request.getRequestHeaders())); logger.logError(String.format(LOCALE, "%s onReceivedError() 3/3 ERR DESC : %s", SPACE, error.getDescription())); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.M) public void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error) { if (loggingEnabled) { final Uri url = request.getUrl(); final String method = request.getMethod(); final int code = error.getErrorCode(); logger.logError(String.format(LOCALE, "%s onReceivedError() 1/3 CALL : %d %s %s", SPACE, code, method, url)); logger.logError(String.format(LOCALE, "%s onReceivedError() 2/3 REQ HEADERS: %s", SPACE, request.getRequestHeaders())); logger.logError(String.format(LOCALE, "%s onReceivedError() 3/3 ERR DESC : %s", SPACE, error.getDescription())); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onReceivedHttpError() { final WebResourceRequest request = Mockito.mock(WebResourceRequest.class); final WebResourceResponse response = Mockito.mock(WebResourceResponse.class); logger.setLoggingEnabled(false); logger.onReceivedHttpError(webView, request, response); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.onReceivedHttpError(webView, request, response); verifyLogEngine().logError(Mockito.anyString()); } | @RequiresApi(api = Build.VERSION_CODES.M) public void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse) { if (loggingEnabled) { final Uri url = request.getUrl(); final int code = errorResponse.getStatusCode(); final String method = request.getMethod(); logger.logError(String.format(LOCALE, "%s onReceivedHttpError() 1/4 CALL : %d %s %s", SPACE, code, method, url)); logger.logError(String.format(LOCALE, "%s onReceivedHttpError() 2/4 REQ HEADERS: %s", SPACE, request.getRequestHeaders())); logger.logError(String.format(LOCALE, "%s onReceivedHttpError() 3/4 ERR DESC : %s", SPACE, errorResponse.getReasonPhrase())); logger.logError(String.format(LOCALE, "%s onReceivedHttpError() 4/4 ERR HEADERS: %s", SPACE, errorResponse.getResponseHeaders())); } } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.M) public void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse) { if (loggingEnabled) { final Uri url = request.getUrl(); final int code = errorResponse.getStatusCode(); final String method = request.getMethod(); logger.logError(String.format(LOCALE, "%s onReceivedHttpError() 1/4 CALL : %d %s %s", SPACE, code, method, url)); logger.logError(String.format(LOCALE, "%s onReceivedHttpError() 2/4 REQ HEADERS: %s", SPACE, request.getRequestHeaders())); logger.logError(String.format(LOCALE, "%s onReceivedHttpError() 3/4 ERR DESC : %s", SPACE, errorResponse.getReasonPhrase())); logger.logError(String.format(LOCALE, "%s onReceivedHttpError() 4/4 ERR HEADERS: %s", SPACE, errorResponse.getResponseHeaders())); } } } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.M) public void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse) { if (loggingEnabled) { final Uri url = request.getUrl(); final int code = errorResponse.getStatusCode(); final String method = request.getMethod(); logger.logError(String.format(LOCALE, "%s onReceivedHttpError() 1/4 CALL : %d %s %s", SPACE, code, method, url)); logger.logError(String.format(LOCALE, "%s onReceivedHttpError() 2/4 REQ HEADERS: %s", SPACE, request.getRequestHeaders())); logger.logError(String.format(LOCALE, "%s onReceivedHttpError() 3/4 ERR DESC : %s", SPACE, errorResponse.getReasonPhrase())); logger.logError(String.format(LOCALE, "%s onReceivedHttpError() 4/4 ERR HEADERS: %s", SPACE, errorResponse.getResponseHeaders())); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.M) public void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse) { if (loggingEnabled) { final Uri url = request.getUrl(); final int code = errorResponse.getStatusCode(); final String method = request.getMethod(); logger.logError(String.format(LOCALE, "%s onReceivedHttpError() 1/4 CALL : %d %s %s", SPACE, code, method, url)); logger.logError(String.format(LOCALE, "%s onReceivedHttpError() 2/4 REQ HEADERS: %s", SPACE, request.getRequestHeaders())); logger.logError(String.format(LOCALE, "%s onReceivedHttpError() 3/4 ERR DESC : %s", SPACE, errorResponse.getReasonPhrase())); logger.logError(String.format(LOCALE, "%s onReceivedHttpError() 4/4 ERR HEADERS: %s", SPACE, errorResponse.getResponseHeaders())); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.M) public void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse) { if (loggingEnabled) { final Uri url = request.getUrl(); final int code = errorResponse.getStatusCode(); final String method = request.getMethod(); logger.logError(String.format(LOCALE, "%s onReceivedHttpError() 1/4 CALL : %d %s %s", SPACE, code, method, url)); logger.logError(String.format(LOCALE, "%s onReceivedHttpError() 2/4 REQ HEADERS: %s", SPACE, request.getRequestHeaders())); logger.logError(String.format(LOCALE, "%s onReceivedHttpError() 3/4 ERR DESC : %s", SPACE, errorResponse.getReasonPhrase())); logger.logError(String.format(LOCALE, "%s onReceivedHttpError() 4/4 ERR HEADERS: %s", SPACE, errorResponse.getResponseHeaders())); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onReceivedSslError() { final SslErrorHandler errorHandler = Mockito.mock(SslErrorHandler.class); final SslError sslError = Mockito.mock(SslError.class); logger.setLoggingEnabled(false); logger.onReceivedSslError(webView, errorHandler, sslError); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.onReceivedSslError(webView, errorHandler, sslError); verifyLogEngine().logError(Mockito.anyString()); } | public void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error) { if (loggingEnabled) { logger.logError(String.format(LOCALE, "%s onReceivedSslError() ERR: %s", SPACE, error)); } } | DebugWebViewClientLogger implements LogControl { public void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error) { if (loggingEnabled) { logger.logError(String.format(LOCALE, "%s onReceivedSslError() ERR: %s", SPACE, error)); } } } | DebugWebViewClientLogger implements LogControl { public void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error) { if (loggingEnabled) { logger.logError(String.format(LOCALE, "%s onReceivedSslError() ERR: %s", SPACE, error)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); } | DebugWebViewClientLogger implements LogControl { public void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error) { if (loggingEnabled) { logger.logError(String.format(LOCALE, "%s onReceivedSslError() ERR: %s", SPACE, error)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClientLogger implements LogControl { public void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error) { if (loggingEnabled) { logger.logError(String.format(LOCALE, "%s onReceivedSslError() ERR: %s", SPACE, error)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void shouldOverrideUrlLoading() { final String url = "foo"; logger.setLoggingEnabled(false); logger.shouldOverrideUrlLoading(webView, url, false); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.shouldOverrideUrlLoading(webView, url, false); verifyLogEngine().log(Mockito.anyString()); } | @RequiresApi(api = Build.VERSION_CODES.N) public void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal) { if (loggingEnabled) { final Uri url = request.getUrl(); final String method = request.getMethod(); final boolean redirect = request.isRedirect(); final boolean mainframe = request.isForMainFrame(); final boolean gesture = request.hasGesture(); logger.log(String.format(LOCALE, "%s shouldOverrideUrlLoading() 1/4 CALL : %s %s", SPACE, method, url)); logger.log(String.format(LOCALE, "%s shouldOverrideUrlLoading() 2/4 CALL INFO : redirect=%s, forMainFrame=%s, hasGesture=%s", SPACE, redirect, mainframe, gesture)); logger.log(String.format(LOCALE, "%s shouldOverrideUrlLoading() 3/4 REQ HEADERS: %s", SPACE, request.getRequestHeaders())); logger.log(String.format(LOCALE, "%s shouldOverrideUrlLoading() 4/4 OVERRIDE : %s", SPACE, retVal)); } } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.N) public void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal) { if (loggingEnabled) { final Uri url = request.getUrl(); final String method = request.getMethod(); final boolean redirect = request.isRedirect(); final boolean mainframe = request.isForMainFrame(); final boolean gesture = request.hasGesture(); logger.log(String.format(LOCALE, "%s shouldOverrideUrlLoading() 1/4 CALL : %s %s", SPACE, method, url)); logger.log(String.format(LOCALE, "%s shouldOverrideUrlLoading() 2/4 CALL INFO : redirect=%s, forMainFrame=%s, hasGesture=%s", SPACE, redirect, mainframe, gesture)); logger.log(String.format(LOCALE, "%s shouldOverrideUrlLoading() 3/4 REQ HEADERS: %s", SPACE, request.getRequestHeaders())); logger.log(String.format(LOCALE, "%s shouldOverrideUrlLoading() 4/4 OVERRIDE : %s", SPACE, retVal)); } } } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.N) public void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal) { if (loggingEnabled) { final Uri url = request.getUrl(); final String method = request.getMethod(); final boolean redirect = request.isRedirect(); final boolean mainframe = request.isForMainFrame(); final boolean gesture = request.hasGesture(); logger.log(String.format(LOCALE, "%s shouldOverrideUrlLoading() 1/4 CALL : %s %s", SPACE, method, url)); logger.log(String.format(LOCALE, "%s shouldOverrideUrlLoading() 2/4 CALL INFO : redirect=%s, forMainFrame=%s, hasGesture=%s", SPACE, redirect, mainframe, gesture)); logger.log(String.format(LOCALE, "%s shouldOverrideUrlLoading() 3/4 REQ HEADERS: %s", SPACE, request.getRequestHeaders())); logger.log(String.format(LOCALE, "%s shouldOverrideUrlLoading() 4/4 OVERRIDE : %s", SPACE, retVal)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.N) public void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal) { if (loggingEnabled) { final Uri url = request.getUrl(); final String method = request.getMethod(); final boolean redirect = request.isRedirect(); final boolean mainframe = request.isForMainFrame(); final boolean gesture = request.hasGesture(); logger.log(String.format(LOCALE, "%s shouldOverrideUrlLoading() 1/4 CALL : %s %s", SPACE, method, url)); logger.log(String.format(LOCALE, "%s shouldOverrideUrlLoading() 2/4 CALL INFO : redirect=%s, forMainFrame=%s, hasGesture=%s", SPACE, redirect, mainframe, gesture)); logger.log(String.format(LOCALE, "%s shouldOverrideUrlLoading() 3/4 REQ HEADERS: %s", SPACE, request.getRequestHeaders())); logger.log(String.format(LOCALE, "%s shouldOverrideUrlLoading() 4/4 OVERRIDE : %s", SPACE, retVal)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.N) public void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal) { if (loggingEnabled) { final Uri url = request.getUrl(); final String method = request.getMethod(); final boolean redirect = request.isRedirect(); final boolean mainframe = request.isForMainFrame(); final boolean gesture = request.hasGesture(); logger.log(String.format(LOCALE, "%s shouldOverrideUrlLoading() 1/4 CALL : %s %s", SPACE, method, url)); logger.log(String.format(LOCALE, "%s shouldOverrideUrlLoading() 2/4 CALL INFO : redirect=%s, forMainFrame=%s, hasGesture=%s", SPACE, redirect, mainframe, gesture)); logger.log(String.format(LOCALE, "%s shouldOverrideUrlLoading() 3/4 REQ HEADERS: %s", SPACE, request.getRequestHeaders())); logger.log(String.format(LOCALE, "%s shouldOverrideUrlLoading() 4/4 OVERRIDE : %s", SPACE, retVal)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onLoadResource() { final String url = "foo"; logger.setLoggingEnabled(false); logger.onLoadResource(webView, url); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.onLoadResource(webView, url); verifyLogEngine().log(Mockito.anyString()); } | public void onLoadResource(WebView view, String url) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onLoadResource() %s", SPACE, url)); } } | DebugWebViewClientLogger implements LogControl { public void onLoadResource(WebView view, String url) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onLoadResource() %s", SPACE, url)); } } } | DebugWebViewClientLogger implements LogControl { public void onLoadResource(WebView view, String url) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onLoadResource() %s", SPACE, url)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); } | DebugWebViewClientLogger implements LogControl { public void onLoadResource(WebView view, String url) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onLoadResource() %s", SPACE, url)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClientLogger implements LogControl { public void onLoadResource(WebView view, String url) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onLoadResource() %s", SPACE, url)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onPageCommitVisible() { final String url = "foo"; logger.setLoggingEnabled(false); logger.onPageCommitVisible(webView, url); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.onPageCommitVisible(webView, url); verifyLogEngine().log(Mockito.anyString()); } | @TargetApi(Build.VERSION_CODES.M) public void onPageCommitVisible(WebView view, String url) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onPageCommitVisible() %s", SPACE, url)); } } | DebugWebViewClientLogger implements LogControl { @TargetApi(Build.VERSION_CODES.M) public void onPageCommitVisible(WebView view, String url) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onPageCommitVisible() %s", SPACE, url)); } } } | DebugWebViewClientLogger implements LogControl { @TargetApi(Build.VERSION_CODES.M) public void onPageCommitVisible(WebView view, String url) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onPageCommitVisible() %s", SPACE, url)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); } | DebugWebViewClientLogger implements LogControl { @TargetApi(Build.VERSION_CODES.M) public void onPageCommitVisible(WebView view, String url) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onPageCommitVisible() %s", SPACE, url)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClientLogger implements LogControl { @TargetApi(Build.VERSION_CODES.M) public void onPageCommitVisible(WebView view, String url) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onPageCommitVisible() %s", SPACE, url)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void shouldInterceptRequest() { final String url = "foo"; final WebResourceResponse response = Mockito.mock(WebResourceResponse.class); logger.setLoggingEnabled(false); logger.shouldInterceptRequest(webView, url, response); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.shouldInterceptRequest(webView, url, response); verifyLogEngine().log(Mockito.anyString()); } | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal) { if (loggingEnabled) { final String result = retVal == null ? "false" : StringUtils.toString(retVal); logger.log(String.format(LOCALE, "%s shouldInterceptRequest() 1/2 CALL : %s", SPACE, url)); logger.log(String.format(LOCALE, "%s shouldInterceptRequest() 2/2 OVERRIDE: %s", SPACE, url, result)); } } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal) { if (loggingEnabled) { final String result = retVal == null ? "false" : StringUtils.toString(retVal); logger.log(String.format(LOCALE, "%s shouldInterceptRequest() 1/2 CALL : %s", SPACE, url)); logger.log(String.format(LOCALE, "%s shouldInterceptRequest() 2/2 OVERRIDE: %s", SPACE, url, result)); } } } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal) { if (loggingEnabled) { final String result = retVal == null ? "false" : StringUtils.toString(retVal); logger.log(String.format(LOCALE, "%s shouldInterceptRequest() 1/2 CALL : %s", SPACE, url)); logger.log(String.format(LOCALE, "%s shouldInterceptRequest() 2/2 OVERRIDE: %s", SPACE, url, result)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal) { if (loggingEnabled) { final String result = retVal == null ? "false" : StringUtils.toString(retVal); logger.log(String.format(LOCALE, "%s shouldInterceptRequest() 1/2 CALL : %s", SPACE, url)); logger.log(String.format(LOCALE, "%s shouldInterceptRequest() 2/2 OVERRIDE: %s", SPACE, url, result)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal) { if (loggingEnabled) { final String result = retVal == null ? "false" : StringUtils.toString(retVal); logger.log(String.format(LOCALE, "%s shouldInterceptRequest() 1/2 CALL : %s", SPACE, url)); logger.log(String.format(LOCALE, "%s shouldInterceptRequest() 2/2 OVERRIDE: %s", SPACE, url, result)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onReceivedHttpError() { final WebResourceRequest request = Mockito.mock(WebResourceRequest.class); final WebResourceResponse response = Mockito.mock(WebResourceResponse.class); debugClient.onReceivedHttpError(webView, request, response); verifyLogger().onReceivedHttpError(webView, request, response); verifyWrappedClient().onReceivedHttpError(webView, request, response); } | @RequiresApi(api = Build.VERSION_CODES.M) @Override public void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse) { logger.onReceivedHttpError(view, request, errorResponse); client.onReceivedHttpError(view, request, errorResponse); } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.M) @Override public void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse) { logger.onReceivedHttpError(view, request, errorResponse); client.onReceivedHttpError(view, request, errorResponse); } } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.M) @Override public void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse) { logger.onReceivedHttpError(view, request, errorResponse); client.onReceivedHttpError(view, request, errorResponse); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.M) @Override public void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse) { logger.onReceivedHttpError(view, request, errorResponse); client.onReceivedHttpError(view, request, errorResponse); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.M) @Override public void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse) { logger.onReceivedHttpError(view, request, errorResponse); client.onReceivedHttpError(view, request, errorResponse); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onTooManyRedirects() { final Message cancelMsg = Mockito.mock(Message.class); final Message continueMsg = Mockito.mock(Message.class); logger.setLoggingEnabled(false); logger.onTooManyRedirects(webView, cancelMsg, continueMsg); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.onTooManyRedirects(webView, cancelMsg, continueMsg); verifyLogEngine().logError(Mockito.anyString()); } | public void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg) { if (loggingEnabled) { logger.logError(String.format(LOCALE, "%s onTooManyRedirects()", SPACE)); } } | DebugWebViewClientLogger implements LogControl { public void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg) { if (loggingEnabled) { logger.logError(String.format(LOCALE, "%s onTooManyRedirects()", SPACE)); } } } | DebugWebViewClientLogger implements LogControl { public void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg) { if (loggingEnabled) { logger.logError(String.format(LOCALE, "%s onTooManyRedirects()", SPACE)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); } | DebugWebViewClientLogger implements LogControl { public void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg) { if (loggingEnabled) { logger.logError(String.format(LOCALE, "%s onTooManyRedirects()", SPACE)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClientLogger implements LogControl { public void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg) { if (loggingEnabled) { logger.logError(String.format(LOCALE, "%s onTooManyRedirects()", SPACE)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onReceivedHttpAuthRequest() { final HttpAuthHandler handler = Mockito.mock(HttpAuthHandler.class); final String host = "foo"; final String realm = "bar"; logger.setLoggingEnabled(false); logger.onReceivedHttpAuthRequest(webView, handler, host, realm); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.onReceivedHttpAuthRequest(webView, handler, host, realm); verifyLogEngine().logSecurity(Mockito.anyString()); } | public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) { if (loggingEnabled) { logger.logSecurity(String.format(LOCALE, "%s onReceivedHttpAuthRequest() %s %s %s", SPACE, host, realm, handler)); } } | DebugWebViewClientLogger implements LogControl { public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) { if (loggingEnabled) { logger.logSecurity(String.format(LOCALE, "%s onReceivedHttpAuthRequest() %s %s %s", SPACE, host, realm, handler)); } } } | DebugWebViewClientLogger implements LogControl { public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) { if (loggingEnabled) { logger.logSecurity(String.format(LOCALE, "%s onReceivedHttpAuthRequest() %s %s %s", SPACE, host, realm, handler)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); } | DebugWebViewClientLogger implements LogControl { public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) { if (loggingEnabled) { logger.logSecurity(String.format(LOCALE, "%s onReceivedHttpAuthRequest() %s %s %s", SPACE, host, realm, handler)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClientLogger implements LogControl { public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) { if (loggingEnabled) { logger.logSecurity(String.format(LOCALE, "%s onReceivedHttpAuthRequest() %s %s %s", SPACE, host, realm, handler)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onPageStarted() { final String url = "foo"; final Bitmap bitmap = Mockito.mock(Bitmap.class); logger.setLoggingEnabled(false); logger.onPageStarted(webView, url, bitmap); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.onPageStarted(webView, url, bitmap); verifyLogEngine().log(Mockito.anyString()); } | public void onPageStarted(WebView view, String url, Bitmap facIcon) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onPageStarted() %s", IN, url)); } } | DebugWebViewClientLogger implements LogControl { public void onPageStarted(WebView view, String url, Bitmap facIcon) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onPageStarted() %s", IN, url)); } } } | DebugWebViewClientLogger implements LogControl { public void onPageStarted(WebView view, String url, Bitmap facIcon) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onPageStarted() %s", IN, url)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); } | DebugWebViewClientLogger implements LogControl { public void onPageStarted(WebView view, String url, Bitmap facIcon) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onPageStarted() %s", IN, url)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClientLogger implements LogControl { public void onPageStarted(WebView view, String url, Bitmap facIcon) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onPageStarted() %s", IN, url)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onPageFinished() { final String url = "foo"; logger.setLoggingEnabled(false); logger.onPageFinished(webView, url); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.onPageFinished(webView, url); verifyLogEngine().log(Mockito.anyString()); } | public void onPageFinished(WebView view, String url) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onPageFinished() %s", OUT, url)); } } | DebugWebViewClientLogger implements LogControl { public void onPageFinished(WebView view, String url) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onPageFinished() %s", OUT, url)); } } } | DebugWebViewClientLogger implements LogControl { public void onPageFinished(WebView view, String url) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onPageFinished() %s", OUT, url)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); } | DebugWebViewClientLogger implements LogControl { public void onPageFinished(WebView view, String url) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onPageFinished() %s", OUT, url)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClientLogger implements LogControl { public void onPageFinished(WebView view, String url) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onPageFinished() %s", OUT, url)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onReceivedClientCertRequest() { final ClientCertRequest request = Mockito.mock(ClientCertRequest.class); logger.setLoggingEnabled(false); logger.onReceivedClientCertRequest(webView, request); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.onReceivedClientCertRequest(webView, request); verifyLogEngine().logSecurity(Mockito.anyString()); } | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public void onReceivedClientCertRequest(WebView view, ClientCertRequest request) { if (loggingEnabled) { logger.logSecurity(String.format(LOCALE, "%s onReceivedClientCertRequest() %s", SPACE, StringUtils.toString(request))); } } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public void onReceivedClientCertRequest(WebView view, ClientCertRequest request) { if (loggingEnabled) { logger.logSecurity(String.format(LOCALE, "%s onReceivedClientCertRequest() %s", SPACE, StringUtils.toString(request))); } } } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public void onReceivedClientCertRequest(WebView view, ClientCertRequest request) { if (loggingEnabled) { logger.logSecurity(String.format(LOCALE, "%s onReceivedClientCertRequest() %s", SPACE, StringUtils.toString(request))); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public void onReceivedClientCertRequest(WebView view, ClientCertRequest request) { if (loggingEnabled) { logger.logSecurity(String.format(LOCALE, "%s onReceivedClientCertRequest() %s", SPACE, StringUtils.toString(request))); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) public void onReceivedClientCertRequest(WebView view, ClientCertRequest request) { if (loggingEnabled) { logger.logSecurity(String.format(LOCALE, "%s onReceivedClientCertRequest() %s", SPACE, StringUtils.toString(request))); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onFormResubmission() { final Message dontResend = Mockito.mock(Message.class); final Message resend = Mockito.mock(Message.class); logger.setLoggingEnabled(false); logger.onFormResubmission(webView, dontResend, resend); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.onFormResubmission(webView, dontResend, resend); verifyLogEngine().log(Mockito.anyString()); } | public void onFormResubmission(final WebView view, final Message dontResend, final Message resend) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onFormResubmission()", SPACE)); } } | DebugWebViewClientLogger implements LogControl { public void onFormResubmission(final WebView view, final Message dontResend, final Message resend) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onFormResubmission()", SPACE)); } } } | DebugWebViewClientLogger implements LogControl { public void onFormResubmission(final WebView view, final Message dontResend, final Message resend) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onFormResubmission()", SPACE)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); } | DebugWebViewClientLogger implements LogControl { public void onFormResubmission(final WebView view, final Message dontResend, final Message resend) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onFormResubmission()", SPACE)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClientLogger implements LogControl { public void onFormResubmission(final WebView view, final Message dontResend, final Message resend) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onFormResubmission()", SPACE)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void doUpdateVisitedHistory() { final String url = "foo"; final boolean reload = true; logger.setLoggingEnabled(false); logger.doUpdateVisitedHistory(webView, url, reload); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.doUpdateVisitedHistory(webView, url, reload); verifyLogEngine().log(Mockito.anyString()); } | public void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s doUpdateVisitedHistory() %s, isReload: %s", SPACE, url, isReload)); } } | DebugWebViewClientLogger implements LogControl { public void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s doUpdateVisitedHistory() %s, isReload: %s", SPACE, url, isReload)); } } } | DebugWebViewClientLogger implements LogControl { public void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s doUpdateVisitedHistory() %s, isReload: %s", SPACE, url, isReload)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); } | DebugWebViewClientLogger implements LogControl { public void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s doUpdateVisitedHistory() %s, isReload: %s", SPACE, url, isReload)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClientLogger implements LogControl { public void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s doUpdateVisitedHistory() %s, isReload: %s", SPACE, url, isReload)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void shouldOverrideKeyEvent() { final KeyEvent keyEvent = Mockito.mock(KeyEvent.class); logger.setLoggingEnabled(false); logger.setLogKeyEventsEnabled(false); logger.shouldOverrideKeyEvent(webView, keyEvent, false); verifyLogNotCalled(); logger.setLoggingEnabled(false); logger.setLogKeyEventsEnabled(true); logger.shouldOverrideKeyEvent(webView, keyEvent, false); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.setLogKeyEventsEnabled(false); logger.shouldOverrideKeyEvent(webView, keyEvent, false); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.setLogKeyEventsEnabled(true); logger.shouldOverrideKeyEvent(webView, keyEvent, false); verifyLogEngine().logKeyEvent(Mockito.anyString()); } | public void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal) { if (loggingEnabled && logKeyEventsEnabled) { logger.logKeyEvent(String.format(LOCALE, "%s shouldOverrideKeyEvent() 1/2 EVENT : %s", SPACE, event)); logger.logKeyEvent(String.format(LOCALE, "%s shouldOverrideKeyEvent() 2/2 OVERRIDE: %s", SPACE, retVal)); } } | DebugWebViewClientLogger implements LogControl { public void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal) { if (loggingEnabled && logKeyEventsEnabled) { logger.logKeyEvent(String.format(LOCALE, "%s shouldOverrideKeyEvent() 1/2 EVENT : %s", SPACE, event)); logger.logKeyEvent(String.format(LOCALE, "%s shouldOverrideKeyEvent() 2/2 OVERRIDE: %s", SPACE, retVal)); } } } | DebugWebViewClientLogger implements LogControl { public void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal) { if (loggingEnabled && logKeyEventsEnabled) { logger.logKeyEvent(String.format(LOCALE, "%s shouldOverrideKeyEvent() 1/2 EVENT : %s", SPACE, event)); logger.logKeyEvent(String.format(LOCALE, "%s shouldOverrideKeyEvent() 2/2 OVERRIDE: %s", SPACE, retVal)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); } | DebugWebViewClientLogger implements LogControl { public void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal) { if (loggingEnabled && logKeyEventsEnabled) { logger.logKeyEvent(String.format(LOCALE, "%s shouldOverrideKeyEvent() 1/2 EVENT : %s", SPACE, event)); logger.logKeyEvent(String.format(LOCALE, "%s shouldOverrideKeyEvent() 2/2 OVERRIDE: %s", SPACE, retVal)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClientLogger implements LogControl { public void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal) { if (loggingEnabled && logKeyEventsEnabled) { logger.logKeyEvent(String.format(LOCALE, "%s shouldOverrideKeyEvent() 1/2 EVENT : %s", SPACE, event)); logger.logKeyEvent(String.format(LOCALE, "%s shouldOverrideKeyEvent() 2/2 OVERRIDE: %s", SPACE, retVal)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onUnhandledInputEvent() { final InputEvent inputEvent = Mockito.mock(InputEvent.class); logger.setLoggingEnabled(false); logger.setLogKeyEventsEnabled(false); logger.onUnhandledInputEvent(webView, inputEvent); verifyLogNotCalled(); logger.setLoggingEnabled(false); logger.setLogKeyEventsEnabled(true); logger.onUnhandledInputEvent(webView, inputEvent); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.setLogKeyEventsEnabled(false); logger.onUnhandledInputEvent(webView, inputEvent); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.setLogKeyEventsEnabled(true); logger.onUnhandledInputEvent(webView, inputEvent); verifyLogEngine().logKeyEvent(Mockito.anyString()); } | public void onUnhandledInputEvent(final WebView view, final InputEvent event) { if (loggingEnabled && logKeyEventsEnabled) { logger.logKeyEvent(String.format(LOCALE, "%s onUnhandledInputEvent() %s", SPACE, event)); } } | DebugWebViewClientLogger implements LogControl { public void onUnhandledInputEvent(final WebView view, final InputEvent event) { if (loggingEnabled && logKeyEventsEnabled) { logger.logKeyEvent(String.format(LOCALE, "%s onUnhandledInputEvent() %s", SPACE, event)); } } } | DebugWebViewClientLogger implements LogControl { public void onUnhandledInputEvent(final WebView view, final InputEvent event) { if (loggingEnabled && logKeyEventsEnabled) { logger.logKeyEvent(String.format(LOCALE, "%s onUnhandledInputEvent() %s", SPACE, event)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); } | DebugWebViewClientLogger implements LogControl { public void onUnhandledInputEvent(final WebView view, final InputEvent event) { if (loggingEnabled && logKeyEventsEnabled) { logger.logKeyEvent(String.format(LOCALE, "%s onUnhandledInputEvent() %s", SPACE, event)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClientLogger implements LogControl { public void onUnhandledInputEvent(final WebView view, final InputEvent event) { if (loggingEnabled && logKeyEventsEnabled) { logger.logKeyEvent(String.format(LOCALE, "%s onUnhandledInputEvent() %s", SPACE, event)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onUnhandledKeyEvent() { final KeyEvent keyEvent = Mockito.mock(KeyEvent.class); logger.setLoggingEnabled(false); logger.setLogKeyEventsEnabled(false); logger.onUnhandledKeyEvent(webView, keyEvent); verifyLogNotCalled(); logger.setLoggingEnabled(false); logger.setLogKeyEventsEnabled(true); logger.onUnhandledKeyEvent(webView, keyEvent); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.setLogKeyEventsEnabled(false); logger.onUnhandledKeyEvent(webView, keyEvent); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.setLogKeyEventsEnabled(true); logger.onUnhandledKeyEvent(webView, keyEvent); verifyLogEngine().logKeyEvent(Mockito.anyString()); } | public void onUnhandledKeyEvent(final WebView view, final KeyEvent event) { if (loggingEnabled && logKeyEventsEnabled) { logger.logKeyEvent(String.format(LOCALE, "%s onUnhandledKeyEvent() %s", SPACE, event)); } } | DebugWebViewClientLogger implements LogControl { public void onUnhandledKeyEvent(final WebView view, final KeyEvent event) { if (loggingEnabled && logKeyEventsEnabled) { logger.logKeyEvent(String.format(LOCALE, "%s onUnhandledKeyEvent() %s", SPACE, event)); } } } | DebugWebViewClientLogger implements LogControl { public void onUnhandledKeyEvent(final WebView view, final KeyEvent event) { if (loggingEnabled && logKeyEventsEnabled) { logger.logKeyEvent(String.format(LOCALE, "%s onUnhandledKeyEvent() %s", SPACE, event)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); } | DebugWebViewClientLogger implements LogControl { public void onUnhandledKeyEvent(final WebView view, final KeyEvent event) { if (loggingEnabled && logKeyEventsEnabled) { logger.logKeyEvent(String.format(LOCALE, "%s onUnhandledKeyEvent() %s", SPACE, event)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClientLogger implements LogControl { public void onUnhandledKeyEvent(final WebView view, final KeyEvent event) { if (loggingEnabled && logKeyEventsEnabled) { logger.logKeyEvent(String.format(LOCALE, "%s onUnhandledKeyEvent() %s", SPACE, event)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onReceivedSslError() { final SslErrorHandler errorHandler = Mockito.mock(SslErrorHandler.class); final SslError sslError = Mockito.mock(SslError.class); debugClient.onReceivedSslError(webView, errorHandler, sslError); verifyLogger().onReceivedSslError(webView, errorHandler, sslError); verifyWrappedClient().onReceivedSslError(webView, errorHandler, sslError); } | @Override public void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error) { logger.onReceivedSslError(view, handler, error); client.onReceivedSslError(view, handler, error); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error) { logger.onReceivedSslError(view, handler, error); client.onReceivedSslError(view, handler, error); } } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error) { logger.onReceivedSslError(view, handler, error); client.onReceivedSslError(view, handler, error); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error) { logger.onReceivedSslError(view, handler, error); client.onReceivedSslError(view, handler, error); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error) { logger.onReceivedSslError(view, handler, error); client.onReceivedSslError(view, handler, error); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onScaleChanged() { final float oldScale = 1.0f; final float newScale = 2.0f; logger.setLoggingEnabled(false); logger.onScaleChanged(webView, oldScale, newScale); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.onScaleChanged(webView, oldScale, newScale); verifyLogEngine().log(Mockito.anyString()); } | public void onScaleChanged(final WebView view, final float oldScale, final float newScale) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onScaleChanged() old: %s, new: %s", SPACE, oldScale, newScale)); } } | DebugWebViewClientLogger implements LogControl { public void onScaleChanged(final WebView view, final float oldScale, final float newScale) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onScaleChanged() old: %s, new: %s", SPACE, oldScale, newScale)); } } } | DebugWebViewClientLogger implements LogControl { public void onScaleChanged(final WebView view, final float oldScale, final float newScale) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onScaleChanged() old: %s, new: %s", SPACE, oldScale, newScale)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); } | DebugWebViewClientLogger implements LogControl { public void onScaleChanged(final WebView view, final float oldScale, final float newScale) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onScaleChanged() old: %s, new: %s", SPACE, oldScale, newScale)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClientLogger implements LogControl { public void onScaleChanged(final WebView view, final float oldScale, final float newScale) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onScaleChanged() old: %s, new: %s", SPACE, oldScale, newScale)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onReceivedLoginRequest() { final String realm = "realm"; final String account = "account"; final String args = "args"; logger.setLoggingEnabled(false); logger.onReceivedLoginRequest(webView, realm, account, args); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.onReceivedLoginRequest(webView, realm, account, args); verifyLogEngine().logSecurity(Mockito.anyString()); } | public void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args) { if (loggingEnabled) { logger.logSecurity(String.format(LOCALE, "%s onReceivedLoginRequest() %s, %s, %s", SPACE, realm, account, args)); } } | DebugWebViewClientLogger implements LogControl { public void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args) { if (loggingEnabled) { logger.logSecurity(String.format(LOCALE, "%s onReceivedLoginRequest() %s, %s, %s", SPACE, realm, account, args)); } } } | DebugWebViewClientLogger implements LogControl { public void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args) { if (loggingEnabled) { logger.logSecurity(String.format(LOCALE, "%s onReceivedLoginRequest() %s, %s, %s", SPACE, realm, account, args)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); } | DebugWebViewClientLogger implements LogControl { public void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args) { if (loggingEnabled) { logger.logSecurity(String.format(LOCALE, "%s onReceivedLoginRequest() %s, %s, %s", SPACE, realm, account, args)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClientLogger implements LogControl { public void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args) { if (loggingEnabled) { logger.logSecurity(String.format(LOCALE, "%s onReceivedLoginRequest() %s, %s, %s", SPACE, realm, account, args)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onRenderProcessGone() { final RenderProcessGoneDetail detail = Mockito.mock(RenderProcessGoneDetail.class); logger.setLoggingEnabled(false); logger.onRenderProcessGone(webView, detail, false); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.onRenderProcessGone(webView, detail, false); verifyLogEngine().log(Mockito.anyString()); } | @RequiresApi(api = Build.VERSION_CODES.O) public void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onRenderProcessGone() 1/2 DETAIL: %s", SPACE, detail)); logger.log(String.format(LOCALE, "%s onRenderProcessGone() 2/2 RESULT: %s", SPACE, retVal)); } } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.O) public void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onRenderProcessGone() 1/2 DETAIL: %s", SPACE, detail)); logger.log(String.format(LOCALE, "%s onRenderProcessGone() 2/2 RESULT: %s", SPACE, retVal)); } } } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.O) public void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onRenderProcessGone() 1/2 DETAIL: %s", SPACE, detail)); logger.log(String.format(LOCALE, "%s onRenderProcessGone() 2/2 RESULT: %s", SPACE, retVal)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.O) public void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onRenderProcessGone() 1/2 DETAIL: %s", SPACE, detail)); logger.log(String.format(LOCALE, "%s onRenderProcessGone() 2/2 RESULT: %s", SPACE, retVal)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.O) public void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal) { if (loggingEnabled) { logger.log(String.format(LOCALE, "%s onRenderProcessGone() 1/2 DETAIL: %s", SPACE, detail)); logger.log(String.format(LOCALE, "%s onRenderProcessGone() 2/2 RESULT: %s", SPACE, retVal)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onSafeBrowsingHit() { final WebResourceRequest request = Mockito.mock(WebResourceRequest.class); final SafeBrowsingResponse callback = Mockito.mock(SafeBrowsingResponse.class); final int threatType = -1; logger.setLoggingEnabled(false); logger.onSafeBrowsingHit(webView, request, threatType, callback); verifyLogNotCalled(); logger.setLoggingEnabled(true); logger.onSafeBrowsingHit(webView, request, threatType, callback); verifyLogEngine().log(Mockito.anyString()); } | @RequiresApi(api = Build.VERSION_CODES.O_MR1) public void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback) { if (loggingEnabled) { final Uri url = request.getUrl(); final String method = request.getMethod(); final String threat = StringUtils.resolveThreatType(threatType); logger.log(String.format(LOCALE, "%s onSafeBrowsingHit() 1/3 CALL : %s %s", SPACE, method, url)); logger.log(String.format(LOCALE, "%s onSafeBrowsingHit() 2/3 REQ HEADERS: %s", SPACE, request.getRequestHeaders())); logger.log(String.format(LOCALE, "%s onSafeBrowsingHit() 3/3 THREAT : %s", SPACE, threat)); } } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.O_MR1) public void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback) { if (loggingEnabled) { final Uri url = request.getUrl(); final String method = request.getMethod(); final String threat = StringUtils.resolveThreatType(threatType); logger.log(String.format(LOCALE, "%s onSafeBrowsingHit() 1/3 CALL : %s %s", SPACE, method, url)); logger.log(String.format(LOCALE, "%s onSafeBrowsingHit() 2/3 REQ HEADERS: %s", SPACE, request.getRequestHeaders())); logger.log(String.format(LOCALE, "%s onSafeBrowsingHit() 3/3 THREAT : %s", SPACE, threat)); } } } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.O_MR1) public void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback) { if (loggingEnabled) { final Uri url = request.getUrl(); final String method = request.getMethod(); final String threat = StringUtils.resolveThreatType(threatType); logger.log(String.format(LOCALE, "%s onSafeBrowsingHit() 1/3 CALL : %s %s", SPACE, method, url)); logger.log(String.format(LOCALE, "%s onSafeBrowsingHit() 2/3 REQ HEADERS: %s", SPACE, request.getRequestHeaders())); logger.log(String.format(LOCALE, "%s onSafeBrowsingHit() 3/3 THREAT : %s", SPACE, threat)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.O_MR1) public void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback) { if (loggingEnabled) { final Uri url = request.getUrl(); final String method = request.getMethod(); final String threat = StringUtils.resolveThreatType(threatType); logger.log(String.format(LOCALE, "%s onSafeBrowsingHit() 1/3 CALL : %s %s", SPACE, method, url)); logger.log(String.format(LOCALE, "%s onSafeBrowsingHit() 2/3 REQ HEADERS: %s", SPACE, request.getRequestHeaders())); logger.log(String.format(LOCALE, "%s onSafeBrowsingHit() 3/3 THREAT : %s", SPACE, threat)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClientLogger implements LogControl { @RequiresApi(api = Build.VERSION_CODES.O_MR1) public void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback) { if (loggingEnabled) { final Uri url = request.getUrl(); final String method = request.getMethod(); final String threat = StringUtils.resolveThreatType(threatType); logger.log(String.format(LOCALE, "%s onSafeBrowsingHit() 1/3 CALL : %s %s", SPACE, method, url)); logger.log(String.format(LOCALE, "%s onSafeBrowsingHit() 2/3 REQ HEADERS: %s", SPACE, request.getRequestHeaders())); logger.log(String.format(LOCALE, "%s onSafeBrowsingHit() 3/3 THREAT : %s", SPACE, threat)); } } DebugWebViewClientLogger(); DebugWebViewClientLogger(@NonNull final String tag); @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) protected DebugWebViewClientLogger(@NonNull final LogEngine logEngine); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) void shouldOverrideUrlLoading(WebView view, WebResourceRequest request, boolean retVal); void shouldOverrideUrlLoading(WebView view, String url, boolean retVal); void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, String url, WebResourceResponse retVal); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void shouldInterceptRequest(WebView view, WebResourceRequest request, final WebResourceResponse retVal); void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); void onPageStarted(WebView view, String url, Bitmap facIcon); void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) void onReceivedClientCertRequest(WebView view, ClientCertRequest request); void onFormResubmission(final WebView view, final Message dontResend, final Message resend); void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); void shouldOverrideKeyEvent(final WebView view, final KeyEvent event, boolean retVal); void onUnhandledInputEvent(final WebView view, final InputEvent event); void onUnhandledKeyEvent(final WebView view, final KeyEvent event); void onScaleChanged(final WebView view, final float oldScale, final float newScale); void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) void onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail, boolean retVal); @RequiresApi(api = Build.VERSION_CODES.O_MR1) void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void shouldOverrideUrlLoading() { final String url = "foo"; final boolean retVal = debugClient.shouldOverrideUrlLoading(webView, url); verifyLogger().shouldOverrideUrlLoading(webView, url, retVal); verifyWrappedClient().shouldOverrideUrlLoading(webView, url); } | @RequiresApi(api = Build.VERSION_CODES.N) @Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { final boolean retVal = client.shouldOverrideUrlLoading(view, request); logger.shouldOverrideUrlLoading(view, request, retVal); return retVal; } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.N) @Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { final boolean retVal = client.shouldOverrideUrlLoading(view, request); logger.shouldOverrideUrlLoading(view, request, retVal); return retVal; } } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.N) @Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { final boolean retVal = client.shouldOverrideUrlLoading(view, request); logger.shouldOverrideUrlLoading(view, request, retVal); return retVal; } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.N) @Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { final boolean retVal = client.shouldOverrideUrlLoading(view, request); logger.shouldOverrideUrlLoading(view, request, retVal); return retVal; } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.N) @Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { final boolean retVal = client.shouldOverrideUrlLoading(view, request); logger.shouldOverrideUrlLoading(view, request, retVal); return retVal; } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void shouldOverrideUrlLoading1() { final WebResourceRequest request = Mockito.mock(WebResourceRequest.class); final boolean retVal = debugClient.shouldOverrideUrlLoading(webView, request); verifyLogger().shouldOverrideUrlLoading(webView, request, retVal); verifyWrappedClient().shouldOverrideUrlLoading(webView, request); } | @RequiresApi(api = Build.VERSION_CODES.N) @Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { final boolean retVal = client.shouldOverrideUrlLoading(view, request); logger.shouldOverrideUrlLoading(view, request, retVal); return retVal; } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.N) @Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { final boolean retVal = client.shouldOverrideUrlLoading(view, request); logger.shouldOverrideUrlLoading(view, request, retVal); return retVal; } } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.N) @Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { final boolean retVal = client.shouldOverrideUrlLoading(view, request); logger.shouldOverrideUrlLoading(view, request, retVal); return retVal; } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.N) @Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { final boolean retVal = client.shouldOverrideUrlLoading(view, request); logger.shouldOverrideUrlLoading(view, request, retVal); return retVal; } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.N) @Override public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { final boolean retVal = client.shouldOverrideUrlLoading(view, request); logger.shouldOverrideUrlLoading(view, request, retVal); return retVal; } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onLoadResource() { final String url = "foo"; debugClient.onLoadResource(webView, url); verifyLogger().onLoadResource(webView, url); verifyWrappedClient().onLoadResource(webView, url); } | @Override public void onLoadResource(WebView view, String url) { logger.onLoadResource(view, url); client.onLoadResource(view, url); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onLoadResource(WebView view, String url) { logger.onLoadResource(view, url); client.onLoadResource(view, url); } } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onLoadResource(WebView view, String url) { logger.onLoadResource(view, url); client.onLoadResource(view, url); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onLoadResource(WebView view, String url) { logger.onLoadResource(view, url); client.onLoadResource(view, url); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClient extends WebViewClient implements LogControl { @Override public void onLoadResource(WebView view, String url) { logger.onLoadResource(view, url); client.onLoadResource(view, url); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void onPageCommitVisible() { final String url = "foo"; debugClient.onPageCommitVisible(webView, url); verifyLogger().onPageCommitVisible(webView, url); verifyWrappedClient().onPageCommitVisible(webView, url); } | @TargetApi(Build.VERSION_CODES.M) @Override public void onPageCommitVisible(WebView view, String url) { logger.onPageCommitVisible(view, url); client.onPageCommitVisible(view, url); } | DebugWebViewClient extends WebViewClient implements LogControl { @TargetApi(Build.VERSION_CODES.M) @Override public void onPageCommitVisible(WebView view, String url) { logger.onPageCommitVisible(view, url); client.onPageCommitVisible(view, url); } } | DebugWebViewClient extends WebViewClient implements LogControl { @TargetApi(Build.VERSION_CODES.M) @Override public void onPageCommitVisible(WebView view, String url) { logger.onPageCommitVisible(view, url); client.onPageCommitVisible(view, url); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); } | DebugWebViewClient extends WebViewClient implements LogControl { @TargetApi(Build.VERSION_CODES.M) @Override public void onPageCommitVisible(WebView view, String url) { logger.onPageCommitVisible(view, url); client.onPageCommitVisible(view, url); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClient extends WebViewClient implements LogControl { @TargetApi(Build.VERSION_CODES.M) @Override public void onPageCommitVisible(WebView view, String url) { logger.onPageCommitVisible(view, url); client.onPageCommitVisible(view, url); } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void shouldInterceptRequest() { final String url = "foo"; final WebResourceResponse retVal = debugClient.shouldInterceptRequest(webView, url); verifyLogger().shouldInterceptRequest(webView, url, retVal); verifyWrappedClient().shouldInterceptRequest(webView, url); } | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated public WebResourceResponse shouldInterceptRequest(WebView view, String url) { final WebResourceResponse retVal = client.shouldInterceptRequest(view, url); logger.shouldInterceptRequest(view, url, retVal); return retVal; } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated public WebResourceResponse shouldInterceptRequest(WebView view, String url) { final WebResourceResponse retVal = client.shouldInterceptRequest(view, url); logger.shouldInterceptRequest(view, url, retVal); return retVal; } } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated public WebResourceResponse shouldInterceptRequest(WebView view, String url) { final WebResourceResponse retVal = client.shouldInterceptRequest(view, url); logger.shouldInterceptRequest(view, url, retVal); return retVal; } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated public WebResourceResponse shouldInterceptRequest(WebView view, String url) { final WebResourceResponse retVal = client.shouldInterceptRequest(view, url); logger.shouldInterceptRequest(view, url, retVal); return retVal; } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated public WebResourceResponse shouldInterceptRequest(WebView view, String url) { final WebResourceResponse retVal = client.shouldInterceptRequest(view, url); logger.shouldInterceptRequest(view, url, retVal); return retVal; } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void shouldInterceptRequest_api21() { final WebResourceRequest request = Mockito.mock(WebResourceRequest.class); final WebResourceResponse retVal = debugClient.shouldInterceptRequest(webView, request); verifyLogger().shouldInterceptRequest(webView, request, retVal); verifyWrappedClient().shouldInterceptRequest(webView, request); } | @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated public WebResourceResponse shouldInterceptRequest(WebView view, String url) { final WebResourceResponse retVal = client.shouldInterceptRequest(view, url); logger.shouldInterceptRequest(view, url, retVal); return retVal; } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated public WebResourceResponse shouldInterceptRequest(WebView view, String url) { final WebResourceResponse retVal = client.shouldInterceptRequest(view, url); logger.shouldInterceptRequest(view, url, retVal); return retVal; } } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated public WebResourceResponse shouldInterceptRequest(WebView view, String url) { final WebResourceResponse retVal = client.shouldInterceptRequest(view, url); logger.shouldInterceptRequest(view, url, retVal); return retVal; } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated public WebResourceResponse shouldInterceptRequest(WebView view, String url) { final WebResourceResponse retVal = client.shouldInterceptRequest(view, url); logger.shouldInterceptRequest(view, url, retVal); return retVal; } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } | DebugWebViewClient extends WebViewClient implements LogControl { @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated public WebResourceResponse shouldInterceptRequest(WebView view, String url) { final WebResourceResponse retVal = client.shouldInterceptRequest(view, url); logger.shouldInterceptRequest(view, url, retVal); return retVal; } DebugWebViewClient(); DebugWebViewClient(@NonNull final WebViewClient client); @SuppressWarnings("WeakerAccess") DebugWebViewClient(
@NonNull final WebViewClient client,
@NonNull final DebugWebViewClientLogger logger); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedError(final WebView view, final WebResourceRequest request, final WebResourceError error); @Override @Deprecated void onReceivedError(final WebView view, final int errorCode, final String description, final String failingUrl); @RequiresApi(api = Build.VERSION_CODES.M) @Override void onReceivedHttpError(final WebView view, final WebResourceRequest request, final WebResourceResponse errorResponse); @Override void onReceivedSslError(final WebView view, final SslErrorHandler handler, final SslError error); @RequiresApi(api = Build.VERSION_CODES.N) @Override boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request); @Override boolean shouldOverrideUrlLoading(WebView view, String url); @Override void onLoadResource(WebView view, String url); @TargetApi(Build.VERSION_CODES.M) @Override void onPageCommitVisible(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Deprecated WebResourceResponse shouldInterceptRequest(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request); @Override @Deprecated @SuppressWarnings("deprecation") //for use with older versions void onTooManyRedirects(WebView view, Message cancelMsg, Message continueMsg); @Override void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm); @Override void onPageStarted(WebView view, String url, Bitmap facIcon); @Override void onPageFinished(WebView view, String url); @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override void onReceivedClientCertRequest(WebView view, ClientCertRequest request); @Override void onFormResubmission(final WebView view, final Message dontResend, final Message resend); @Override void doUpdateVisitedHistory(final WebView view, final String url, final boolean isReload); @Override boolean shouldOverrideKeyEvent(final WebView view, final KeyEvent event); @SuppressWarnings("unused") void onUnhandledInputEvent(final WebView view, final InputEvent event); @Override void onUnhandledKeyEvent(final WebView view, final KeyEvent event); @Override void onScaleChanged(final WebView view, final float oldScale, final float newScale); @Override void onReceivedLoginRequest(final WebView view, final String realm, final String account, final String args); @RequiresApi(api = Build.VERSION_CODES.O) @Override boolean onRenderProcessGone(final WebView view, final RenderProcessGoneDetail detail); @RequiresApi(api = Build.VERSION_CODES.O_MR1) @Override void onSafeBrowsingHit(final WebView view, final WebResourceRequest request, final int threatType, final SafeBrowsingResponse callback); @Override boolean isLoggingEnabled(); @Override void setLoggingEnabled(final boolean enabled); @Override boolean isLogKeyEventsEnabled(); @Override void setLogKeyEventsEnabled(final boolean enabled); } |
@Test public void fallbacksCorrectly() { TestServiceData acceptableServiceData = new TestServiceData("my-service1", "test-tag"); TestServiceData unAcceptableServiceData = new TestServiceData("my-service2", "unknown-tag"); CloudConnector testCloudConnector = new TestCloudConnector(acceptableServiceData, unAcceptableServiceData); List<ServiceInfo> serviceInfos = testCloudConnector.getServiceInfos(); assertNotNull(serviceInfos); assertEquals(2, serviceInfos.size()); assertThat(serviceInfos.get(0), is(instanceOf(TestServiceInfo.class))); assertThat(serviceInfos.get(0), is(instanceOf(BaseServiceInfo.class))); } | @Override public List<ServiceInfo> getServiceInfos() { List<ServiceInfo> serviceInfos = new ArrayList<ServiceInfo>(); for (SD serviceData : getServicesData()) { serviceInfos.add(getServiceInfo(serviceData)); } return serviceInfos; } | AbstractCloudConnector implements CloudConnector { @Override public List<ServiceInfo> getServiceInfos() { List<ServiceInfo> serviceInfos = new ArrayList<ServiceInfo>(); for (SD serviceData : getServicesData()) { serviceInfos.add(getServiceInfo(serviceData)); } return serviceInfos; } } | AbstractCloudConnector implements CloudConnector { @Override public List<ServiceInfo> getServiceInfos() { List<ServiceInfo> serviceInfos = new ArrayList<ServiceInfo>(); for (SD serviceData : getServicesData()) { serviceInfos.add(getServiceInfo(serviceData)); } return serviceInfos; } AbstractCloudConnector(Class<? extends ServiceInfoCreator<? extends ServiceInfo, ?>> serviceInfoCreatorClass); } | AbstractCloudConnector implements CloudConnector { @Override public List<ServiceInfo> getServiceInfos() { List<ServiceInfo> serviceInfos = new ArrayList<ServiceInfo>(); for (SD serviceData : getServicesData()) { serviceInfos.add(getServiceInfo(serviceData)); } return serviceInfos; } AbstractCloudConnector(Class<? extends ServiceInfoCreator<? extends ServiceInfo, ?>> serviceInfoCreatorClass); @Override List<ServiceInfo> getServiceInfos(); } | AbstractCloudConnector implements CloudConnector { @Override public List<ServiceInfo> getServiceInfos() { List<ServiceInfo> serviceInfos = new ArrayList<ServiceInfo>(); for (SD serviceData : getServicesData()) { serviceInfos.add(getServiceInfo(serviceData)); } return serviceInfos; } AbstractCloudConnector(Class<? extends ServiceInfoCreator<? extends ServiceInfo, ?>> serviceInfoCreatorClass); @Override List<ServiceInfo> getServiceInfos(); } |
@Test public void jdbcUrlWithQueryNoUsernamePassword() { RelationalServiceInfo serviceInfo = createServiceInfo("dbtype: assertEquals("jdbc:jdbcdbtype: } | @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } | RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } } | RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType); RelationalServiceInfo(String id, String uriString, String jdbcUrl, String jdbcUrlDatabaseType); } | RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType); RelationalServiceInfo(String id, String uriString, String jdbcUrl, String jdbcUrlDatabaseType); @ServiceProperty(category = "connection") String getJdbcUrl(); } | RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType); RelationalServiceInfo(String id, String uriString, String jdbcUrl, String jdbcUrlDatabaseType); @ServiceProperty(category = "connection") String getJdbcUrl(); static final String JDBC_PREFIX; } |
@Test public void appProps() { Map<String, Object> appProps = new HashMap<>(); appProps.put("foo", "bar"); appProps.put("users", null); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(new StubApplicationInstanceInfo("instance-id-1", "myapp", appProps)); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); assertEquals("myapp", testCloud.getCloudProperties().get("cloud.application.app-id")); assertEquals("instance-id-1", testCloud.getCloudProperties().get("cloud.application.instance-id")); assertEquals("bar", testCloud.getCloudProperties().get("cloud.application.foo")); } | public Properties getCloudProperties() { Map<String, List<ServiceInfo>> mappedServiceInfos = new HashMap<>(); for (ServiceInfo serviceInfo : getServiceInfos()) { String key = getServiceLabel(serviceInfo); List<ServiceInfo> serviceInfosForLabel = mappedServiceInfos.computeIfAbsent(key, k -> new ArrayList<>()); serviceInfosForLabel.add(serviceInfo); } final String servicePropKeyLead = "cloud.services."; Properties cloudProperties = new Properties(); for (Entry<String, List<ServiceInfo>> mappedServiceInfo : mappedServiceInfos.entrySet()) { List<ServiceInfo> serviceInfos = mappedServiceInfo.getValue(); for (ServiceInfo serviceInfo : serviceInfos) { String idBasedKey = servicePropKeyLead + serviceInfo.getId(); cloudProperties.putAll(getServiceProperties(idBasedKey, serviceInfo)); if (serviceInfos.size() == 1) { String labelBasedKey = servicePropKeyLead + mappedServiceInfo.getKey(); cloudProperties.putAll(getServiceProperties(labelBasedKey, serviceInfo)); } } } cloudProperties.putAll(getAppProperties()); return cloudProperties; } | Cloud { public Properties getCloudProperties() { Map<String, List<ServiceInfo>> mappedServiceInfos = new HashMap<>(); for (ServiceInfo serviceInfo : getServiceInfos()) { String key = getServiceLabel(serviceInfo); List<ServiceInfo> serviceInfosForLabel = mappedServiceInfos.computeIfAbsent(key, k -> new ArrayList<>()); serviceInfosForLabel.add(serviceInfo); } final String servicePropKeyLead = "cloud.services."; Properties cloudProperties = new Properties(); for (Entry<String, List<ServiceInfo>> mappedServiceInfo : mappedServiceInfos.entrySet()) { List<ServiceInfo> serviceInfos = mappedServiceInfo.getValue(); for (ServiceInfo serviceInfo : serviceInfos) { String idBasedKey = servicePropKeyLead + serviceInfo.getId(); cloudProperties.putAll(getServiceProperties(idBasedKey, serviceInfo)); if (serviceInfos.size() == 1) { String labelBasedKey = servicePropKeyLead + mappedServiceInfo.getKey(); cloudProperties.putAll(getServiceProperties(labelBasedKey, serviceInfo)); } } } cloudProperties.putAll(getAppProperties()); return cloudProperties; } } | Cloud { public Properties getCloudProperties() { Map<String, List<ServiceInfo>> mappedServiceInfos = new HashMap<>(); for (ServiceInfo serviceInfo : getServiceInfos()) { String key = getServiceLabel(serviceInfo); List<ServiceInfo> serviceInfosForLabel = mappedServiceInfos.computeIfAbsent(key, k -> new ArrayList<>()); serviceInfosForLabel.add(serviceInfo); } final String servicePropKeyLead = "cloud.services."; Properties cloudProperties = new Properties(); for (Entry<String, List<ServiceInfo>> mappedServiceInfo : mappedServiceInfos.entrySet()) { List<ServiceInfo> serviceInfos = mappedServiceInfo.getValue(); for (ServiceInfo serviceInfo : serviceInfos) { String idBasedKey = servicePropKeyLead + serviceInfo.getId(); cloudProperties.putAll(getServiceProperties(idBasedKey, serviceInfo)); if (serviceInfos.size() == 1) { String labelBasedKey = servicePropKeyLead + mappedServiceInfo.getKey(); cloudProperties.putAll(getServiceProperties(labelBasedKey, serviceInfo)); } } } cloudProperties.putAll(getAppProperties()); return cloudProperties; } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); } | Cloud { public Properties getCloudProperties() { Map<String, List<ServiceInfo>> mappedServiceInfos = new HashMap<>(); for (ServiceInfo serviceInfo : getServiceInfos()) { String key = getServiceLabel(serviceInfo); List<ServiceInfo> serviceInfosForLabel = mappedServiceInfos.computeIfAbsent(key, k -> new ArrayList<>()); serviceInfosForLabel.add(serviceInfo); } final String servicePropKeyLead = "cloud.services."; Properties cloudProperties = new Properties(); for (Entry<String, List<ServiceInfo>> mappedServiceInfo : mappedServiceInfos.entrySet()) { List<ServiceInfo> serviceInfos = mappedServiceInfo.getValue(); for (ServiceInfo serviceInfo : serviceInfos) { String idBasedKey = servicePropKeyLead + serviceInfo.getId(); cloudProperties.putAll(getServiceProperties(idBasedKey, serviceInfo)); if (serviceInfos.size() == 1) { String labelBasedKey = servicePropKeyLead + mappedServiceInfo.getKey(); cloudProperties.putAll(getServiceProperties(labelBasedKey, serviceInfo)); } } } cloudProperties.putAll(getAppProperties()); return cloudProperties; } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } | Cloud { public Properties getCloudProperties() { Map<String, List<ServiceInfo>> mappedServiceInfos = new HashMap<>(); for (ServiceInfo serviceInfo : getServiceInfos()) { String key = getServiceLabel(serviceInfo); List<ServiceInfo> serviceInfosForLabel = mappedServiceInfos.computeIfAbsent(key, k -> new ArrayList<>()); serviceInfosForLabel.add(serviceInfo); } final String servicePropKeyLead = "cloud.services."; Properties cloudProperties = new Properties(); for (Entry<String, List<ServiceInfo>> mappedServiceInfo : mappedServiceInfos.entrySet()) { List<ServiceInfo> serviceInfos = mappedServiceInfo.getValue(); for (ServiceInfo serviceInfo : serviceInfos) { String idBasedKey = servicePropKeyLead + serviceInfo.getId(); cloudProperties.putAll(getServiceProperties(idBasedKey, serviceInfo)); if (serviceInfos.size() == 1) { String labelBasedKey = servicePropKeyLead + mappedServiceInfo.getKey(); cloudProperties.putAll(getServiceProperties(labelBasedKey, serviceInfo)); } } } cloudProperties.putAll(getAppProperties()); return cloudProperties; } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } |
@Test public void appPropsWithNullValues() { StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(new StubApplicationInstanceInfo(null, null, null)); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); assertNull(testCloud.getCloudProperties().get("cloud.application.app-id")); assertNull(testCloud.getCloudProperties().get("cloud.application.instance-id")); } | public Properties getCloudProperties() { Map<String, List<ServiceInfo>> mappedServiceInfos = new HashMap<>(); for (ServiceInfo serviceInfo : getServiceInfos()) { String key = getServiceLabel(serviceInfo); List<ServiceInfo> serviceInfosForLabel = mappedServiceInfos.computeIfAbsent(key, k -> new ArrayList<>()); serviceInfosForLabel.add(serviceInfo); } final String servicePropKeyLead = "cloud.services."; Properties cloudProperties = new Properties(); for (Entry<String, List<ServiceInfo>> mappedServiceInfo : mappedServiceInfos.entrySet()) { List<ServiceInfo> serviceInfos = mappedServiceInfo.getValue(); for (ServiceInfo serviceInfo : serviceInfos) { String idBasedKey = servicePropKeyLead + serviceInfo.getId(); cloudProperties.putAll(getServiceProperties(idBasedKey, serviceInfo)); if (serviceInfos.size() == 1) { String labelBasedKey = servicePropKeyLead + mappedServiceInfo.getKey(); cloudProperties.putAll(getServiceProperties(labelBasedKey, serviceInfo)); } } } cloudProperties.putAll(getAppProperties()); return cloudProperties; } | Cloud { public Properties getCloudProperties() { Map<String, List<ServiceInfo>> mappedServiceInfos = new HashMap<>(); for (ServiceInfo serviceInfo : getServiceInfos()) { String key = getServiceLabel(serviceInfo); List<ServiceInfo> serviceInfosForLabel = mappedServiceInfos.computeIfAbsent(key, k -> new ArrayList<>()); serviceInfosForLabel.add(serviceInfo); } final String servicePropKeyLead = "cloud.services."; Properties cloudProperties = new Properties(); for (Entry<String, List<ServiceInfo>> mappedServiceInfo : mappedServiceInfos.entrySet()) { List<ServiceInfo> serviceInfos = mappedServiceInfo.getValue(); for (ServiceInfo serviceInfo : serviceInfos) { String idBasedKey = servicePropKeyLead + serviceInfo.getId(); cloudProperties.putAll(getServiceProperties(idBasedKey, serviceInfo)); if (serviceInfos.size() == 1) { String labelBasedKey = servicePropKeyLead + mappedServiceInfo.getKey(); cloudProperties.putAll(getServiceProperties(labelBasedKey, serviceInfo)); } } } cloudProperties.putAll(getAppProperties()); return cloudProperties; } } | Cloud { public Properties getCloudProperties() { Map<String, List<ServiceInfo>> mappedServiceInfos = new HashMap<>(); for (ServiceInfo serviceInfo : getServiceInfos()) { String key = getServiceLabel(serviceInfo); List<ServiceInfo> serviceInfosForLabel = mappedServiceInfos.computeIfAbsent(key, k -> new ArrayList<>()); serviceInfosForLabel.add(serviceInfo); } final String servicePropKeyLead = "cloud.services."; Properties cloudProperties = new Properties(); for (Entry<String, List<ServiceInfo>> mappedServiceInfo : mappedServiceInfos.entrySet()) { List<ServiceInfo> serviceInfos = mappedServiceInfo.getValue(); for (ServiceInfo serviceInfo : serviceInfos) { String idBasedKey = servicePropKeyLead + serviceInfo.getId(); cloudProperties.putAll(getServiceProperties(idBasedKey, serviceInfo)); if (serviceInfos.size() == 1) { String labelBasedKey = servicePropKeyLead + mappedServiceInfo.getKey(); cloudProperties.putAll(getServiceProperties(labelBasedKey, serviceInfo)); } } } cloudProperties.putAll(getAppProperties()); return cloudProperties; } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); } | Cloud { public Properties getCloudProperties() { Map<String, List<ServiceInfo>> mappedServiceInfos = new HashMap<>(); for (ServiceInfo serviceInfo : getServiceInfos()) { String key = getServiceLabel(serviceInfo); List<ServiceInfo> serviceInfosForLabel = mappedServiceInfos.computeIfAbsent(key, k -> new ArrayList<>()); serviceInfosForLabel.add(serviceInfo); } final String servicePropKeyLead = "cloud.services."; Properties cloudProperties = new Properties(); for (Entry<String, List<ServiceInfo>> mappedServiceInfo : mappedServiceInfos.entrySet()) { List<ServiceInfo> serviceInfos = mappedServiceInfo.getValue(); for (ServiceInfo serviceInfo : serviceInfos) { String idBasedKey = servicePropKeyLead + serviceInfo.getId(); cloudProperties.putAll(getServiceProperties(idBasedKey, serviceInfo)); if (serviceInfos.size() == 1) { String labelBasedKey = servicePropKeyLead + mappedServiceInfo.getKey(); cloudProperties.putAll(getServiceProperties(labelBasedKey, serviceInfo)); } } } cloudProperties.putAll(getAppProperties()); return cloudProperties; } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } | Cloud { public Properties getCloudProperties() { Map<String, List<ServiceInfo>> mappedServiceInfos = new HashMap<>(); for (ServiceInfo serviceInfo : getServiceInfos()) { String key = getServiceLabel(serviceInfo); List<ServiceInfo> serviceInfosForLabel = mappedServiceInfos.computeIfAbsent(key, k -> new ArrayList<>()); serviceInfosForLabel.add(serviceInfo); } final String servicePropKeyLead = "cloud.services."; Properties cloudProperties = new Properties(); for (Entry<String, List<ServiceInfo>> mappedServiceInfo : mappedServiceInfos.entrySet()) { List<ServiceInfo> serviceInfos = mappedServiceInfo.getValue(); for (ServiceInfo serviceInfo : serviceInfos) { String idBasedKey = servicePropKeyLead + serviceInfo.getId(); cloudProperties.putAll(getServiceProperties(idBasedKey, serviceInfo)); if (serviceInfos.size() == 1) { String labelBasedKey = servicePropKeyLead + mappedServiceInfo.getKey(); cloudProperties.putAll(getServiceProperties(labelBasedKey, serviceInfo)); } } } cloudProperties.putAll(getAppProperties()); return cloudProperties; } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } |
@Test public void serviceConnectorCreationDefaultTypeAndConfig() { StubServiceInfo testServiceInfo = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo); serviceConnectorCreators.add(new StubServiceConnectorCreator()); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); StubServiceConnector connector = testCloud.getServiceConnector(testServiceInfo.getId(), null, null); assertStubService(testServiceInfo, connector, null); } | public <SC> SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { ServiceInfo serviceInfo = getServiceInfo(serviceId); return getServiceConnector(serviceInfo, serviceConnectorType, serviceConnectorConfig); } | Cloud { public <SC> SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { ServiceInfo serviceInfo = getServiceInfo(serviceId); return getServiceConnector(serviceInfo, serviceConnectorType, serviceConnectorConfig); } } | Cloud { public <SC> SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { ServiceInfo serviceInfo = getServiceInfo(serviceId); return getServiceConnector(serviceInfo, serviceConnectorType, serviceConnectorConfig); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); } | Cloud { public <SC> SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { ServiceInfo serviceInfo = getServiceInfo(serviceId); return getServiceConnector(serviceInfo, serviceConnectorType, serviceConnectorConfig); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } | Cloud { public <SC> SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { ServiceInfo serviceInfo = getServiceInfo(serviceId); return getServiceConnector(serviceInfo, serviceConnectorType, serviceConnectorConfig); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } |
@Test public void getSingletonServiceConnectorSingleService() { StubServiceInfo testServiceInfo = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo); serviceConnectorCreators.add(new StubServiceConnectorCreator()); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); StubServiceConnector connector = testCloud.getSingletonServiceConnector(null, null); assertStubService(testServiceInfo, connector, null); } | public <SC> SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { List<ServiceInfo> matchingServiceInfos = getServiceInfos(serviceConnectorType); if (matchingServiceInfos.size() != 1) { throw new CloudException("No unique service matching " + serviceConnectorType + " found. Expected 1, found " + matchingServiceInfos.size()); } ServiceInfo matchingServiceInfo = matchingServiceInfos.get(0); return getServiceConnector(matchingServiceInfo, serviceConnectorType, serviceConnectorConfig); } | Cloud { public <SC> SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { List<ServiceInfo> matchingServiceInfos = getServiceInfos(serviceConnectorType); if (matchingServiceInfos.size() != 1) { throw new CloudException("No unique service matching " + serviceConnectorType + " found. Expected 1, found " + matchingServiceInfos.size()); } ServiceInfo matchingServiceInfo = matchingServiceInfos.get(0); return getServiceConnector(matchingServiceInfo, serviceConnectorType, serviceConnectorConfig); } } | Cloud { public <SC> SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { List<ServiceInfo> matchingServiceInfos = getServiceInfos(serviceConnectorType); if (matchingServiceInfos.size() != 1) { throw new CloudException("No unique service matching " + serviceConnectorType + " found. Expected 1, found " + matchingServiceInfos.size()); } ServiceInfo matchingServiceInfo = matchingServiceInfos.get(0); return getServiceConnector(matchingServiceInfo, serviceConnectorType, serviceConnectorConfig); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); } | Cloud { public <SC> SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { List<ServiceInfo> matchingServiceInfos = getServiceInfos(serviceConnectorType); if (matchingServiceInfos.size() != 1) { throw new CloudException("No unique service matching " + serviceConnectorType + " found. Expected 1, found " + matchingServiceInfos.size()); } ServiceInfo matchingServiceInfo = matchingServiceInfos.get(0); return getServiceConnector(matchingServiceInfo, serviceConnectorType, serviceConnectorConfig); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } | Cloud { public <SC> SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { List<ServiceInfo> matchingServiceInfos = getServiceInfos(serviceConnectorType); if (matchingServiceInfos.size() != 1) { throw new CloudException("No unique service matching " + serviceConnectorType + " found. Expected 1, found " + matchingServiceInfos.size()); } ServiceInfo matchingServiceInfo = matchingServiceInfos.get(0); return getServiceConnector(matchingServiceInfo, serviceConnectorType, serviceConnectorConfig); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } |
@Test(expected=CloudException.class) public void getSingletonServiceConnectorNoService() { StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); testCloud.getSingletonServiceConnector(null, null); } | public <SC> SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { List<ServiceInfo> matchingServiceInfos = getServiceInfos(serviceConnectorType); if (matchingServiceInfos.size() != 1) { throw new CloudException("No unique service matching " + serviceConnectorType + " found. Expected 1, found " + matchingServiceInfos.size()); } ServiceInfo matchingServiceInfo = matchingServiceInfos.get(0); return getServiceConnector(matchingServiceInfo, serviceConnectorType, serviceConnectorConfig); } | Cloud { public <SC> SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { List<ServiceInfo> matchingServiceInfos = getServiceInfos(serviceConnectorType); if (matchingServiceInfos.size() != 1) { throw new CloudException("No unique service matching " + serviceConnectorType + " found. Expected 1, found " + matchingServiceInfos.size()); } ServiceInfo matchingServiceInfo = matchingServiceInfos.get(0); return getServiceConnector(matchingServiceInfo, serviceConnectorType, serviceConnectorConfig); } } | Cloud { public <SC> SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { List<ServiceInfo> matchingServiceInfos = getServiceInfos(serviceConnectorType); if (matchingServiceInfos.size() != 1) { throw new CloudException("No unique service matching " + serviceConnectorType + " found. Expected 1, found " + matchingServiceInfos.size()); } ServiceInfo matchingServiceInfo = matchingServiceInfos.get(0); return getServiceConnector(matchingServiceInfo, serviceConnectorType, serviceConnectorConfig); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); } | Cloud { public <SC> SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { List<ServiceInfo> matchingServiceInfos = getServiceInfos(serviceConnectorType); if (matchingServiceInfos.size() != 1) { throw new CloudException("No unique service matching " + serviceConnectorType + " found. Expected 1, found " + matchingServiceInfos.size()); } ServiceInfo matchingServiceInfo = matchingServiceInfos.get(0); return getServiceConnector(matchingServiceInfo, serviceConnectorType, serviceConnectorConfig); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } | Cloud { public <SC> SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { List<ServiceInfo> matchingServiceInfos = getServiceInfos(serviceConnectorType); if (matchingServiceInfos.size() != 1) { throw new CloudException("No unique service matching " + serviceConnectorType + " found. Expected 1, found " + matchingServiceInfos.size()); } ServiceInfo matchingServiceInfo = matchingServiceInfos.get(0); return getServiceConnector(matchingServiceInfo, serviceConnectorType, serviceConnectorConfig); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } |
@Test(expected=CloudException.class) public void getSingletonServiceConnectorMultipleServices() { StubServiceInfo testServiceInfo1 = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubServiceInfo testServiceInfo2 = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo1, testServiceInfo2); serviceConnectorCreators.add(new StubServiceConnectorCreator()); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); testCloud.getSingletonServiceConnector(null, null); } | public <SC> SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { List<ServiceInfo> matchingServiceInfos = getServiceInfos(serviceConnectorType); if (matchingServiceInfos.size() != 1) { throw new CloudException("No unique service matching " + serviceConnectorType + " found. Expected 1, found " + matchingServiceInfos.size()); } ServiceInfo matchingServiceInfo = matchingServiceInfos.get(0); return getServiceConnector(matchingServiceInfo, serviceConnectorType, serviceConnectorConfig); } | Cloud { public <SC> SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { List<ServiceInfo> matchingServiceInfos = getServiceInfos(serviceConnectorType); if (matchingServiceInfos.size() != 1) { throw new CloudException("No unique service matching " + serviceConnectorType + " found. Expected 1, found " + matchingServiceInfos.size()); } ServiceInfo matchingServiceInfo = matchingServiceInfos.get(0); return getServiceConnector(matchingServiceInfo, serviceConnectorType, serviceConnectorConfig); } } | Cloud { public <SC> SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { List<ServiceInfo> matchingServiceInfos = getServiceInfos(serviceConnectorType); if (matchingServiceInfos.size() != 1) { throw new CloudException("No unique service matching " + serviceConnectorType + " found. Expected 1, found " + matchingServiceInfos.size()); } ServiceInfo matchingServiceInfo = matchingServiceInfos.get(0); return getServiceConnector(matchingServiceInfo, serviceConnectorType, serviceConnectorConfig); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); } | Cloud { public <SC> SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { List<ServiceInfo> matchingServiceInfos = getServiceInfos(serviceConnectorType); if (matchingServiceInfos.size() != 1) { throw new CloudException("No unique service matching " + serviceConnectorType + " found. Expected 1, found " + matchingServiceInfos.size()); } ServiceInfo matchingServiceInfo = matchingServiceInfos.get(0); return getServiceConnector(matchingServiceInfo, serviceConnectorType, serviceConnectorConfig); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } | Cloud { public <SC> SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { List<ServiceInfo> matchingServiceInfos = getServiceInfos(serviceConnectorType); if (matchingServiceInfos.size() != 1) { throw new CloudException("No unique service matching " + serviceConnectorType + " found. Expected 1, found " + matchingServiceInfos.size()); } ServiceInfo matchingServiceInfo = matchingServiceInfos.get(0); return getServiceConnector(matchingServiceInfo, serviceConnectorType, serviceConnectorConfig); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } |
@Test(expected=CloudException.class) public void getSingletonServiceConnectorNoMatchingServiceConnectorCreator() { BaseServiceInfo testServiceInfo = new BaseServiceInfo("user-service"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo); serviceConnectorCreators.add(new StubServiceConnectorCreator()); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); testCloud.getSingletonServiceConnector(StubServiceConnector.class, null); } | public <SC> SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { List<ServiceInfo> matchingServiceInfos = getServiceInfos(serviceConnectorType); if (matchingServiceInfos.size() != 1) { throw new CloudException("No unique service matching " + serviceConnectorType + " found. Expected 1, found " + matchingServiceInfos.size()); } ServiceInfo matchingServiceInfo = matchingServiceInfos.get(0); return getServiceConnector(matchingServiceInfo, serviceConnectorType, serviceConnectorConfig); } | Cloud { public <SC> SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { List<ServiceInfo> matchingServiceInfos = getServiceInfos(serviceConnectorType); if (matchingServiceInfos.size() != 1) { throw new CloudException("No unique service matching " + serviceConnectorType + " found. Expected 1, found " + matchingServiceInfos.size()); } ServiceInfo matchingServiceInfo = matchingServiceInfos.get(0); return getServiceConnector(matchingServiceInfo, serviceConnectorType, serviceConnectorConfig); } } | Cloud { public <SC> SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { List<ServiceInfo> matchingServiceInfos = getServiceInfos(serviceConnectorType); if (matchingServiceInfos.size() != 1) { throw new CloudException("No unique service matching " + serviceConnectorType + " found. Expected 1, found " + matchingServiceInfos.size()); } ServiceInfo matchingServiceInfo = matchingServiceInfos.get(0); return getServiceConnector(matchingServiceInfo, serviceConnectorType, serviceConnectorConfig); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); } | Cloud { public <SC> SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { List<ServiceInfo> matchingServiceInfos = getServiceInfos(serviceConnectorType); if (matchingServiceInfos.size() != 1) { throw new CloudException("No unique service matching " + serviceConnectorType + " found. Expected 1, found " + matchingServiceInfos.size()); } ServiceInfo matchingServiceInfo = matchingServiceInfos.get(0); return getServiceConnector(matchingServiceInfo, serviceConnectorType, serviceConnectorConfig); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } | Cloud { public <SC> SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { List<ServiceInfo> matchingServiceInfos = getServiceInfos(serviceConnectorType); if (matchingServiceInfos.size() != 1) { throw new CloudException("No unique service matching " + serviceConnectorType + " found. Expected 1, found " + matchingServiceInfos.size()); } ServiceInfo matchingServiceInfo = matchingServiceInfos.get(0); return getServiceConnector(matchingServiceInfo, serviceConnectorType, serviceConnectorConfig); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } |
@Test public void serviceConnectorCreationSpecifiedTypeAndConfig() { StubServiceInfo testServiceInfo = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo); serviceConnectorCreators.add(new StubServiceConnectorCreator()); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); StubServiceConnectorConfig config = new StubServiceConnectorConfig("test-config"); StubServiceConnector connector = testCloud.getServiceConnector(testServiceInfo.getId(), StubServiceConnector.class, config); assertStubService(testServiceInfo, connector, config); } | public <SC> SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { ServiceInfo serviceInfo = getServiceInfo(serviceId); return getServiceConnector(serviceInfo, serviceConnectorType, serviceConnectorConfig); } | Cloud { public <SC> SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { ServiceInfo serviceInfo = getServiceInfo(serviceId); return getServiceConnector(serviceInfo, serviceConnectorType, serviceConnectorConfig); } } | Cloud { public <SC> SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { ServiceInfo serviceInfo = getServiceInfo(serviceId); return getServiceConnector(serviceInfo, serviceConnectorType, serviceConnectorConfig); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); } | Cloud { public <SC> SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { ServiceInfo serviceInfo = getServiceInfo(serviceId); return getServiceConnector(serviceInfo, serviceConnectorType, serviceConnectorConfig); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } | Cloud { public <SC> SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig) { ServiceInfo serviceInfo = getServiceInfo(serviceId); return getServiceConnector(serviceInfo, serviceConnectorType, serviceConnectorConfig); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } |
@Test public void serviceInfoNoServices() { StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); assertEquals(0, testCloud.getServiceInfos().size()); assertEquals(0, testCloud.getServiceInfos(StubServiceInfo.class).size()); } | public List<ServiceInfo> getServiceInfos() { return flatten(cloudConnector.getServiceInfos()); } | Cloud { public List<ServiceInfo> getServiceInfos() { return flatten(cloudConnector.getServiceInfos()); } } | Cloud { public List<ServiceInfo> getServiceInfos() { return flatten(cloudConnector.getServiceInfos()); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); } | Cloud { public List<ServiceInfo> getServiceInfos() { return flatten(cloudConnector.getServiceInfos()); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } | Cloud { public List<ServiceInfo> getServiceInfos() { return flatten(cloudConnector.getServiceInfos()); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } |
@Test public void cloudConnectorRegistration() { CloudFactory cloudFactory = new CloudFactory(); List<CloudConnector> registeredConnectors = cloudFactory.getCloudConnectors(); assertEquals("One connector registered", 1, registeredConnectors.size()); assertEquals("Registered connector is stub connector", StubCloudConnector.class, registeredConnectors.get(0).getClass()); } | List<CloudConnector> getCloudConnectors() { return cloudConnectors; } | CloudFactory { List<CloudConnector> getCloudConnectors() { return cloudConnectors; } } | CloudFactory { List<CloudConnector> getCloudConnectors() { return cloudConnectors; } CloudFactory(); } | CloudFactory { List<CloudConnector> getCloudConnectors() { return cloudConnectors; } CloudFactory(); Cloud getCloud(); void registerCloudConnector(CloudConnector cloudConnector); } | CloudFactory { List<CloudConnector> getCloudConnectors() { return cloudConnectors; } CloudFactory(); Cloud getCloud(); void registerCloudConnector(CloudConnector cloudConnector); } |
@Test public void serviceInfoMultipleServicesOfTheSameType() { StubServiceInfo testServiceInfo1 = new StubServiceInfo("test-id1", "test-host", 1000, "test-username", "test-password"); StubServiceInfo testServiceInfo2 = new StubServiceInfo("test-id2", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo1, testServiceInfo2); serviceConnectorCreators.add(new StubServiceConnectorCreator()); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); assertEquals(2, testCloud.getServiceInfos().size()); assertEquals(2, testCloud.getServiceInfos(StubServiceConnector.class).size()); } | public List<ServiceInfo> getServiceInfos() { return flatten(cloudConnector.getServiceInfos()); } | Cloud { public List<ServiceInfo> getServiceInfos() { return flatten(cloudConnector.getServiceInfos()); } } | Cloud { public List<ServiceInfo> getServiceInfos() { return flatten(cloudConnector.getServiceInfos()); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); } | Cloud { public List<ServiceInfo> getServiceInfos() { return flatten(cloudConnector.getServiceInfos()); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } | Cloud { public List<ServiceInfo> getServiceInfos() { return flatten(cloudConnector.getServiceInfos()); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } |
@Test public void getServiceInfoByValidId() { StubServiceInfo testServiceInfo1 = new StubServiceInfo("test-id1", "test-host", 1000, "test-username", "test-password"); StubServiceInfo testServiceInfo2 = new StubServiceInfo("test-id2", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo1, testServiceInfo2); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); assertEquals(testServiceInfo1, testCloud.getServiceInfo(testServiceInfo1.getId())); assertEquals(testServiceInfo2, testCloud.getServiceInfo(testServiceInfo2.getId())); } | public ServiceInfo getServiceInfo(String serviceId) { for (ServiceInfo serviceInfo : getServiceInfos()) { if (serviceInfo.getId().equals(serviceId)) { return serviceInfo; } } throw new CloudException("No service with id " + serviceId + " found"); } | Cloud { public ServiceInfo getServiceInfo(String serviceId) { for (ServiceInfo serviceInfo : getServiceInfos()) { if (serviceInfo.getId().equals(serviceId)) { return serviceInfo; } } throw new CloudException("No service with id " + serviceId + " found"); } } | Cloud { public ServiceInfo getServiceInfo(String serviceId) { for (ServiceInfo serviceInfo : getServiceInfos()) { if (serviceInfo.getId().equals(serviceId)) { return serviceInfo; } } throw new CloudException("No service with id " + serviceId + " found"); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); } | Cloud { public ServiceInfo getServiceInfo(String serviceId) { for (ServiceInfo serviceInfo : getServiceInfos()) { if (serviceInfo.getId().equals(serviceId)) { return serviceInfo; } } throw new CloudException("No service with id " + serviceId + " found"); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } | Cloud { public ServiceInfo getServiceInfo(String serviceId) { for (ServiceInfo serviceInfo : getServiceInfos()) { if (serviceInfo.getId().equals(serviceId)) { return serviceInfo; } } throw new CloudException("No service with id " + serviceId + " found"); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } |
@Test public void servicePropsTwoServicesOfTheSameLabel() { StubServiceInfo testServiceInfo1 = new StubServiceInfo("test-id1", "test-host", 1000, "test-username", "test-password"); StubServiceInfo testServiceInfo2 = new StubServiceInfo("test-id2", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo1, testServiceInfo2); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); Properties cloudProperties = testCloud.getCloudProperties(); assertStubServiceProp("cloud.services.test-id1", testServiceInfo1, cloudProperties); assertStubServiceProp("cloud.services.test-id2", testServiceInfo2, cloudProperties); assertNull(cloudProperties.get("cloud.services.stub.connection.host")); } | public Properties getCloudProperties() { Map<String, List<ServiceInfo>> mappedServiceInfos = new HashMap<>(); for (ServiceInfo serviceInfo : getServiceInfos()) { String key = getServiceLabel(serviceInfo); List<ServiceInfo> serviceInfosForLabel = mappedServiceInfos.computeIfAbsent(key, k -> new ArrayList<>()); serviceInfosForLabel.add(serviceInfo); } final String servicePropKeyLead = "cloud.services."; Properties cloudProperties = new Properties(); for (Entry<String, List<ServiceInfo>> mappedServiceInfo : mappedServiceInfos.entrySet()) { List<ServiceInfo> serviceInfos = mappedServiceInfo.getValue(); for (ServiceInfo serviceInfo : serviceInfos) { String idBasedKey = servicePropKeyLead + serviceInfo.getId(); cloudProperties.putAll(getServiceProperties(idBasedKey, serviceInfo)); if (serviceInfos.size() == 1) { String labelBasedKey = servicePropKeyLead + mappedServiceInfo.getKey(); cloudProperties.putAll(getServiceProperties(labelBasedKey, serviceInfo)); } } } cloudProperties.putAll(getAppProperties()); return cloudProperties; } | Cloud { public Properties getCloudProperties() { Map<String, List<ServiceInfo>> mappedServiceInfos = new HashMap<>(); for (ServiceInfo serviceInfo : getServiceInfos()) { String key = getServiceLabel(serviceInfo); List<ServiceInfo> serviceInfosForLabel = mappedServiceInfos.computeIfAbsent(key, k -> new ArrayList<>()); serviceInfosForLabel.add(serviceInfo); } final String servicePropKeyLead = "cloud.services."; Properties cloudProperties = new Properties(); for (Entry<String, List<ServiceInfo>> mappedServiceInfo : mappedServiceInfos.entrySet()) { List<ServiceInfo> serviceInfos = mappedServiceInfo.getValue(); for (ServiceInfo serviceInfo : serviceInfos) { String idBasedKey = servicePropKeyLead + serviceInfo.getId(); cloudProperties.putAll(getServiceProperties(idBasedKey, serviceInfo)); if (serviceInfos.size() == 1) { String labelBasedKey = servicePropKeyLead + mappedServiceInfo.getKey(); cloudProperties.putAll(getServiceProperties(labelBasedKey, serviceInfo)); } } } cloudProperties.putAll(getAppProperties()); return cloudProperties; } } | Cloud { public Properties getCloudProperties() { Map<String, List<ServiceInfo>> mappedServiceInfos = new HashMap<>(); for (ServiceInfo serviceInfo : getServiceInfos()) { String key = getServiceLabel(serviceInfo); List<ServiceInfo> serviceInfosForLabel = mappedServiceInfos.computeIfAbsent(key, k -> new ArrayList<>()); serviceInfosForLabel.add(serviceInfo); } final String servicePropKeyLead = "cloud.services."; Properties cloudProperties = new Properties(); for (Entry<String, List<ServiceInfo>> mappedServiceInfo : mappedServiceInfos.entrySet()) { List<ServiceInfo> serviceInfos = mappedServiceInfo.getValue(); for (ServiceInfo serviceInfo : serviceInfos) { String idBasedKey = servicePropKeyLead + serviceInfo.getId(); cloudProperties.putAll(getServiceProperties(idBasedKey, serviceInfo)); if (serviceInfos.size() == 1) { String labelBasedKey = servicePropKeyLead + mappedServiceInfo.getKey(); cloudProperties.putAll(getServiceProperties(labelBasedKey, serviceInfo)); } } } cloudProperties.putAll(getAppProperties()); return cloudProperties; } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); } | Cloud { public Properties getCloudProperties() { Map<String, List<ServiceInfo>> mappedServiceInfos = new HashMap<>(); for (ServiceInfo serviceInfo : getServiceInfos()) { String key = getServiceLabel(serviceInfo); List<ServiceInfo> serviceInfosForLabel = mappedServiceInfos.computeIfAbsent(key, k -> new ArrayList<>()); serviceInfosForLabel.add(serviceInfo); } final String servicePropKeyLead = "cloud.services."; Properties cloudProperties = new Properties(); for (Entry<String, List<ServiceInfo>> mappedServiceInfo : mappedServiceInfos.entrySet()) { List<ServiceInfo> serviceInfos = mappedServiceInfo.getValue(); for (ServiceInfo serviceInfo : serviceInfos) { String idBasedKey = servicePropKeyLead + serviceInfo.getId(); cloudProperties.putAll(getServiceProperties(idBasedKey, serviceInfo)); if (serviceInfos.size() == 1) { String labelBasedKey = servicePropKeyLead + mappedServiceInfo.getKey(); cloudProperties.putAll(getServiceProperties(labelBasedKey, serviceInfo)); } } } cloudProperties.putAll(getAppProperties()); return cloudProperties; } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } | Cloud { public Properties getCloudProperties() { Map<String, List<ServiceInfo>> mappedServiceInfos = new HashMap<>(); for (ServiceInfo serviceInfo : getServiceInfos()) { String key = getServiceLabel(serviceInfo); List<ServiceInfo> serviceInfosForLabel = mappedServiceInfos.computeIfAbsent(key, k -> new ArrayList<>()); serviceInfosForLabel.add(serviceInfo); } final String servicePropKeyLead = "cloud.services."; Properties cloudProperties = new Properties(); for (Entry<String, List<ServiceInfo>> mappedServiceInfo : mappedServiceInfos.entrySet()) { List<ServiceInfo> serviceInfos = mappedServiceInfo.getValue(); for (ServiceInfo serviceInfo : serviceInfos) { String idBasedKey = servicePropKeyLead + serviceInfo.getId(); cloudProperties.putAll(getServiceProperties(idBasedKey, serviceInfo)); if (serviceInfos.size() == 1) { String labelBasedKey = servicePropKeyLead + mappedServiceInfo.getKey(); cloudProperties.putAll(getServiceProperties(labelBasedKey, serviceInfo)); } } } cloudProperties.putAll(getAppProperties()); return cloudProperties; } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } |
@Test public void servicePropsOneServiceOfTheSameLabel() { StubServiceInfo testServiceInfo = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); Properties cloudProperties = testCloud.getCloudProperties(); assertStubServiceProp("cloud.services.test-id", testServiceInfo, cloudProperties); assertStubServiceProp("cloud.services.stub", testServiceInfo, cloudProperties); } | public Properties getCloudProperties() { Map<String, List<ServiceInfo>> mappedServiceInfos = new HashMap<>(); for (ServiceInfo serviceInfo : getServiceInfos()) { String key = getServiceLabel(serviceInfo); List<ServiceInfo> serviceInfosForLabel = mappedServiceInfos.computeIfAbsent(key, k -> new ArrayList<>()); serviceInfosForLabel.add(serviceInfo); } final String servicePropKeyLead = "cloud.services."; Properties cloudProperties = new Properties(); for (Entry<String, List<ServiceInfo>> mappedServiceInfo : mappedServiceInfos.entrySet()) { List<ServiceInfo> serviceInfos = mappedServiceInfo.getValue(); for (ServiceInfo serviceInfo : serviceInfos) { String idBasedKey = servicePropKeyLead + serviceInfo.getId(); cloudProperties.putAll(getServiceProperties(idBasedKey, serviceInfo)); if (serviceInfos.size() == 1) { String labelBasedKey = servicePropKeyLead + mappedServiceInfo.getKey(); cloudProperties.putAll(getServiceProperties(labelBasedKey, serviceInfo)); } } } cloudProperties.putAll(getAppProperties()); return cloudProperties; } | Cloud { public Properties getCloudProperties() { Map<String, List<ServiceInfo>> mappedServiceInfos = new HashMap<>(); for (ServiceInfo serviceInfo : getServiceInfos()) { String key = getServiceLabel(serviceInfo); List<ServiceInfo> serviceInfosForLabel = mappedServiceInfos.computeIfAbsent(key, k -> new ArrayList<>()); serviceInfosForLabel.add(serviceInfo); } final String servicePropKeyLead = "cloud.services."; Properties cloudProperties = new Properties(); for (Entry<String, List<ServiceInfo>> mappedServiceInfo : mappedServiceInfos.entrySet()) { List<ServiceInfo> serviceInfos = mappedServiceInfo.getValue(); for (ServiceInfo serviceInfo : serviceInfos) { String idBasedKey = servicePropKeyLead + serviceInfo.getId(); cloudProperties.putAll(getServiceProperties(idBasedKey, serviceInfo)); if (serviceInfos.size() == 1) { String labelBasedKey = servicePropKeyLead + mappedServiceInfo.getKey(); cloudProperties.putAll(getServiceProperties(labelBasedKey, serviceInfo)); } } } cloudProperties.putAll(getAppProperties()); return cloudProperties; } } | Cloud { public Properties getCloudProperties() { Map<String, List<ServiceInfo>> mappedServiceInfos = new HashMap<>(); for (ServiceInfo serviceInfo : getServiceInfos()) { String key = getServiceLabel(serviceInfo); List<ServiceInfo> serviceInfosForLabel = mappedServiceInfos.computeIfAbsent(key, k -> new ArrayList<>()); serviceInfosForLabel.add(serviceInfo); } final String servicePropKeyLead = "cloud.services."; Properties cloudProperties = new Properties(); for (Entry<String, List<ServiceInfo>> mappedServiceInfo : mappedServiceInfos.entrySet()) { List<ServiceInfo> serviceInfos = mappedServiceInfo.getValue(); for (ServiceInfo serviceInfo : serviceInfos) { String idBasedKey = servicePropKeyLead + serviceInfo.getId(); cloudProperties.putAll(getServiceProperties(idBasedKey, serviceInfo)); if (serviceInfos.size() == 1) { String labelBasedKey = servicePropKeyLead + mappedServiceInfo.getKey(); cloudProperties.putAll(getServiceProperties(labelBasedKey, serviceInfo)); } } } cloudProperties.putAll(getAppProperties()); return cloudProperties; } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); } | Cloud { public Properties getCloudProperties() { Map<String, List<ServiceInfo>> mappedServiceInfos = new HashMap<>(); for (ServiceInfo serviceInfo : getServiceInfos()) { String key = getServiceLabel(serviceInfo); List<ServiceInfo> serviceInfosForLabel = mappedServiceInfos.computeIfAbsent(key, k -> new ArrayList<>()); serviceInfosForLabel.add(serviceInfo); } final String servicePropKeyLead = "cloud.services."; Properties cloudProperties = new Properties(); for (Entry<String, List<ServiceInfo>> mappedServiceInfo : mappedServiceInfos.entrySet()) { List<ServiceInfo> serviceInfos = mappedServiceInfo.getValue(); for (ServiceInfo serviceInfo : serviceInfos) { String idBasedKey = servicePropKeyLead + serviceInfo.getId(); cloudProperties.putAll(getServiceProperties(idBasedKey, serviceInfo)); if (serviceInfos.size() == 1) { String labelBasedKey = servicePropKeyLead + mappedServiceInfo.getKey(); cloudProperties.putAll(getServiceProperties(labelBasedKey, serviceInfo)); } } } cloudProperties.putAll(getAppProperties()); return cloudProperties; } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } | Cloud { public Properties getCloudProperties() { Map<String, List<ServiceInfo>> mappedServiceInfos = new HashMap<>(); for (ServiceInfo serviceInfo : getServiceInfos()) { String key = getServiceLabel(serviceInfo); List<ServiceInfo> serviceInfosForLabel = mappedServiceInfos.computeIfAbsent(key, k -> new ArrayList<>()); serviceInfosForLabel.add(serviceInfo); } final String servicePropKeyLead = "cloud.services."; Properties cloudProperties = new Properties(); for (Entry<String, List<ServiceInfo>> mappedServiceInfo : mappedServiceInfos.entrySet()) { List<ServiceInfo> serviceInfos = mappedServiceInfo.getValue(); for (ServiceInfo serviceInfo : serviceInfos) { String idBasedKey = servicePropKeyLead + serviceInfo.getId(); cloudProperties.putAll(getServiceProperties(idBasedKey, serviceInfo)); if (serviceInfos.size() == 1) { String labelBasedKey = servicePropKeyLead + mappedServiceInfo.getKey(); cloudProperties.putAll(getServiceProperties(labelBasedKey, serviceInfo)); } } } cloudProperties.putAll(getAppProperties()); return cloudProperties; } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } |
@Test(expected=CloudException.class) public void getServiceInfoByInvalidId() { StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); testCloud.getServiceInfo("foo"); } | public ServiceInfo getServiceInfo(String serviceId) { for (ServiceInfo serviceInfo : getServiceInfos()) { if (serviceInfo.getId().equals(serviceId)) { return serviceInfo; } } throw new CloudException("No service with id " + serviceId + " found"); } | Cloud { public ServiceInfo getServiceInfo(String serviceId) { for (ServiceInfo serviceInfo : getServiceInfos()) { if (serviceInfo.getId().equals(serviceId)) { return serviceInfo; } } throw new CloudException("No service with id " + serviceId + " found"); } } | Cloud { public ServiceInfo getServiceInfo(String serviceId) { for (ServiceInfo serviceInfo : getServiceInfos()) { if (serviceInfo.getId().equals(serviceId)) { return serviceInfo; } } throw new CloudException("No service with id " + serviceId + " found"); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); } | Cloud { public ServiceInfo getServiceInfo(String serviceId) { for (ServiceInfo serviceInfo : getServiceInfos()) { if (serviceInfo.getId().equals(serviceId)) { return serviceInfo; } } throw new CloudException("No service with id " + serviceId + " found"); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } | Cloud { public ServiceInfo getServiceInfo(String serviceId) { for (ServiceInfo serviceInfo : getServiceInfos()) { if (serviceInfo.getId().equals(serviceId)) { return serviceInfo; } } throw new CloudException("No service with id " + serviceId + " found"); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } |
@Test public void compositeServiceInfo() { StubServiceInfo testServiceInfo1 = new StubServiceInfo("test-id-1", "test-host", 1000, "test-username", "test-password"); StubServiceInfo testServiceInfo2 = new StubServiceInfo("test-id-2", "test-host", 1000, "test-username", "test-password"); ServiceInfo testCompositeServiceInfo = new StubCompositeServiceInfo("test-composite",testServiceInfo1, testServiceInfo2); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testCompositeServiceInfo); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); assertNotNull(testCloud.getServiceInfo("test-id-1")); assertNotNull(testCloud.getServiceInfo("test-id-2")); } | public ServiceInfo getServiceInfo(String serviceId) { for (ServiceInfo serviceInfo : getServiceInfos()) { if (serviceInfo.getId().equals(serviceId)) { return serviceInfo; } } throw new CloudException("No service with id " + serviceId + " found"); } | Cloud { public ServiceInfo getServiceInfo(String serviceId) { for (ServiceInfo serviceInfo : getServiceInfos()) { if (serviceInfo.getId().equals(serviceId)) { return serviceInfo; } } throw new CloudException("No service with id " + serviceId + " found"); } } | Cloud { public ServiceInfo getServiceInfo(String serviceId) { for (ServiceInfo serviceInfo : getServiceInfos()) { if (serviceInfo.getId().equals(serviceId)) { return serviceInfo; } } throw new CloudException("No service with id " + serviceId + " found"); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); } | Cloud { public ServiceInfo getServiceInfo(String serviceId) { for (ServiceInfo serviceInfo : getServiceInfos()) { if (serviceInfo.getId().equals(serviceId)) { return serviceInfo; } } throw new CloudException("No service with id " + serviceId + " found"); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } | Cloud { public ServiceInfo getServiceInfo(String serviceId) { for (ServiceInfo serviceInfo : getServiceInfos()) { if (serviceInfo.getId().equals(serviceId)) { return serviceInfo; } } throw new CloudException("No service with id " + serviceId + " found"); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } |
@Test public void compositeServiceInfoRecursive() { StubServiceInfo testServiceInfo1a = new StubServiceInfo("test-id-1a", "test-host", 1000, "test-username", "test-password"); StubServiceInfo testServiceInfo1b = new StubServiceInfo("test-id-1b", "test-host", 1000, "test-username", "test-password"); ServiceInfo testCompositeServiceInfo1 = new StubCompositeServiceInfo("test-composite-1",testServiceInfo1a, testServiceInfo1b); StubServiceInfo testServiceInfo2a = new StubServiceInfo("test-id-2a", "test-host", 1000, "test-username", "test-password"); StubServiceInfo testServiceInfo2b = new StubServiceInfo("test-id-2b", "test-host", 1000, "test-username", "test-password"); ServiceInfo testCompositeServiceInfo2 = new StubCompositeServiceInfo("test-composite-2",testServiceInfo2a, testServiceInfo2b); ServiceInfo testCompositeServiceInfo = new StubCompositeServiceInfo("test-composite",testCompositeServiceInfo1, testCompositeServiceInfo2); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testCompositeServiceInfo); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); assertNotNull(testCloud.getServiceInfo("test-id-1a")); assertNotNull(testCloud.getServiceInfo("test-id-1b")); assertNotNull(testCloud.getServiceInfo("test-id-2a")); assertNotNull(testCloud.getServiceInfo("test-id-2b")); } | public ServiceInfo getServiceInfo(String serviceId) { for (ServiceInfo serviceInfo : getServiceInfos()) { if (serviceInfo.getId().equals(serviceId)) { return serviceInfo; } } throw new CloudException("No service with id " + serviceId + " found"); } | Cloud { public ServiceInfo getServiceInfo(String serviceId) { for (ServiceInfo serviceInfo : getServiceInfos()) { if (serviceInfo.getId().equals(serviceId)) { return serviceInfo; } } throw new CloudException("No service with id " + serviceId + " found"); } } | Cloud { public ServiceInfo getServiceInfo(String serviceId) { for (ServiceInfo serviceInfo : getServiceInfos()) { if (serviceInfo.getId().equals(serviceId)) { return serviceInfo; } } throw new CloudException("No service with id " + serviceId + " found"); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); } | Cloud { public ServiceInfo getServiceInfo(String serviceId) { for (ServiceInfo serviceInfo : getServiceInfos()) { if (serviceInfo.getId().equals(serviceId)) { return serviceInfo; } } throw new CloudException("No service with id " + serviceId + " found"); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } | Cloud { public ServiceInfo getServiceInfo(String serviceId) { for (ServiceInfo serviceInfo : getServiceInfos()) { if (serviceInfo.getId().equals(serviceId)) { return serviceInfo; } } throw new CloudException("No service with id " + serviceId + " found"); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } |
@Test public void getServiceInfosByType() { StubServiceInfo testServiceInfo = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); TestServiceInfoTypeA testServiceInfoTypeA1 = new TestServiceInfoTypeA("test-id-a1"); TestServiceInfoTypeA testServiceInfoTypeA2 = new TestServiceInfoTypeA("test-id-a2"); TestServiceInfoTypeB testServiceInfoTypeB = new TestServiceInfoTypeB("test-id-b"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo, testServiceInfoTypeA1, testServiceInfoTypeA2, testServiceInfoTypeB); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); List<TestServiceInfoTypeA> actualServiceInfoTypeA = testCloud.getServiceInfosByType(TestServiceInfoTypeA.class); assertEquals(2, actualServiceInfoTypeA.size()); assertEquals(1, testCloud.getServiceInfosByType(TestServiceInfoTypeB.class).size()); } | @SuppressWarnings("unchecked") public <T extends ServiceInfo> List<T> getServiceInfosByType(Class<T> serviceInfoType) { List<ServiceInfo> allServiceInfos = getServiceInfos(); List<T> matchingServiceInfos = new ArrayList<>(); for (ServiceInfo serviceInfo : allServiceInfos) { if (serviceInfoType.isAssignableFrom(serviceInfo.getClass())) { matchingServiceInfos.add((T) serviceInfo); } } return matchingServiceInfos; } | Cloud { @SuppressWarnings("unchecked") public <T extends ServiceInfo> List<T> getServiceInfosByType(Class<T> serviceInfoType) { List<ServiceInfo> allServiceInfos = getServiceInfos(); List<T> matchingServiceInfos = new ArrayList<>(); for (ServiceInfo serviceInfo : allServiceInfos) { if (serviceInfoType.isAssignableFrom(serviceInfo.getClass())) { matchingServiceInfos.add((T) serviceInfo); } } return matchingServiceInfos; } } | Cloud { @SuppressWarnings("unchecked") public <T extends ServiceInfo> List<T> getServiceInfosByType(Class<T> serviceInfoType) { List<ServiceInfo> allServiceInfos = getServiceInfos(); List<T> matchingServiceInfos = new ArrayList<>(); for (ServiceInfo serviceInfo : allServiceInfos) { if (serviceInfoType.isAssignableFrom(serviceInfo.getClass())) { matchingServiceInfos.add((T) serviceInfo); } } return matchingServiceInfos; } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); } | Cloud { @SuppressWarnings("unchecked") public <T extends ServiceInfo> List<T> getServiceInfosByType(Class<T> serviceInfoType) { List<ServiceInfo> allServiceInfos = getServiceInfos(); List<T> matchingServiceInfos = new ArrayList<>(); for (ServiceInfo serviceInfo : allServiceInfos) { if (serviceInfoType.isAssignableFrom(serviceInfo.getClass())) { matchingServiceInfos.add((T) serviceInfo); } } return matchingServiceInfos; } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } | Cloud { @SuppressWarnings("unchecked") public <T extends ServiceInfo> List<T> getServiceInfosByType(Class<T> serviceInfoType) { List<ServiceInfo> allServiceInfos = getServiceInfos(); List<T> matchingServiceInfos = new ArrayList<>(); for (ServiceInfo serviceInfo : allServiceInfos) { if (serviceInfoType.isAssignableFrom(serviceInfo.getClass())) { matchingServiceInfos.add((T) serviceInfo); } } return matchingServiceInfos; } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } |
@Test(expected=CloudException.class) public void getSingletonServiceInfoByTypeNoService() { StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); testCloud.getSingletonServiceInfoByType(StubServiceInfo.class); } | public <T extends ServiceInfo> T getSingletonServiceInfoByType(Class<T> serviceInfoType) { List<T> serviceInfos = getServiceInfosByType(serviceInfoType); if (serviceInfos.size() != 1) { throw new CloudException( "No unique service info " + serviceInfoType + " found. Expected 1, found " + serviceInfos.size()); } return serviceInfos.get(0); } | Cloud { public <T extends ServiceInfo> T getSingletonServiceInfoByType(Class<T> serviceInfoType) { List<T> serviceInfos = getServiceInfosByType(serviceInfoType); if (serviceInfos.size() != 1) { throw new CloudException( "No unique service info " + serviceInfoType + " found. Expected 1, found " + serviceInfos.size()); } return serviceInfos.get(0); } } | Cloud { public <T extends ServiceInfo> T getSingletonServiceInfoByType(Class<T> serviceInfoType) { List<T> serviceInfos = getServiceInfosByType(serviceInfoType); if (serviceInfos.size() != 1) { throw new CloudException( "No unique service info " + serviceInfoType + " found. Expected 1, found " + serviceInfos.size()); } return serviceInfos.get(0); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); } | Cloud { public <T extends ServiceInfo> T getSingletonServiceInfoByType(Class<T> serviceInfoType) { List<T> serviceInfos = getServiceInfosByType(serviceInfoType); if (serviceInfos.size() != 1) { throw new CloudException( "No unique service info " + serviceInfoType + " found. Expected 1, found " + serviceInfos.size()); } return serviceInfos.get(0); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } | Cloud { public <T extends ServiceInfo> T getSingletonServiceInfoByType(Class<T> serviceInfoType) { List<T> serviceInfos = getServiceInfosByType(serviceInfoType); if (serviceInfos.size() != 1) { throw new CloudException( "No unique service info " + serviceInfoType + " found. Expected 1, found " + serviceInfos.size()); } return serviceInfos.get(0); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } |
@Test(expected=CloudException.class) public void getSingletonServiceInfoByTypeMultipleServices() { StubServiceInfo testServiceInfo1 = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubServiceInfo testServiceInfo2 = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo1, testServiceInfo2); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); testCloud.getSingletonServiceInfoByType(StubServiceInfo.class); } | public <T extends ServiceInfo> T getSingletonServiceInfoByType(Class<T> serviceInfoType) { List<T> serviceInfos = getServiceInfosByType(serviceInfoType); if (serviceInfos.size() != 1) { throw new CloudException( "No unique service info " + serviceInfoType + " found. Expected 1, found " + serviceInfos.size()); } return serviceInfos.get(0); } | Cloud { public <T extends ServiceInfo> T getSingletonServiceInfoByType(Class<T> serviceInfoType) { List<T> serviceInfos = getServiceInfosByType(serviceInfoType); if (serviceInfos.size() != 1) { throw new CloudException( "No unique service info " + serviceInfoType + " found. Expected 1, found " + serviceInfos.size()); } return serviceInfos.get(0); } } | Cloud { public <T extends ServiceInfo> T getSingletonServiceInfoByType(Class<T> serviceInfoType) { List<T> serviceInfos = getServiceInfosByType(serviceInfoType); if (serviceInfos.size() != 1) { throw new CloudException( "No unique service info " + serviceInfoType + " found. Expected 1, found " + serviceInfos.size()); } return serviceInfos.get(0); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); } | Cloud { public <T extends ServiceInfo> T getSingletonServiceInfoByType(Class<T> serviceInfoType) { List<T> serviceInfos = getServiceInfosByType(serviceInfoType); if (serviceInfos.size() != 1) { throw new CloudException( "No unique service info " + serviceInfoType + " found. Expected 1, found " + serviceInfos.size()); } return serviceInfos.get(0); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } | Cloud { public <T extends ServiceInfo> T getSingletonServiceInfoByType(Class<T> serviceInfoType) { List<T> serviceInfos = getServiceInfosByType(serviceInfoType); if (serviceInfos.size() != 1) { throw new CloudException( "No unique service info " + serviceInfoType + " found. Expected 1, found " + serviceInfos.size()); } return serviceInfos.get(0); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } |
@Test public void cloudServiceConnectorCreatorRegistration() { CloudFactory cloudFactory = new CloudFactory(); List<ServiceConnectorCreator<?, ? extends ServiceInfo>> registeredServiceConnectorCreators = cloudFactory.getServiceCreators(); assertEquals("One serviceCreators registered", 2, registeredServiceConnectorCreators.size()); assertEquals("First registered connector is a stub", StubServiceConnectorCreator.class, registeredServiceConnectorCreators.get(0).getClass()); assertEquals("Second egistered connector is a non-parameterized stub", NonParameterizedStubServiceConnectorCreator.class, registeredServiceConnectorCreators.get(1).getClass()); } | List<ServiceConnectorCreator<?, ? extends ServiceInfo>> getServiceCreators() { return serviceCreators; } | CloudFactory { List<ServiceConnectorCreator<?, ? extends ServiceInfo>> getServiceCreators() { return serviceCreators; } } | CloudFactory { List<ServiceConnectorCreator<?, ? extends ServiceInfo>> getServiceCreators() { return serviceCreators; } CloudFactory(); } | CloudFactory { List<ServiceConnectorCreator<?, ? extends ServiceInfo>> getServiceCreators() { return serviceCreators; } CloudFactory(); Cloud getCloud(); void registerCloudConnector(CloudConnector cloudConnector); } | CloudFactory { List<ServiceConnectorCreator<?, ? extends ServiceInfo>> getServiceCreators() { return serviceCreators; } CloudFactory(); Cloud getCloud(); void registerCloudConnector(CloudConnector cloudConnector); } |
@Test public void getSingletonServiceInfoByTypeSingleService() { StubServiceInfo testServiceInfo = new StubServiceInfo("test-id", "test-host", 1000, "test-username", "test-password"); StubCloudConnector stubCloudConnector = CloudTestUtil.getTestCloudConnector(testServiceInfo); Cloud testCloud = new Cloud(stubCloudConnector, serviceConnectorCreators); assertNotNull(testCloud.getSingletonServiceInfoByType(StubServiceInfo.class)); } | public <T extends ServiceInfo> T getSingletonServiceInfoByType(Class<T> serviceInfoType) { List<T> serviceInfos = getServiceInfosByType(serviceInfoType); if (serviceInfos.size() != 1) { throw new CloudException( "No unique service info " + serviceInfoType + " found. Expected 1, found " + serviceInfos.size()); } return serviceInfos.get(0); } | Cloud { public <T extends ServiceInfo> T getSingletonServiceInfoByType(Class<T> serviceInfoType) { List<T> serviceInfos = getServiceInfosByType(serviceInfoType); if (serviceInfos.size() != 1) { throw new CloudException( "No unique service info " + serviceInfoType + " found. Expected 1, found " + serviceInfos.size()); } return serviceInfos.get(0); } } | Cloud { public <T extends ServiceInfo> T getSingletonServiceInfoByType(Class<T> serviceInfoType) { List<T> serviceInfos = getServiceInfosByType(serviceInfoType); if (serviceInfos.size() != 1) { throw new CloudException( "No unique service info " + serviceInfoType + " found. Expected 1, found " + serviceInfos.size()); } return serviceInfos.get(0); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); } | Cloud { public <T extends ServiceInfo> T getSingletonServiceInfoByType(Class<T> serviceInfoType) { List<T> serviceInfos = getServiceInfosByType(serviceInfoType); if (serviceInfos.size() != 1) { throw new CloudException( "No unique service info " + serviceInfoType + " found. Expected 1, found " + serviceInfos.size()); } return serviceInfos.get(0); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } | Cloud { public <T extends ServiceInfo> T getSingletonServiceInfoByType(Class<T> serviceInfoType) { List<T> serviceInfos = getServiceInfosByType(serviceInfoType); if (serviceInfos.size() != 1) { throw new CloudException( "No unique service info " + serviceInfoType + " found. Expected 1, found " + serviceInfos.size()); } return serviceInfos.get(0); } Cloud(CloudConnector cloudConnector, List<ServiceConnectorCreator<?, ? extends ServiceInfo>> serviceConnectorCreators); ApplicationInstanceInfo getApplicationInstanceInfo(); ServiceInfo getServiceInfo(String serviceId); List<ServiceInfo> getServiceInfos(); List<ServiceInfo> getServiceInfos(Class<T> serviceConnectorType); @SuppressWarnings("unchecked") List<T> getServiceInfosByType(Class<T> serviceInfoType); T getSingletonServiceInfoByType(Class<T> serviceInfoType); SC getServiceConnector(String serviceId, Class<SC> serviceConnectorType,
ServiceConnectorConfig serviceConnectorConfig); SC getSingletonServiceConnector(Class<SC> serviceConnectorType, ServiceConnectorConfig serviceConnectorConfig); void registerServiceConnectorCreator(ServiceConnectorCreator<?, ? extends ServiceInfo> serviceConnectorCreator); Properties getCloudProperties(); } |
@Test public void testPropertyParsing() { first.setProperty("spring.cloud.appId", "should skip me because I'm meta"); first.setProperty("spring.cloud.service1", "one"); first.setProperty("spring.cloud.", "should skip me because I don't have an ID"); first.setProperty("spring.cloud.service.two", "two"); first.setProperty("foobar", "should skip me because I don't match the prefix"); Map<String, String> services = LocalConfigUtil.readServices(first); assertEquals(2, services.size()); assertEquals("one", services.get("service1")); assertEquals("two", services.get("service.two")); } | static Map<String, String> readServices(Properties properties) { Map<String, String> services = new HashMap<String, String>(); for (String propertyName : properties.stringPropertyNames()) { if (LocalConfigConnector.META_PROPERTIES.contains(propertyName)) { logger.finer("skipping meta property " + propertyName); continue; } Matcher m = LocalConfigConnector.SERVICE_PROPERTY_PATTERN.matcher(propertyName); if (!m.matches()) { logger.finest("skipping non-Spring-Cloud property " + propertyName); continue; } String serviceId = m.group(1); String serviceUri = properties.getProperty(propertyName); logger.fine("found service URI for service " + serviceId); services.put(serviceId, serviceUri); } return services; } | LocalConfigUtil { static Map<String, String> readServices(Properties properties) { Map<String, String> services = new HashMap<String, String>(); for (String propertyName : properties.stringPropertyNames()) { if (LocalConfigConnector.META_PROPERTIES.contains(propertyName)) { logger.finer("skipping meta property " + propertyName); continue; } Matcher m = LocalConfigConnector.SERVICE_PROPERTY_PATTERN.matcher(propertyName); if (!m.matches()) { logger.finest("skipping non-Spring-Cloud property " + propertyName); continue; } String serviceId = m.group(1); String serviceUri = properties.getProperty(propertyName); logger.fine("found service URI for service " + serviceId); services.put(serviceId, serviceUri); } return services; } } | LocalConfigUtil { static Map<String, String> readServices(Properties properties) { Map<String, String> services = new HashMap<String, String>(); for (String propertyName : properties.stringPropertyNames()) { if (LocalConfigConnector.META_PROPERTIES.contains(propertyName)) { logger.finer("skipping meta property " + propertyName); continue; } Matcher m = LocalConfigConnector.SERVICE_PROPERTY_PATTERN.matcher(propertyName); if (!m.matches()) { logger.finest("skipping non-Spring-Cloud property " + propertyName); continue; } String serviceId = m.group(1); String serviceUri = properties.getProperty(propertyName); logger.fine("found service URI for service " + serviceId); services.put(serviceId, serviceUri); } return services; } private LocalConfigUtil(); } | LocalConfigUtil { static Map<String, String> readServices(Properties properties) { Map<String, String> services = new HashMap<String, String>(); for (String propertyName : properties.stringPropertyNames()) { if (LocalConfigConnector.META_PROPERTIES.contains(propertyName)) { logger.finer("skipping meta property " + propertyName); continue; } Matcher m = LocalConfigConnector.SERVICE_PROPERTY_PATTERN.matcher(propertyName); if (!m.matches()) { logger.finest("skipping non-Spring-Cloud property " + propertyName); continue; } String serviceId = m.group(1); String serviceUri = properties.getProperty(propertyName); logger.fine("found service URI for service " + serviceId); services.put(serviceId, serviceUri); } return services; } private LocalConfigUtil(); } | LocalConfigUtil { static Map<String, String> readServices(Properties properties) { Map<String, String> services = new HashMap<String, String>(); for (String propertyName : properties.stringPropertyNames()) { if (LocalConfigConnector.META_PROPERTIES.contains(propertyName)) { logger.finer("skipping meta property " + propertyName); continue; } Matcher m = LocalConfigConnector.SERVICE_PROPERTY_PATTERN.matcher(propertyName); if (!m.matches()) { logger.finest("skipping non-Spring-Cloud property " + propertyName); continue; } String serviceId = m.group(1); String serviceUri = properties.getProperty(propertyName); logger.fine("found service URI for service " + serviceId); services.put(serviceId, serviceUri); } return services; } private LocalConfigUtil(); } |
@Test public void testCollation() { first.setProperty("spring.cloud.first", "firstUri"); second.setProperty("spring.cloud.second", "secondUri"); List<UriBasedServiceData> serviceData = LocalConfigUtil.readServicesData(propertySources); assertEquals(2, serviceData.size()); boolean foundFirst = false; for (UriBasedServiceData kvp : serviceData) { if (kvp.getKey().equals("first")) { assertEquals("firstUri", kvp.getUri()); foundFirst = true; } } assertTrue(foundFirst); } | static List<UriBasedServiceData> readServicesData(LinkedHashMap<String, Properties> propertySources) { Map<String, String> collectedServices = new HashMap<String, String>(); for (Map.Entry<String, Properties> propertySource : propertySources.entrySet()) { if (propertySource.getValue().isEmpty()) { logger.info("no " + propertySource.getKey()); continue; } logger.info("reading services from " + propertySource.getKey()); Map<String, String> services = readServices(propertySource.getValue()); for (Map.Entry<String, String> service : services.entrySet()) { String oldUri = collectedServices.put(service.getKey(), service.getValue()); if (oldUri == null) logger.info("added service '" + service.getKey() + "' from " + propertySource.getKey()); else logger.warning("replaced service '" + service.getKey() + "' with new URI from " + propertySource.getKey()); } } List<UriBasedServiceData> serviceData = new ArrayList<UriBasedServiceData>(collectedServices.size()); for (Map.Entry<String, String> serviceInfo : collectedServices.entrySet()) { serviceData.add(new UriBasedServiceData(serviceInfo.getKey(), serviceInfo.getValue())); } return serviceData; } | LocalConfigUtil { static List<UriBasedServiceData> readServicesData(LinkedHashMap<String, Properties> propertySources) { Map<String, String> collectedServices = new HashMap<String, String>(); for (Map.Entry<String, Properties> propertySource : propertySources.entrySet()) { if (propertySource.getValue().isEmpty()) { logger.info("no " + propertySource.getKey()); continue; } logger.info("reading services from " + propertySource.getKey()); Map<String, String> services = readServices(propertySource.getValue()); for (Map.Entry<String, String> service : services.entrySet()) { String oldUri = collectedServices.put(service.getKey(), service.getValue()); if (oldUri == null) logger.info("added service '" + service.getKey() + "' from " + propertySource.getKey()); else logger.warning("replaced service '" + service.getKey() + "' with new URI from " + propertySource.getKey()); } } List<UriBasedServiceData> serviceData = new ArrayList<UriBasedServiceData>(collectedServices.size()); for (Map.Entry<String, String> serviceInfo : collectedServices.entrySet()) { serviceData.add(new UriBasedServiceData(serviceInfo.getKey(), serviceInfo.getValue())); } return serviceData; } } | LocalConfigUtil { static List<UriBasedServiceData> readServicesData(LinkedHashMap<String, Properties> propertySources) { Map<String, String> collectedServices = new HashMap<String, String>(); for (Map.Entry<String, Properties> propertySource : propertySources.entrySet()) { if (propertySource.getValue().isEmpty()) { logger.info("no " + propertySource.getKey()); continue; } logger.info("reading services from " + propertySource.getKey()); Map<String, String> services = readServices(propertySource.getValue()); for (Map.Entry<String, String> service : services.entrySet()) { String oldUri = collectedServices.put(service.getKey(), service.getValue()); if (oldUri == null) logger.info("added service '" + service.getKey() + "' from " + propertySource.getKey()); else logger.warning("replaced service '" + service.getKey() + "' with new URI from " + propertySource.getKey()); } } List<UriBasedServiceData> serviceData = new ArrayList<UriBasedServiceData>(collectedServices.size()); for (Map.Entry<String, String> serviceInfo : collectedServices.entrySet()) { serviceData.add(new UriBasedServiceData(serviceInfo.getKey(), serviceInfo.getValue())); } return serviceData; } private LocalConfigUtil(); } | LocalConfigUtil { static List<UriBasedServiceData> readServicesData(LinkedHashMap<String, Properties> propertySources) { Map<String, String> collectedServices = new HashMap<String, String>(); for (Map.Entry<String, Properties> propertySource : propertySources.entrySet()) { if (propertySource.getValue().isEmpty()) { logger.info("no " + propertySource.getKey()); continue; } logger.info("reading services from " + propertySource.getKey()); Map<String, String> services = readServices(propertySource.getValue()); for (Map.Entry<String, String> service : services.entrySet()) { String oldUri = collectedServices.put(service.getKey(), service.getValue()); if (oldUri == null) logger.info("added service '" + service.getKey() + "' from " + propertySource.getKey()); else logger.warning("replaced service '" + service.getKey() + "' with new URI from " + propertySource.getKey()); } } List<UriBasedServiceData> serviceData = new ArrayList<UriBasedServiceData>(collectedServices.size()); for (Map.Entry<String, String> serviceInfo : collectedServices.entrySet()) { serviceData.add(new UriBasedServiceData(serviceInfo.getKey(), serviceInfo.getValue())); } return serviceData; } private LocalConfigUtil(); } | LocalConfigUtil { static List<UriBasedServiceData> readServicesData(LinkedHashMap<String, Properties> propertySources) { Map<String, String> collectedServices = new HashMap<String, String>(); for (Map.Entry<String, Properties> propertySource : propertySources.entrySet()) { if (propertySource.getValue().isEmpty()) { logger.info("no " + propertySource.getKey()); continue; } logger.info("reading services from " + propertySource.getKey()); Map<String, String> services = readServices(propertySource.getValue()); for (Map.Entry<String, String> service : services.entrySet()) { String oldUri = collectedServices.put(service.getKey(), service.getValue()); if (oldUri == null) logger.info("added service '" + service.getKey() + "' from " + propertySource.getKey()); else logger.warning("replaced service '" + service.getKey() + "' with new URI from " + propertySource.getKey()); } } List<UriBasedServiceData> serviceData = new ArrayList<UriBasedServiceData>(collectedServices.size()); for (Map.Entry<String, String> serviceInfo : collectedServices.entrySet()) { serviceData.add(new UriBasedServiceData(serviceInfo.getKey(), serviceInfo.getValue())); } return serviceData; } private LocalConfigUtil(); } |
@Test public void testOverride() { first.setProperty("spring.cloud.duplicate", "firstUri"); second.setProperty("spring.cloud.duplicate", "secondUri"); List<UriBasedServiceData> serviceData = LocalConfigUtil.readServicesData(propertySources); assertEquals(1, serviceData.size()); UriBasedServiceData kvp = serviceData.get(0); assertEquals("duplicate", kvp.getKey()); assertEquals("secondUri", kvp.getUri()); } | static List<UriBasedServiceData> readServicesData(LinkedHashMap<String, Properties> propertySources) { Map<String, String> collectedServices = new HashMap<String, String>(); for (Map.Entry<String, Properties> propertySource : propertySources.entrySet()) { if (propertySource.getValue().isEmpty()) { logger.info("no " + propertySource.getKey()); continue; } logger.info("reading services from " + propertySource.getKey()); Map<String, String> services = readServices(propertySource.getValue()); for (Map.Entry<String, String> service : services.entrySet()) { String oldUri = collectedServices.put(service.getKey(), service.getValue()); if (oldUri == null) logger.info("added service '" + service.getKey() + "' from " + propertySource.getKey()); else logger.warning("replaced service '" + service.getKey() + "' with new URI from " + propertySource.getKey()); } } List<UriBasedServiceData> serviceData = new ArrayList<UriBasedServiceData>(collectedServices.size()); for (Map.Entry<String, String> serviceInfo : collectedServices.entrySet()) { serviceData.add(new UriBasedServiceData(serviceInfo.getKey(), serviceInfo.getValue())); } return serviceData; } | LocalConfigUtil { static List<UriBasedServiceData> readServicesData(LinkedHashMap<String, Properties> propertySources) { Map<String, String> collectedServices = new HashMap<String, String>(); for (Map.Entry<String, Properties> propertySource : propertySources.entrySet()) { if (propertySource.getValue().isEmpty()) { logger.info("no " + propertySource.getKey()); continue; } logger.info("reading services from " + propertySource.getKey()); Map<String, String> services = readServices(propertySource.getValue()); for (Map.Entry<String, String> service : services.entrySet()) { String oldUri = collectedServices.put(service.getKey(), service.getValue()); if (oldUri == null) logger.info("added service '" + service.getKey() + "' from " + propertySource.getKey()); else logger.warning("replaced service '" + service.getKey() + "' with new URI from " + propertySource.getKey()); } } List<UriBasedServiceData> serviceData = new ArrayList<UriBasedServiceData>(collectedServices.size()); for (Map.Entry<String, String> serviceInfo : collectedServices.entrySet()) { serviceData.add(new UriBasedServiceData(serviceInfo.getKey(), serviceInfo.getValue())); } return serviceData; } } | LocalConfigUtil { static List<UriBasedServiceData> readServicesData(LinkedHashMap<String, Properties> propertySources) { Map<String, String> collectedServices = new HashMap<String, String>(); for (Map.Entry<String, Properties> propertySource : propertySources.entrySet()) { if (propertySource.getValue().isEmpty()) { logger.info("no " + propertySource.getKey()); continue; } logger.info("reading services from " + propertySource.getKey()); Map<String, String> services = readServices(propertySource.getValue()); for (Map.Entry<String, String> service : services.entrySet()) { String oldUri = collectedServices.put(service.getKey(), service.getValue()); if (oldUri == null) logger.info("added service '" + service.getKey() + "' from " + propertySource.getKey()); else logger.warning("replaced service '" + service.getKey() + "' with new URI from " + propertySource.getKey()); } } List<UriBasedServiceData> serviceData = new ArrayList<UriBasedServiceData>(collectedServices.size()); for (Map.Entry<String, String> serviceInfo : collectedServices.entrySet()) { serviceData.add(new UriBasedServiceData(serviceInfo.getKey(), serviceInfo.getValue())); } return serviceData; } private LocalConfigUtil(); } | LocalConfigUtil { static List<UriBasedServiceData> readServicesData(LinkedHashMap<String, Properties> propertySources) { Map<String, String> collectedServices = new HashMap<String, String>(); for (Map.Entry<String, Properties> propertySource : propertySources.entrySet()) { if (propertySource.getValue().isEmpty()) { logger.info("no " + propertySource.getKey()); continue; } logger.info("reading services from " + propertySource.getKey()); Map<String, String> services = readServices(propertySource.getValue()); for (Map.Entry<String, String> service : services.entrySet()) { String oldUri = collectedServices.put(service.getKey(), service.getValue()); if (oldUri == null) logger.info("added service '" + service.getKey() + "' from " + propertySource.getKey()); else logger.warning("replaced service '" + service.getKey() + "' with new URI from " + propertySource.getKey()); } } List<UriBasedServiceData> serviceData = new ArrayList<UriBasedServiceData>(collectedServices.size()); for (Map.Entry<String, String> serviceInfo : collectedServices.entrySet()) { serviceData.add(new UriBasedServiceData(serviceInfo.getKey(), serviceInfo.getValue())); } return serviceData; } private LocalConfigUtil(); } | LocalConfigUtil { static List<UriBasedServiceData> readServicesData(LinkedHashMap<String, Properties> propertySources) { Map<String, String> collectedServices = new HashMap<String, String>(); for (Map.Entry<String, Properties> propertySource : propertySources.entrySet()) { if (propertySource.getValue().isEmpty()) { logger.info("no " + propertySource.getKey()); continue; } logger.info("reading services from " + propertySource.getKey()); Map<String, String> services = readServices(propertySource.getValue()); for (Map.Entry<String, String> service : services.entrySet()) { String oldUri = collectedServices.put(service.getKey(), service.getValue()); if (oldUri == null) logger.info("added service '" + service.getKey() + "' from " + propertySource.getKey()); else logger.warning("replaced service '" + service.getKey() + "' with new URI from " + propertySource.getKey()); } } List<UriBasedServiceData> serviceData = new ArrayList<UriBasedServiceData>(collectedServices.size()); for (Map.Entry<String, String> serviceInfo : collectedServices.entrySet()) { serviceData.add(new UriBasedServiceData(serviceInfo.getKey(), serviceInfo.getValue())); } return serviceData; } private LocalConfigUtil(); } |
@Test public void testNoAppIdAnywhere() { assertFalse(connector.isInMatchingCloud()); } | @Override public boolean isInMatchingCloud() { if (fileProperties == null) readFileProperties(); String appId = findProperty(APP_ID_PROPERTY); if (appId == null) logger.info("the property " + APP_ID_PROPERTY + " was not found in the system properties or configuration file"); return appId != null; } | LocalConfigConnector extends AbstractCloudConnector<UriBasedServiceData> { @Override public boolean isInMatchingCloud() { if (fileProperties == null) readFileProperties(); String appId = findProperty(APP_ID_PROPERTY); if (appId == null) logger.info("the property " + APP_ID_PROPERTY + " was not found in the system properties or configuration file"); return appId != null; } } | LocalConfigConnector extends AbstractCloudConnector<UriBasedServiceData> { @Override public boolean isInMatchingCloud() { if (fileProperties == null) readFileProperties(); String appId = findProperty(APP_ID_PROPERTY); if (appId == null) logger.info("the property " + APP_ID_PROPERTY + " was not found in the system properties or configuration file"); return appId != null; } @SuppressWarnings({"unchecked", "rawtypes"}) LocalConfigConnector(); } | LocalConfigConnector extends AbstractCloudConnector<UriBasedServiceData> { @Override public boolean isInMatchingCloud() { if (fileProperties == null) readFileProperties(); String appId = findProperty(APP_ID_PROPERTY); if (appId == null) logger.info("the property " + APP_ID_PROPERTY + " was not found in the system properties or configuration file"); return appId != null; } @SuppressWarnings({"unchecked", "rawtypes"}) LocalConfigConnector(); @Override boolean isInMatchingCloud(); @Override ApplicationInstanceInfo getApplicationInstanceInfo(); } | LocalConfigConnector extends AbstractCloudConnector<UriBasedServiceData> { @Override public boolean isInMatchingCloud() { if (fileProperties == null) readFileProperties(); String appId = findProperty(APP_ID_PROPERTY); if (appId == null) logger.info("the property " + APP_ID_PROPERTY + " was not found in the system properties or configuration file"); return appId != null; } @SuppressWarnings({"unchecked", "rawtypes"}) LocalConfigConnector(); @Override boolean isInMatchingCloud(); @Override ApplicationInstanceInfo getApplicationInstanceInfo(); static final String PROPERTY_PREFIX; static final Pattern SERVICE_PROPERTY_PATTERN; static final String APP_ID_PROPERTY; static final String PROPERTIES_FILE_PROPERTY; static final List<String> META_PROPERTIES; } |
@Test public void testSecurityExceptionHandling() { env = mock(PassthroughEnvironmentAccessor.class); resolver = new PropertiesFileResolver(env); when(env.getSystemProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY)).thenThrow(new SecurityException()); assertNull(resolver.findCloudPropertiesFileFromSystem()); verify(env).getSystemProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); } | File findCloudPropertiesFileFromSystem() { String filename = null; try { filename = env.getSystemProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); } catch (SecurityException e) { logger.log(Level.WARNING, "SecurityManager prevented reading system property " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY, e); return null; } if (filename == null) { logger.fine("didn't find system property for a configuration file"); return null; } File file = new File(filename); logger.info("found system property for a configuration file: " + file); return file; } | PropertiesFileResolver { File findCloudPropertiesFileFromSystem() { String filename = null; try { filename = env.getSystemProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); } catch (SecurityException e) { logger.log(Level.WARNING, "SecurityManager prevented reading system property " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY, e); return null; } if (filename == null) { logger.fine("didn't find system property for a configuration file"); return null; } File file = new File(filename); logger.info("found system property for a configuration file: " + file); return file; } } | PropertiesFileResolver { File findCloudPropertiesFileFromSystem() { String filename = null; try { filename = env.getSystemProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); } catch (SecurityException e) { logger.log(Level.WARNING, "SecurityManager prevented reading system property " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY, e); return null; } if (filename == null) { logger.fine("didn't find system property for a configuration file"); return null; } File file = new File(filename); logger.info("found system property for a configuration file: " + file); return file; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); } | PropertiesFileResolver { File findCloudPropertiesFileFromSystem() { String filename = null; try { filename = env.getSystemProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); } catch (SecurityException e) { logger.log(Level.WARNING, "SecurityManager prevented reading system property " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY, e); return null; } if (filename == null) { logger.fine("didn't find system property for a configuration file"); return null; } File file = new File(filename); logger.info("found system property for a configuration file: " + file); return file; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); } | PropertiesFileResolver { File findCloudPropertiesFileFromSystem() { String filename = null; try { filename = env.getSystemProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); } catch (SecurityException e) { logger.log(Level.WARNING, "SecurityManager prevented reading system property " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY, e); return null; } if (filename == null) { logger.fine("didn't find system property for a configuration file"); return null; } File file = new File(filename); logger.info("found system property for a configuration file: " + file); return file; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); static final String BOOTSTRAP_PROPERTIES_FILENAME; } |
@Test public void testMissingSystemProperty() { assertNull(resolver.findCloudPropertiesFileFromSystem()); } | File findCloudPropertiesFileFromSystem() { String filename = null; try { filename = env.getSystemProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); } catch (SecurityException e) { logger.log(Level.WARNING, "SecurityManager prevented reading system property " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY, e); return null; } if (filename == null) { logger.fine("didn't find system property for a configuration file"); return null; } File file = new File(filename); logger.info("found system property for a configuration file: " + file); return file; } | PropertiesFileResolver { File findCloudPropertiesFileFromSystem() { String filename = null; try { filename = env.getSystemProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); } catch (SecurityException e) { logger.log(Level.WARNING, "SecurityManager prevented reading system property " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY, e); return null; } if (filename == null) { logger.fine("didn't find system property for a configuration file"); return null; } File file = new File(filename); logger.info("found system property for a configuration file: " + file); return file; } } | PropertiesFileResolver { File findCloudPropertiesFileFromSystem() { String filename = null; try { filename = env.getSystemProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); } catch (SecurityException e) { logger.log(Level.WARNING, "SecurityManager prevented reading system property " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY, e); return null; } if (filename == null) { logger.fine("didn't find system property for a configuration file"); return null; } File file = new File(filename); logger.info("found system property for a configuration file: " + file); return file; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); } | PropertiesFileResolver { File findCloudPropertiesFileFromSystem() { String filename = null; try { filename = env.getSystemProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); } catch (SecurityException e) { logger.log(Level.WARNING, "SecurityManager prevented reading system property " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY, e); return null; } if (filename == null) { logger.fine("didn't find system property for a configuration file"); return null; } File file = new File(filename); logger.info("found system property for a configuration file: " + file); return file; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); } | PropertiesFileResolver { File findCloudPropertiesFileFromSystem() { String filename = null; try { filename = env.getSystemProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); } catch (SecurityException e) { logger.log(Level.WARNING, "SecurityManager prevented reading system property " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY, e); return null; } if (filename == null) { logger.fine("didn't find system property for a configuration file"); return null; } File file = new File(filename); logger.info("found system property for a configuration file: " + file); return file; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); static final String BOOTSTRAP_PROPERTIES_FILENAME; } |
@Test public void testSystemProperty() { env.setSystemProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY, PROPERTIES_FILE_NAME); assertEquals(PROPERTIES_FILE_NAME, resolver.findCloudPropertiesFileFromSystem().getPath()); } | File findCloudPropertiesFileFromSystem() { String filename = null; try { filename = env.getSystemProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); } catch (SecurityException e) { logger.log(Level.WARNING, "SecurityManager prevented reading system property " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY, e); return null; } if (filename == null) { logger.fine("didn't find system property for a configuration file"); return null; } File file = new File(filename); logger.info("found system property for a configuration file: " + file); return file; } | PropertiesFileResolver { File findCloudPropertiesFileFromSystem() { String filename = null; try { filename = env.getSystemProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); } catch (SecurityException e) { logger.log(Level.WARNING, "SecurityManager prevented reading system property " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY, e); return null; } if (filename == null) { logger.fine("didn't find system property for a configuration file"); return null; } File file = new File(filename); logger.info("found system property for a configuration file: " + file); return file; } } | PropertiesFileResolver { File findCloudPropertiesFileFromSystem() { String filename = null; try { filename = env.getSystemProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); } catch (SecurityException e) { logger.log(Level.WARNING, "SecurityManager prevented reading system property " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY, e); return null; } if (filename == null) { logger.fine("didn't find system property for a configuration file"); return null; } File file = new File(filename); logger.info("found system property for a configuration file: " + file); return file; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); } | PropertiesFileResolver { File findCloudPropertiesFileFromSystem() { String filename = null; try { filename = env.getSystemProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); } catch (SecurityException e) { logger.log(Level.WARNING, "SecurityManager prevented reading system property " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY, e); return null; } if (filename == null) { logger.fine("didn't find system property for a configuration file"); return null; } File file = new File(filename); logger.info("found system property for a configuration file: " + file); return file; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); } | PropertiesFileResolver { File findCloudPropertiesFileFromSystem() { String filename = null; try { filename = env.getSystemProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); } catch (SecurityException e) { logger.log(Level.WARNING, "SecurityManager prevented reading system property " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY, e); return null; } if (filename == null) { logger.fine("didn't find system property for a configuration file"); return null; } File file = new File(filename); logger.info("found system property for a configuration file: " + file); return file; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); static final String BOOTSTRAP_PROPERTIES_FILENAME; } |
@Test public void testNoClasspathFile() { resolver = new PropertiesFileResolver(env, "bazquux.properties"); assertNull(resolver.findCloudPropertiesFileFromClasspath()); } | File findCloudPropertiesFileFromClasspath() { InputStream in = getClass().getClassLoader().getResourceAsStream(classpathPropertiesFilename); if (in == null) { logger.info("no " + classpathPropertiesFilename + " found on the classpath to direct us to an external properties file"); return null; } Properties properties = new Properties(); try { properties.load(in); } catch (IOException e) { logger.log(Level.SEVERE, "found " + classpathPropertiesFilename + " on the classpath but couldn't load it as a properties file", e); return null; } String template = properties.getProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); if (template == null) { logger.log(Level.SEVERE, "found properties file " + classpathPropertiesFilename + " on the classpath, but it didn't contain a property named " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY); return null; } if (properties.entrySet().size() > 1) logger.warning("the properties file " + classpathPropertiesFilename + " contained properties besides " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY + "; ignoring"); logger.fine("substituting system properties into '" + template + "'"); File configFile = new File(new StrSubstitutor(systemPropertiesLookup(env)).replace(template)); logger.info("derived configuration file name: " + configFile); return configFile; } | PropertiesFileResolver { File findCloudPropertiesFileFromClasspath() { InputStream in = getClass().getClassLoader().getResourceAsStream(classpathPropertiesFilename); if (in == null) { logger.info("no " + classpathPropertiesFilename + " found on the classpath to direct us to an external properties file"); return null; } Properties properties = new Properties(); try { properties.load(in); } catch (IOException e) { logger.log(Level.SEVERE, "found " + classpathPropertiesFilename + " on the classpath but couldn't load it as a properties file", e); return null; } String template = properties.getProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); if (template == null) { logger.log(Level.SEVERE, "found properties file " + classpathPropertiesFilename + " on the classpath, but it didn't contain a property named " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY); return null; } if (properties.entrySet().size() > 1) logger.warning("the properties file " + classpathPropertiesFilename + " contained properties besides " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY + "; ignoring"); logger.fine("substituting system properties into '" + template + "'"); File configFile = new File(new StrSubstitutor(systemPropertiesLookup(env)).replace(template)); logger.info("derived configuration file name: " + configFile); return configFile; } } | PropertiesFileResolver { File findCloudPropertiesFileFromClasspath() { InputStream in = getClass().getClassLoader().getResourceAsStream(classpathPropertiesFilename); if (in == null) { logger.info("no " + classpathPropertiesFilename + " found on the classpath to direct us to an external properties file"); return null; } Properties properties = new Properties(); try { properties.load(in); } catch (IOException e) { logger.log(Level.SEVERE, "found " + classpathPropertiesFilename + " on the classpath but couldn't load it as a properties file", e); return null; } String template = properties.getProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); if (template == null) { logger.log(Level.SEVERE, "found properties file " + classpathPropertiesFilename + " on the classpath, but it didn't contain a property named " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY); return null; } if (properties.entrySet().size() > 1) logger.warning("the properties file " + classpathPropertiesFilename + " contained properties besides " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY + "; ignoring"); logger.fine("substituting system properties into '" + template + "'"); File configFile = new File(new StrSubstitutor(systemPropertiesLookup(env)).replace(template)); logger.info("derived configuration file name: " + configFile); return configFile; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); } | PropertiesFileResolver { File findCloudPropertiesFileFromClasspath() { InputStream in = getClass().getClassLoader().getResourceAsStream(classpathPropertiesFilename); if (in == null) { logger.info("no " + classpathPropertiesFilename + " found on the classpath to direct us to an external properties file"); return null; } Properties properties = new Properties(); try { properties.load(in); } catch (IOException e) { logger.log(Level.SEVERE, "found " + classpathPropertiesFilename + " on the classpath but couldn't load it as a properties file", e); return null; } String template = properties.getProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); if (template == null) { logger.log(Level.SEVERE, "found properties file " + classpathPropertiesFilename + " on the classpath, but it didn't contain a property named " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY); return null; } if (properties.entrySet().size() > 1) logger.warning("the properties file " + classpathPropertiesFilename + " contained properties besides " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY + "; ignoring"); logger.fine("substituting system properties into '" + template + "'"); File configFile = new File(new StrSubstitutor(systemPropertiesLookup(env)).replace(template)); logger.info("derived configuration file name: " + configFile); return configFile; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); } | PropertiesFileResolver { File findCloudPropertiesFileFromClasspath() { InputStream in = getClass().getClassLoader().getResourceAsStream(classpathPropertiesFilename); if (in == null) { logger.info("no " + classpathPropertiesFilename + " found on the classpath to direct us to an external properties file"); return null; } Properties properties = new Properties(); try { properties.load(in); } catch (IOException e) { logger.log(Level.SEVERE, "found " + classpathPropertiesFilename + " on the classpath but couldn't load it as a properties file", e); return null; } String template = properties.getProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); if (template == null) { logger.log(Level.SEVERE, "found properties file " + classpathPropertiesFilename + " on the classpath, but it didn't contain a property named " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY); return null; } if (properties.entrySet().size() > 1) logger.warning("the properties file " + classpathPropertiesFilename + " contained properties besides " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY + "; ignoring"); logger.fine("substituting system properties into '" + template + "'"); File configFile = new File(new StrSubstitutor(systemPropertiesLookup(env)).replace(template)); logger.info("derived configuration file name: " + configFile); return configFile; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); static final String BOOTSTRAP_PROPERTIES_FILENAME; } |
@Test public void testClasspathFileWithoutKey() { resolver = new PropertiesFileResolver(env, "localconfig.testuris.properties"); assertNull(resolver.findCloudPropertiesFileFromClasspath()); } | File findCloudPropertiesFileFromClasspath() { InputStream in = getClass().getClassLoader().getResourceAsStream(classpathPropertiesFilename); if (in == null) { logger.info("no " + classpathPropertiesFilename + " found on the classpath to direct us to an external properties file"); return null; } Properties properties = new Properties(); try { properties.load(in); } catch (IOException e) { logger.log(Level.SEVERE, "found " + classpathPropertiesFilename + " on the classpath but couldn't load it as a properties file", e); return null; } String template = properties.getProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); if (template == null) { logger.log(Level.SEVERE, "found properties file " + classpathPropertiesFilename + " on the classpath, but it didn't contain a property named " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY); return null; } if (properties.entrySet().size() > 1) logger.warning("the properties file " + classpathPropertiesFilename + " contained properties besides " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY + "; ignoring"); logger.fine("substituting system properties into '" + template + "'"); File configFile = new File(new StrSubstitutor(systemPropertiesLookup(env)).replace(template)); logger.info("derived configuration file name: " + configFile); return configFile; } | PropertiesFileResolver { File findCloudPropertiesFileFromClasspath() { InputStream in = getClass().getClassLoader().getResourceAsStream(classpathPropertiesFilename); if (in == null) { logger.info("no " + classpathPropertiesFilename + " found on the classpath to direct us to an external properties file"); return null; } Properties properties = new Properties(); try { properties.load(in); } catch (IOException e) { logger.log(Level.SEVERE, "found " + classpathPropertiesFilename + " on the classpath but couldn't load it as a properties file", e); return null; } String template = properties.getProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); if (template == null) { logger.log(Level.SEVERE, "found properties file " + classpathPropertiesFilename + " on the classpath, but it didn't contain a property named " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY); return null; } if (properties.entrySet().size() > 1) logger.warning("the properties file " + classpathPropertiesFilename + " contained properties besides " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY + "; ignoring"); logger.fine("substituting system properties into '" + template + "'"); File configFile = new File(new StrSubstitutor(systemPropertiesLookup(env)).replace(template)); logger.info("derived configuration file name: " + configFile); return configFile; } } | PropertiesFileResolver { File findCloudPropertiesFileFromClasspath() { InputStream in = getClass().getClassLoader().getResourceAsStream(classpathPropertiesFilename); if (in == null) { logger.info("no " + classpathPropertiesFilename + " found on the classpath to direct us to an external properties file"); return null; } Properties properties = new Properties(); try { properties.load(in); } catch (IOException e) { logger.log(Level.SEVERE, "found " + classpathPropertiesFilename + " on the classpath but couldn't load it as a properties file", e); return null; } String template = properties.getProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); if (template == null) { logger.log(Level.SEVERE, "found properties file " + classpathPropertiesFilename + " on the classpath, but it didn't contain a property named " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY); return null; } if (properties.entrySet().size() > 1) logger.warning("the properties file " + classpathPropertiesFilename + " contained properties besides " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY + "; ignoring"); logger.fine("substituting system properties into '" + template + "'"); File configFile = new File(new StrSubstitutor(systemPropertiesLookup(env)).replace(template)); logger.info("derived configuration file name: " + configFile); return configFile; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); } | PropertiesFileResolver { File findCloudPropertiesFileFromClasspath() { InputStream in = getClass().getClassLoader().getResourceAsStream(classpathPropertiesFilename); if (in == null) { logger.info("no " + classpathPropertiesFilename + " found on the classpath to direct us to an external properties file"); return null; } Properties properties = new Properties(); try { properties.load(in); } catch (IOException e) { logger.log(Level.SEVERE, "found " + classpathPropertiesFilename + " on the classpath but couldn't load it as a properties file", e); return null; } String template = properties.getProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); if (template == null) { logger.log(Level.SEVERE, "found properties file " + classpathPropertiesFilename + " on the classpath, but it didn't contain a property named " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY); return null; } if (properties.entrySet().size() > 1) logger.warning("the properties file " + classpathPropertiesFilename + " contained properties besides " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY + "; ignoring"); logger.fine("substituting system properties into '" + template + "'"); File configFile = new File(new StrSubstitutor(systemPropertiesLookup(env)).replace(template)); logger.info("derived configuration file name: " + configFile); return configFile; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); } | PropertiesFileResolver { File findCloudPropertiesFileFromClasspath() { InputStream in = getClass().getClassLoader().getResourceAsStream(classpathPropertiesFilename); if (in == null) { logger.info("no " + classpathPropertiesFilename + " found on the classpath to direct us to an external properties file"); return null; } Properties properties = new Properties(); try { properties.load(in); } catch (IOException e) { logger.log(Level.SEVERE, "found " + classpathPropertiesFilename + " on the classpath but couldn't load it as a properties file", e); return null; } String template = properties.getProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); if (template == null) { logger.log(Level.SEVERE, "found properties file " + classpathPropertiesFilename + " on the classpath, but it didn't contain a property named " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY); return null; } if (properties.entrySet().size() > 1) logger.warning("the properties file " + classpathPropertiesFilename + " contained properties besides " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY + "; ignoring"); logger.fine("substituting system properties into '" + template + "'"); File configFile = new File(new StrSubstitutor(systemPropertiesLookup(env)).replace(template)); logger.info("derived configuration file name: " + configFile); return configFile; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); static final String BOOTSTRAP_PROPERTIES_FILENAME; } |
@Test public void cloudRetriveal() { CloudFactory cloudFactory = new CloudFactory(); Cloud cloud = cloudFactory.getCloud(); assertNotNull(cloud); } | public Cloud getCloud() { CloudConnector suitableCloudConnector = null; for (CloudConnector cloudConnector : cloudConnectors) { if (cloudConnector.isInMatchingCloud()) { suitableCloudConnector = cloudConnector; break; } } if (suitableCloudConnector == null) { throw new CloudException("No suitable cloud connector found"); } return new Cloud(suitableCloudConnector, serviceCreators); } | CloudFactory { public Cloud getCloud() { CloudConnector suitableCloudConnector = null; for (CloudConnector cloudConnector : cloudConnectors) { if (cloudConnector.isInMatchingCloud()) { suitableCloudConnector = cloudConnector; break; } } if (suitableCloudConnector == null) { throw new CloudException("No suitable cloud connector found"); } return new Cloud(suitableCloudConnector, serviceCreators); } } | CloudFactory { public Cloud getCloud() { CloudConnector suitableCloudConnector = null; for (CloudConnector cloudConnector : cloudConnectors) { if (cloudConnector.isInMatchingCloud()) { suitableCloudConnector = cloudConnector; break; } } if (suitableCloudConnector == null) { throw new CloudException("No suitable cloud connector found"); } return new Cloud(suitableCloudConnector, serviceCreators); } CloudFactory(); } | CloudFactory { public Cloud getCloud() { CloudConnector suitableCloudConnector = null; for (CloudConnector cloudConnector : cloudConnectors) { if (cloudConnector.isInMatchingCloud()) { suitableCloudConnector = cloudConnector; break; } } if (suitableCloudConnector == null) { throw new CloudException("No suitable cloud connector found"); } return new Cloud(suitableCloudConnector, serviceCreators); } CloudFactory(); Cloud getCloud(); void registerCloudConnector(CloudConnector cloudConnector); } | CloudFactory { public Cloud getCloud() { CloudConnector suitableCloudConnector = null; for (CloudConnector cloudConnector : cloudConnectors) { if (cloudConnector.isInMatchingCloud()) { suitableCloudConnector = cloudConnector; break; } } if (suitableCloudConnector == null) { throw new CloudException("No suitable cloud connector found"); } return new Cloud(suitableCloudConnector, serviceCreators); } CloudFactory(); Cloud getCloud(); void registerCloudConnector(CloudConnector cloudConnector); } |
@Test public void testLiteral() { resolver = new PropertiesFileResolver(env, "spring-cloud-literal.properties"); assertEquals(PROPERTIES_FILE_NAME, resolver.findCloudPropertiesFileFromClasspath().getPath()); } | File findCloudPropertiesFileFromClasspath() { InputStream in = getClass().getClassLoader().getResourceAsStream(classpathPropertiesFilename); if (in == null) { logger.info("no " + classpathPropertiesFilename + " found on the classpath to direct us to an external properties file"); return null; } Properties properties = new Properties(); try { properties.load(in); } catch (IOException e) { logger.log(Level.SEVERE, "found " + classpathPropertiesFilename + " on the classpath but couldn't load it as a properties file", e); return null; } String template = properties.getProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); if (template == null) { logger.log(Level.SEVERE, "found properties file " + classpathPropertiesFilename + " on the classpath, but it didn't contain a property named " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY); return null; } if (properties.entrySet().size() > 1) logger.warning("the properties file " + classpathPropertiesFilename + " contained properties besides " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY + "; ignoring"); logger.fine("substituting system properties into '" + template + "'"); File configFile = new File(new StrSubstitutor(systemPropertiesLookup(env)).replace(template)); logger.info("derived configuration file name: " + configFile); return configFile; } | PropertiesFileResolver { File findCloudPropertiesFileFromClasspath() { InputStream in = getClass().getClassLoader().getResourceAsStream(classpathPropertiesFilename); if (in == null) { logger.info("no " + classpathPropertiesFilename + " found on the classpath to direct us to an external properties file"); return null; } Properties properties = new Properties(); try { properties.load(in); } catch (IOException e) { logger.log(Level.SEVERE, "found " + classpathPropertiesFilename + " on the classpath but couldn't load it as a properties file", e); return null; } String template = properties.getProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); if (template == null) { logger.log(Level.SEVERE, "found properties file " + classpathPropertiesFilename + " on the classpath, but it didn't contain a property named " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY); return null; } if (properties.entrySet().size() > 1) logger.warning("the properties file " + classpathPropertiesFilename + " contained properties besides " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY + "; ignoring"); logger.fine("substituting system properties into '" + template + "'"); File configFile = new File(new StrSubstitutor(systemPropertiesLookup(env)).replace(template)); logger.info("derived configuration file name: " + configFile); return configFile; } } | PropertiesFileResolver { File findCloudPropertiesFileFromClasspath() { InputStream in = getClass().getClassLoader().getResourceAsStream(classpathPropertiesFilename); if (in == null) { logger.info("no " + classpathPropertiesFilename + " found on the classpath to direct us to an external properties file"); return null; } Properties properties = new Properties(); try { properties.load(in); } catch (IOException e) { logger.log(Level.SEVERE, "found " + classpathPropertiesFilename + " on the classpath but couldn't load it as a properties file", e); return null; } String template = properties.getProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); if (template == null) { logger.log(Level.SEVERE, "found properties file " + classpathPropertiesFilename + " on the classpath, but it didn't contain a property named " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY); return null; } if (properties.entrySet().size() > 1) logger.warning("the properties file " + classpathPropertiesFilename + " contained properties besides " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY + "; ignoring"); logger.fine("substituting system properties into '" + template + "'"); File configFile = new File(new StrSubstitutor(systemPropertiesLookup(env)).replace(template)); logger.info("derived configuration file name: " + configFile); return configFile; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); } | PropertiesFileResolver { File findCloudPropertiesFileFromClasspath() { InputStream in = getClass().getClassLoader().getResourceAsStream(classpathPropertiesFilename); if (in == null) { logger.info("no " + classpathPropertiesFilename + " found on the classpath to direct us to an external properties file"); return null; } Properties properties = new Properties(); try { properties.load(in); } catch (IOException e) { logger.log(Level.SEVERE, "found " + classpathPropertiesFilename + " on the classpath but couldn't load it as a properties file", e); return null; } String template = properties.getProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); if (template == null) { logger.log(Level.SEVERE, "found properties file " + classpathPropertiesFilename + " on the classpath, but it didn't contain a property named " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY); return null; } if (properties.entrySet().size() > 1) logger.warning("the properties file " + classpathPropertiesFilename + " contained properties besides " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY + "; ignoring"); logger.fine("substituting system properties into '" + template + "'"); File configFile = new File(new StrSubstitutor(systemPropertiesLookup(env)).replace(template)); logger.info("derived configuration file name: " + configFile); return configFile; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); } | PropertiesFileResolver { File findCloudPropertiesFileFromClasspath() { InputStream in = getClass().getClassLoader().getResourceAsStream(classpathPropertiesFilename); if (in == null) { logger.info("no " + classpathPropertiesFilename + " found on the classpath to direct us to an external properties file"); return null; } Properties properties = new Properties(); try { properties.load(in); } catch (IOException e) { logger.log(Level.SEVERE, "found " + classpathPropertiesFilename + " on the classpath but couldn't load it as a properties file", e); return null; } String template = properties.getProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); if (template == null) { logger.log(Level.SEVERE, "found properties file " + classpathPropertiesFilename + " on the classpath, but it didn't contain a property named " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY); return null; } if (properties.entrySet().size() > 1) logger.warning("the properties file " + classpathPropertiesFilename + " contained properties besides " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY + "; ignoring"); logger.fine("substituting system properties into '" + template + "'"); File configFile = new File(new StrSubstitutor(systemPropertiesLookup(env)).replace(template)); logger.info("derived configuration file name: " + configFile); return configFile; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); static final String BOOTSTRAP_PROPERTIES_FILENAME; } |
@Test public void testTemplate() { resolver = new PropertiesFileResolver(env, "spring-cloud-template.properties"); env.setSystemProperty("user.home", "/foo"); assertEquals(PROPERTIES_FILE_NAME, resolver.findCloudPropertiesFileFromClasspath().getPath()); } | File findCloudPropertiesFileFromClasspath() { InputStream in = getClass().getClassLoader().getResourceAsStream(classpathPropertiesFilename); if (in == null) { logger.info("no " + classpathPropertiesFilename + " found on the classpath to direct us to an external properties file"); return null; } Properties properties = new Properties(); try { properties.load(in); } catch (IOException e) { logger.log(Level.SEVERE, "found " + classpathPropertiesFilename + " on the classpath but couldn't load it as a properties file", e); return null; } String template = properties.getProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); if (template == null) { logger.log(Level.SEVERE, "found properties file " + classpathPropertiesFilename + " on the classpath, but it didn't contain a property named " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY); return null; } if (properties.entrySet().size() > 1) logger.warning("the properties file " + classpathPropertiesFilename + " contained properties besides " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY + "; ignoring"); logger.fine("substituting system properties into '" + template + "'"); File configFile = new File(new StrSubstitutor(systemPropertiesLookup(env)).replace(template)); logger.info("derived configuration file name: " + configFile); return configFile; } | PropertiesFileResolver { File findCloudPropertiesFileFromClasspath() { InputStream in = getClass().getClassLoader().getResourceAsStream(classpathPropertiesFilename); if (in == null) { logger.info("no " + classpathPropertiesFilename + " found on the classpath to direct us to an external properties file"); return null; } Properties properties = new Properties(); try { properties.load(in); } catch (IOException e) { logger.log(Level.SEVERE, "found " + classpathPropertiesFilename + " on the classpath but couldn't load it as a properties file", e); return null; } String template = properties.getProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); if (template == null) { logger.log(Level.SEVERE, "found properties file " + classpathPropertiesFilename + " on the classpath, but it didn't contain a property named " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY); return null; } if (properties.entrySet().size() > 1) logger.warning("the properties file " + classpathPropertiesFilename + " contained properties besides " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY + "; ignoring"); logger.fine("substituting system properties into '" + template + "'"); File configFile = new File(new StrSubstitutor(systemPropertiesLookup(env)).replace(template)); logger.info("derived configuration file name: " + configFile); return configFile; } } | PropertiesFileResolver { File findCloudPropertiesFileFromClasspath() { InputStream in = getClass().getClassLoader().getResourceAsStream(classpathPropertiesFilename); if (in == null) { logger.info("no " + classpathPropertiesFilename + " found on the classpath to direct us to an external properties file"); return null; } Properties properties = new Properties(); try { properties.load(in); } catch (IOException e) { logger.log(Level.SEVERE, "found " + classpathPropertiesFilename + " on the classpath but couldn't load it as a properties file", e); return null; } String template = properties.getProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); if (template == null) { logger.log(Level.SEVERE, "found properties file " + classpathPropertiesFilename + " on the classpath, but it didn't contain a property named " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY); return null; } if (properties.entrySet().size() > 1) logger.warning("the properties file " + classpathPropertiesFilename + " contained properties besides " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY + "; ignoring"); logger.fine("substituting system properties into '" + template + "'"); File configFile = new File(new StrSubstitutor(systemPropertiesLookup(env)).replace(template)); logger.info("derived configuration file name: " + configFile); return configFile; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); } | PropertiesFileResolver { File findCloudPropertiesFileFromClasspath() { InputStream in = getClass().getClassLoader().getResourceAsStream(classpathPropertiesFilename); if (in == null) { logger.info("no " + classpathPropertiesFilename + " found on the classpath to direct us to an external properties file"); return null; } Properties properties = new Properties(); try { properties.load(in); } catch (IOException e) { logger.log(Level.SEVERE, "found " + classpathPropertiesFilename + " on the classpath but couldn't load it as a properties file", e); return null; } String template = properties.getProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); if (template == null) { logger.log(Level.SEVERE, "found properties file " + classpathPropertiesFilename + " on the classpath, but it didn't contain a property named " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY); return null; } if (properties.entrySet().size() > 1) logger.warning("the properties file " + classpathPropertiesFilename + " contained properties besides " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY + "; ignoring"); logger.fine("substituting system properties into '" + template + "'"); File configFile = new File(new StrSubstitutor(systemPropertiesLookup(env)).replace(template)); logger.info("derived configuration file name: " + configFile); return configFile; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); } | PropertiesFileResolver { File findCloudPropertiesFileFromClasspath() { InputStream in = getClass().getClassLoader().getResourceAsStream(classpathPropertiesFilename); if (in == null) { logger.info("no " + classpathPropertiesFilename + " found on the classpath to direct us to an external properties file"); return null; } Properties properties = new Properties(); try { properties.load(in); } catch (IOException e) { logger.log(Level.SEVERE, "found " + classpathPropertiesFilename + " on the classpath but couldn't load it as a properties file", e); return null; } String template = properties.getProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY); if (template == null) { logger.log(Level.SEVERE, "found properties file " + classpathPropertiesFilename + " on the classpath, but it didn't contain a property named " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY); return null; } if (properties.entrySet().size() > 1) logger.warning("the properties file " + classpathPropertiesFilename + " contained properties besides " + LocalConfigConnector.PROPERTIES_FILE_PROPERTY + "; ignoring"); logger.fine("substituting system properties into '" + template + "'"); File configFile = new File(new StrSubstitutor(systemPropertiesLookup(env)).replace(template)); logger.info("derived configuration file name: " + configFile); return configFile; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); static final String BOOTSTRAP_PROPERTIES_FILENAME; } |
@Test public void testFromSystem() { env.setSystemProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY, PROPERTIES_FILE_NAME); assertEquals(PROPERTIES_FILE_NAME, resolver.findCloudPropertiesFile().getPath()); } | File findCloudPropertiesFile() { File file = findCloudPropertiesFileFromSystem(); if (file != null) { logger.info("using configuration file from system properties"); return file; } file = findCloudPropertiesFileFromClasspath(); if (file != null) logger.info("using configuration file derived from " + classpathPropertiesFilename); else logger.info("did not find any Spring Cloud configuration file"); return file; } | PropertiesFileResolver { File findCloudPropertiesFile() { File file = findCloudPropertiesFileFromSystem(); if (file != null) { logger.info("using configuration file from system properties"); return file; } file = findCloudPropertiesFileFromClasspath(); if (file != null) logger.info("using configuration file derived from " + classpathPropertiesFilename); else logger.info("did not find any Spring Cloud configuration file"); return file; } } | PropertiesFileResolver { File findCloudPropertiesFile() { File file = findCloudPropertiesFileFromSystem(); if (file != null) { logger.info("using configuration file from system properties"); return file; } file = findCloudPropertiesFileFromClasspath(); if (file != null) logger.info("using configuration file derived from " + classpathPropertiesFilename); else logger.info("did not find any Spring Cloud configuration file"); return file; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); } | PropertiesFileResolver { File findCloudPropertiesFile() { File file = findCloudPropertiesFileFromSystem(); if (file != null) { logger.info("using configuration file from system properties"); return file; } file = findCloudPropertiesFileFromClasspath(); if (file != null) logger.info("using configuration file derived from " + classpathPropertiesFilename); else logger.info("did not find any Spring Cloud configuration file"); return file; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); } | PropertiesFileResolver { File findCloudPropertiesFile() { File file = findCloudPropertiesFileFromSystem(); if (file != null) { logger.info("using configuration file from system properties"); return file; } file = findCloudPropertiesFileFromClasspath(); if (file != null) logger.info("using configuration file derived from " + classpathPropertiesFilename); else logger.info("did not find any Spring Cloud configuration file"); return file; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); static final String BOOTSTRAP_PROPERTIES_FILENAME; } |
@Test public void testFromClasspath() { resolver = new PropertiesFileResolver(env, "spring-cloud-template.properties"); env.setSystemProperty("user.home", "/foo"); assertEquals(PROPERTIES_FILE_NAME, resolver.findCloudPropertiesFile().getPath()); } | File findCloudPropertiesFile() { File file = findCloudPropertiesFileFromSystem(); if (file != null) { logger.info("using configuration file from system properties"); return file; } file = findCloudPropertiesFileFromClasspath(); if (file != null) logger.info("using configuration file derived from " + classpathPropertiesFilename); else logger.info("did not find any Spring Cloud configuration file"); return file; } | PropertiesFileResolver { File findCloudPropertiesFile() { File file = findCloudPropertiesFileFromSystem(); if (file != null) { logger.info("using configuration file from system properties"); return file; } file = findCloudPropertiesFileFromClasspath(); if (file != null) logger.info("using configuration file derived from " + classpathPropertiesFilename); else logger.info("did not find any Spring Cloud configuration file"); return file; } } | PropertiesFileResolver { File findCloudPropertiesFile() { File file = findCloudPropertiesFileFromSystem(); if (file != null) { logger.info("using configuration file from system properties"); return file; } file = findCloudPropertiesFileFromClasspath(); if (file != null) logger.info("using configuration file derived from " + classpathPropertiesFilename); else logger.info("did not find any Spring Cloud configuration file"); return file; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); } | PropertiesFileResolver { File findCloudPropertiesFile() { File file = findCloudPropertiesFileFromSystem(); if (file != null) { logger.info("using configuration file from system properties"); return file; } file = findCloudPropertiesFileFromClasspath(); if (file != null) logger.info("using configuration file derived from " + classpathPropertiesFilename); else logger.info("did not find any Spring Cloud configuration file"); return file; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); } | PropertiesFileResolver { File findCloudPropertiesFile() { File file = findCloudPropertiesFileFromSystem(); if (file != null) { logger.info("using configuration file from system properties"); return file; } file = findCloudPropertiesFileFromClasspath(); if (file != null) logger.info("using configuration file derived from " + classpathPropertiesFilename); else logger.info("did not find any Spring Cloud configuration file"); return file; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); static final String BOOTSTRAP_PROPERTIES_FILENAME; } |
@Test public void testNowhere() { assertNull(resolver.findCloudPropertiesFile()); } | File findCloudPropertiesFile() { File file = findCloudPropertiesFileFromSystem(); if (file != null) { logger.info("using configuration file from system properties"); return file; } file = findCloudPropertiesFileFromClasspath(); if (file != null) logger.info("using configuration file derived from " + classpathPropertiesFilename); else logger.info("did not find any Spring Cloud configuration file"); return file; } | PropertiesFileResolver { File findCloudPropertiesFile() { File file = findCloudPropertiesFileFromSystem(); if (file != null) { logger.info("using configuration file from system properties"); return file; } file = findCloudPropertiesFileFromClasspath(); if (file != null) logger.info("using configuration file derived from " + classpathPropertiesFilename); else logger.info("did not find any Spring Cloud configuration file"); return file; } } | PropertiesFileResolver { File findCloudPropertiesFile() { File file = findCloudPropertiesFileFromSystem(); if (file != null) { logger.info("using configuration file from system properties"); return file; } file = findCloudPropertiesFileFromClasspath(); if (file != null) logger.info("using configuration file derived from " + classpathPropertiesFilename); else logger.info("did not find any Spring Cloud configuration file"); return file; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); } | PropertiesFileResolver { File findCloudPropertiesFile() { File file = findCloudPropertiesFileFromSystem(); if (file != null) { logger.info("using configuration file from system properties"); return file; } file = findCloudPropertiesFileFromClasspath(); if (file != null) logger.info("using configuration file derived from " + classpathPropertiesFilename); else logger.info("did not find any Spring Cloud configuration file"); return file; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); } | PropertiesFileResolver { File findCloudPropertiesFile() { File file = findCloudPropertiesFileFromSystem(); if (file != null) { logger.info("using configuration file from system properties"); return file; } file = findCloudPropertiesFileFromClasspath(); if (file != null) logger.info("using configuration file derived from " + classpathPropertiesFilename); else logger.info("did not find any Spring Cloud configuration file"); return file; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); static final String BOOTSTRAP_PROPERTIES_FILENAME; } |
@Test public void testPrecedence() { env.setSystemProperty(LocalConfigConnector.PROPERTIES_FILE_PROPERTY, PROPERTIES_FILE_NAME); resolver = new PropertiesFileResolver(env, "spring-cloud-literal.properties"); assertEquals(PROPERTIES_FILE_NAME, resolver.findCloudPropertiesFile().getPath()); } | File findCloudPropertiesFile() { File file = findCloudPropertiesFileFromSystem(); if (file != null) { logger.info("using configuration file from system properties"); return file; } file = findCloudPropertiesFileFromClasspath(); if (file != null) logger.info("using configuration file derived from " + classpathPropertiesFilename); else logger.info("did not find any Spring Cloud configuration file"); return file; } | PropertiesFileResolver { File findCloudPropertiesFile() { File file = findCloudPropertiesFileFromSystem(); if (file != null) { logger.info("using configuration file from system properties"); return file; } file = findCloudPropertiesFileFromClasspath(); if (file != null) logger.info("using configuration file derived from " + classpathPropertiesFilename); else logger.info("did not find any Spring Cloud configuration file"); return file; } } | PropertiesFileResolver { File findCloudPropertiesFile() { File file = findCloudPropertiesFileFromSystem(); if (file != null) { logger.info("using configuration file from system properties"); return file; } file = findCloudPropertiesFileFromClasspath(); if (file != null) logger.info("using configuration file derived from " + classpathPropertiesFilename); else logger.info("did not find any Spring Cloud configuration file"); return file; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); } | PropertiesFileResolver { File findCloudPropertiesFile() { File file = findCloudPropertiesFileFromSystem(); if (file != null) { logger.info("using configuration file from system properties"); return file; } file = findCloudPropertiesFileFromClasspath(); if (file != null) logger.info("using configuration file derived from " + classpathPropertiesFilename); else logger.info("did not find any Spring Cloud configuration file"); return file; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); } | PropertiesFileResolver { File findCloudPropertiesFile() { File file = findCloudPropertiesFileFromSystem(); if (file != null) { logger.info("using configuration file from system properties"); return file; } file = findCloudPropertiesFileFromClasspath(); if (file != null) logger.info("using configuration file derived from " + classpathPropertiesFilename); else logger.info("did not find any Spring Cloud configuration file"); return file; } PropertiesFileResolver(final EnvironmentAccessor env, final String classpathPropertiesFilename); PropertiesFileResolver(final EnvironmentAccessor env); PropertiesFileResolver(); static final String BOOTSTRAP_PROPERTIES_FILENAME; } |
@Test public void shouldCreateCluster() throws Exception { CassandraServiceInfo info = new CassandraServiceInfo("local", Collections.singletonList("127.0.0.1"), 9142); Cluster cluster = creator.create(info, null); Configuration configuration = cluster.getConfiguration(); assertThat(configuration.getProtocolOptions().getAuthProvider(), is(AuthProvider.NONE)); } | @Override public Cluster create(CassandraServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { Builder builder = Cluster.builder() .addContactPoints(serviceInfo.getContactPoints().toArray(new String[0])) .withPort(serviceInfo.getPort()); if (StringUtils.hasText(serviceInfo.getUsername())) { builder.withCredentials(serviceInfo.getUsername(), serviceInfo.getPassword()); } if (serviceConnectorConfig instanceof CassandraClusterConfig) { CassandraClusterConfig config = (CassandraClusterConfig) serviceConnectorConfig; if (config.getCompression() != null) { builder.withCompression(config.getCompression()); } builder.withPoolingOptions(config.getPoolingOptions()); builder.withSocketOptions(config.getSocketOptions()); builder.withQueryOptions(config.getQueryOptions()); builder.withNettyOptions(config.getNettyOptions()); builder.withLoadBalancingPolicy(config.getLoadBalancingPolicy()); builder.withReconnectionPolicy(config.getReconnectionPolicy()); builder.withRetryPolicy(config.getRetryPolicy()); if (config.getProtocolVersion() != null) { builder.withProtocolVersion(config.getProtocolVersion()); } if (!config.isMetricsEnabled()) { builder.withoutMetrics(); } if (!config.isJmxReportingEnabled()) { builder.withoutJMXReporting(); } } return builder.build(); } | CassandraClusterCreator extends AbstractServiceConnectorCreator<Cluster, CassandraServiceInfo> { @Override public Cluster create(CassandraServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { Builder builder = Cluster.builder() .addContactPoints(serviceInfo.getContactPoints().toArray(new String[0])) .withPort(serviceInfo.getPort()); if (StringUtils.hasText(serviceInfo.getUsername())) { builder.withCredentials(serviceInfo.getUsername(), serviceInfo.getPassword()); } if (serviceConnectorConfig instanceof CassandraClusterConfig) { CassandraClusterConfig config = (CassandraClusterConfig) serviceConnectorConfig; if (config.getCompression() != null) { builder.withCompression(config.getCompression()); } builder.withPoolingOptions(config.getPoolingOptions()); builder.withSocketOptions(config.getSocketOptions()); builder.withQueryOptions(config.getQueryOptions()); builder.withNettyOptions(config.getNettyOptions()); builder.withLoadBalancingPolicy(config.getLoadBalancingPolicy()); builder.withReconnectionPolicy(config.getReconnectionPolicy()); builder.withRetryPolicy(config.getRetryPolicy()); if (config.getProtocolVersion() != null) { builder.withProtocolVersion(config.getProtocolVersion()); } if (!config.isMetricsEnabled()) { builder.withoutMetrics(); } if (!config.isJmxReportingEnabled()) { builder.withoutJMXReporting(); } } return builder.build(); } } | CassandraClusterCreator extends AbstractServiceConnectorCreator<Cluster, CassandraServiceInfo> { @Override public Cluster create(CassandraServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { Builder builder = Cluster.builder() .addContactPoints(serviceInfo.getContactPoints().toArray(new String[0])) .withPort(serviceInfo.getPort()); if (StringUtils.hasText(serviceInfo.getUsername())) { builder.withCredentials(serviceInfo.getUsername(), serviceInfo.getPassword()); } if (serviceConnectorConfig instanceof CassandraClusterConfig) { CassandraClusterConfig config = (CassandraClusterConfig) serviceConnectorConfig; if (config.getCompression() != null) { builder.withCompression(config.getCompression()); } builder.withPoolingOptions(config.getPoolingOptions()); builder.withSocketOptions(config.getSocketOptions()); builder.withQueryOptions(config.getQueryOptions()); builder.withNettyOptions(config.getNettyOptions()); builder.withLoadBalancingPolicy(config.getLoadBalancingPolicy()); builder.withReconnectionPolicy(config.getReconnectionPolicy()); builder.withRetryPolicy(config.getRetryPolicy()); if (config.getProtocolVersion() != null) { builder.withProtocolVersion(config.getProtocolVersion()); } if (!config.isMetricsEnabled()) { builder.withoutMetrics(); } if (!config.isJmxReportingEnabled()) { builder.withoutJMXReporting(); } } return builder.build(); } } | CassandraClusterCreator extends AbstractServiceConnectorCreator<Cluster, CassandraServiceInfo> { @Override public Cluster create(CassandraServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { Builder builder = Cluster.builder() .addContactPoints(serviceInfo.getContactPoints().toArray(new String[0])) .withPort(serviceInfo.getPort()); if (StringUtils.hasText(serviceInfo.getUsername())) { builder.withCredentials(serviceInfo.getUsername(), serviceInfo.getPassword()); } if (serviceConnectorConfig instanceof CassandraClusterConfig) { CassandraClusterConfig config = (CassandraClusterConfig) serviceConnectorConfig; if (config.getCompression() != null) { builder.withCompression(config.getCompression()); } builder.withPoolingOptions(config.getPoolingOptions()); builder.withSocketOptions(config.getSocketOptions()); builder.withQueryOptions(config.getQueryOptions()); builder.withNettyOptions(config.getNettyOptions()); builder.withLoadBalancingPolicy(config.getLoadBalancingPolicy()); builder.withReconnectionPolicy(config.getReconnectionPolicy()); builder.withRetryPolicy(config.getRetryPolicy()); if (config.getProtocolVersion() != null) { builder.withProtocolVersion(config.getProtocolVersion()); } if (!config.isMetricsEnabled()) { builder.withoutMetrics(); } if (!config.isJmxReportingEnabled()) { builder.withoutJMXReporting(); } } return builder.build(); } @Override Cluster create(CassandraServiceInfo serviceInfo,
ServiceConnectorConfig serviceConnectorConfig); } | CassandraClusterCreator extends AbstractServiceConnectorCreator<Cluster, CassandraServiceInfo> { @Override public Cluster create(CassandraServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { Builder builder = Cluster.builder() .addContactPoints(serviceInfo.getContactPoints().toArray(new String[0])) .withPort(serviceInfo.getPort()); if (StringUtils.hasText(serviceInfo.getUsername())) { builder.withCredentials(serviceInfo.getUsername(), serviceInfo.getPassword()); } if (serviceConnectorConfig instanceof CassandraClusterConfig) { CassandraClusterConfig config = (CassandraClusterConfig) serviceConnectorConfig; if (config.getCompression() != null) { builder.withCompression(config.getCompression()); } builder.withPoolingOptions(config.getPoolingOptions()); builder.withSocketOptions(config.getSocketOptions()); builder.withQueryOptions(config.getQueryOptions()); builder.withNettyOptions(config.getNettyOptions()); builder.withLoadBalancingPolicy(config.getLoadBalancingPolicy()); builder.withReconnectionPolicy(config.getReconnectionPolicy()); builder.withRetryPolicy(config.getRetryPolicy()); if (config.getProtocolVersion() != null) { builder.withProtocolVersion(config.getProtocolVersion()); } if (!config.isMetricsEnabled()) { builder.withoutMetrics(); } if (!config.isJmxReportingEnabled()) { builder.withoutJMXReporting(); } } return builder.build(); } @Override Cluster create(CassandraServiceInfo serviceInfo,
ServiceConnectorConfig serviceConnectorConfig); } |
@Test public void shouldCreateClusterWithAuthentication() throws Exception { CassandraServiceInfo info = new CassandraServiceInfo("local", Collections.singletonList("127.0.0.1"), 9142, "walter", "white"); Cluster cluster = creator.create(info, null); Configuration configuration = cluster.getConfiguration(); assertThat(configuration.getProtocolOptions().getAuthProvider(), is(instanceOf(PlainTextAuthProvider.class))); } | @Override public Cluster create(CassandraServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { Builder builder = Cluster.builder() .addContactPoints(serviceInfo.getContactPoints().toArray(new String[0])) .withPort(serviceInfo.getPort()); if (StringUtils.hasText(serviceInfo.getUsername())) { builder.withCredentials(serviceInfo.getUsername(), serviceInfo.getPassword()); } if (serviceConnectorConfig instanceof CassandraClusterConfig) { CassandraClusterConfig config = (CassandraClusterConfig) serviceConnectorConfig; if (config.getCompression() != null) { builder.withCompression(config.getCompression()); } builder.withPoolingOptions(config.getPoolingOptions()); builder.withSocketOptions(config.getSocketOptions()); builder.withQueryOptions(config.getQueryOptions()); builder.withNettyOptions(config.getNettyOptions()); builder.withLoadBalancingPolicy(config.getLoadBalancingPolicy()); builder.withReconnectionPolicy(config.getReconnectionPolicy()); builder.withRetryPolicy(config.getRetryPolicy()); if (config.getProtocolVersion() != null) { builder.withProtocolVersion(config.getProtocolVersion()); } if (!config.isMetricsEnabled()) { builder.withoutMetrics(); } if (!config.isJmxReportingEnabled()) { builder.withoutJMXReporting(); } } return builder.build(); } | CassandraClusterCreator extends AbstractServiceConnectorCreator<Cluster, CassandraServiceInfo> { @Override public Cluster create(CassandraServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { Builder builder = Cluster.builder() .addContactPoints(serviceInfo.getContactPoints().toArray(new String[0])) .withPort(serviceInfo.getPort()); if (StringUtils.hasText(serviceInfo.getUsername())) { builder.withCredentials(serviceInfo.getUsername(), serviceInfo.getPassword()); } if (serviceConnectorConfig instanceof CassandraClusterConfig) { CassandraClusterConfig config = (CassandraClusterConfig) serviceConnectorConfig; if (config.getCompression() != null) { builder.withCompression(config.getCompression()); } builder.withPoolingOptions(config.getPoolingOptions()); builder.withSocketOptions(config.getSocketOptions()); builder.withQueryOptions(config.getQueryOptions()); builder.withNettyOptions(config.getNettyOptions()); builder.withLoadBalancingPolicy(config.getLoadBalancingPolicy()); builder.withReconnectionPolicy(config.getReconnectionPolicy()); builder.withRetryPolicy(config.getRetryPolicy()); if (config.getProtocolVersion() != null) { builder.withProtocolVersion(config.getProtocolVersion()); } if (!config.isMetricsEnabled()) { builder.withoutMetrics(); } if (!config.isJmxReportingEnabled()) { builder.withoutJMXReporting(); } } return builder.build(); } } | CassandraClusterCreator extends AbstractServiceConnectorCreator<Cluster, CassandraServiceInfo> { @Override public Cluster create(CassandraServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { Builder builder = Cluster.builder() .addContactPoints(serviceInfo.getContactPoints().toArray(new String[0])) .withPort(serviceInfo.getPort()); if (StringUtils.hasText(serviceInfo.getUsername())) { builder.withCredentials(serviceInfo.getUsername(), serviceInfo.getPassword()); } if (serviceConnectorConfig instanceof CassandraClusterConfig) { CassandraClusterConfig config = (CassandraClusterConfig) serviceConnectorConfig; if (config.getCompression() != null) { builder.withCompression(config.getCompression()); } builder.withPoolingOptions(config.getPoolingOptions()); builder.withSocketOptions(config.getSocketOptions()); builder.withQueryOptions(config.getQueryOptions()); builder.withNettyOptions(config.getNettyOptions()); builder.withLoadBalancingPolicy(config.getLoadBalancingPolicy()); builder.withReconnectionPolicy(config.getReconnectionPolicy()); builder.withRetryPolicy(config.getRetryPolicy()); if (config.getProtocolVersion() != null) { builder.withProtocolVersion(config.getProtocolVersion()); } if (!config.isMetricsEnabled()) { builder.withoutMetrics(); } if (!config.isJmxReportingEnabled()) { builder.withoutJMXReporting(); } } return builder.build(); } } | CassandraClusterCreator extends AbstractServiceConnectorCreator<Cluster, CassandraServiceInfo> { @Override public Cluster create(CassandraServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { Builder builder = Cluster.builder() .addContactPoints(serviceInfo.getContactPoints().toArray(new String[0])) .withPort(serviceInfo.getPort()); if (StringUtils.hasText(serviceInfo.getUsername())) { builder.withCredentials(serviceInfo.getUsername(), serviceInfo.getPassword()); } if (serviceConnectorConfig instanceof CassandraClusterConfig) { CassandraClusterConfig config = (CassandraClusterConfig) serviceConnectorConfig; if (config.getCompression() != null) { builder.withCompression(config.getCompression()); } builder.withPoolingOptions(config.getPoolingOptions()); builder.withSocketOptions(config.getSocketOptions()); builder.withQueryOptions(config.getQueryOptions()); builder.withNettyOptions(config.getNettyOptions()); builder.withLoadBalancingPolicy(config.getLoadBalancingPolicy()); builder.withReconnectionPolicy(config.getReconnectionPolicy()); builder.withRetryPolicy(config.getRetryPolicy()); if (config.getProtocolVersion() != null) { builder.withProtocolVersion(config.getProtocolVersion()); } if (!config.isMetricsEnabled()) { builder.withoutMetrics(); } if (!config.isJmxReportingEnabled()) { builder.withoutJMXReporting(); } } return builder.build(); } @Override Cluster create(CassandraServiceInfo serviceInfo,
ServiceConnectorConfig serviceConnectorConfig); } | CassandraClusterCreator extends AbstractServiceConnectorCreator<Cluster, CassandraServiceInfo> { @Override public Cluster create(CassandraServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { Builder builder = Cluster.builder() .addContactPoints(serviceInfo.getContactPoints().toArray(new String[0])) .withPort(serviceInfo.getPort()); if (StringUtils.hasText(serviceInfo.getUsername())) { builder.withCredentials(serviceInfo.getUsername(), serviceInfo.getPassword()); } if (serviceConnectorConfig instanceof CassandraClusterConfig) { CassandraClusterConfig config = (CassandraClusterConfig) serviceConnectorConfig; if (config.getCompression() != null) { builder.withCompression(config.getCompression()); } builder.withPoolingOptions(config.getPoolingOptions()); builder.withSocketOptions(config.getSocketOptions()); builder.withQueryOptions(config.getQueryOptions()); builder.withNettyOptions(config.getNettyOptions()); builder.withLoadBalancingPolicy(config.getLoadBalancingPolicy()); builder.withReconnectionPolicy(config.getReconnectionPolicy()); builder.withRetryPolicy(config.getRetryPolicy()); if (config.getProtocolVersion() != null) { builder.withProtocolVersion(config.getProtocolVersion()); } if (!config.isMetricsEnabled()) { builder.withoutMetrics(); } if (!config.isJmxReportingEnabled()) { builder.withoutJMXReporting(); } } return builder.build(); } @Override Cluster create(CassandraServiceInfo serviceInfo,
ServiceConnectorConfig serviceConnectorConfig); } |
@Test public void shouldCreateClusterWithConfig() throws Exception { CassandraServiceInfo info = new CassandraServiceInfo("local", Collections.singletonList("127.0.0.1"), 9142); CassandraClusterConfig config = new CassandraClusterConfig(); config.setCompression(ProtocolOptions.Compression.NONE); config.setPoolingOptions(new PoolingOptions().setPoolTimeoutMillis(1234)); config.setQueryOptions(new QueryOptions()); config.setProtocolVersion(ProtocolVersion.NEWEST_SUPPORTED); config.setLoadBalancingPolicy(new RoundRobinPolicy()); config.setReconnectionPolicy(new ConstantReconnectionPolicy(1)); config.setRetryPolicy(DowngradingConsistencyRetryPolicy.INSTANCE); config.setSocketOptions(new SocketOptions()); Cluster cluster = creator.create(info, config); Configuration configuration = cluster.getConfiguration(); assertThat(configuration.getProtocolOptions().getCompression(), is(config.getCompression())); assertThat(configuration.getQueryOptions(), is(config.getQueryOptions())); assertThat(configuration.getSocketOptions(), is(config.getSocketOptions())); Policies policies = configuration.getPolicies(); assertThat(policies.getLoadBalancingPolicy(), is(config.getLoadBalancingPolicy())); assertThat(policies.getReconnectionPolicy(), is(config.getReconnectionPolicy())); assertThat(policies.getRetryPolicy(), is(config.getRetryPolicy())); } | @Override public Cluster create(CassandraServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { Builder builder = Cluster.builder() .addContactPoints(serviceInfo.getContactPoints().toArray(new String[0])) .withPort(serviceInfo.getPort()); if (StringUtils.hasText(serviceInfo.getUsername())) { builder.withCredentials(serviceInfo.getUsername(), serviceInfo.getPassword()); } if (serviceConnectorConfig instanceof CassandraClusterConfig) { CassandraClusterConfig config = (CassandraClusterConfig) serviceConnectorConfig; if (config.getCompression() != null) { builder.withCompression(config.getCompression()); } builder.withPoolingOptions(config.getPoolingOptions()); builder.withSocketOptions(config.getSocketOptions()); builder.withQueryOptions(config.getQueryOptions()); builder.withNettyOptions(config.getNettyOptions()); builder.withLoadBalancingPolicy(config.getLoadBalancingPolicy()); builder.withReconnectionPolicy(config.getReconnectionPolicy()); builder.withRetryPolicy(config.getRetryPolicy()); if (config.getProtocolVersion() != null) { builder.withProtocolVersion(config.getProtocolVersion()); } if (!config.isMetricsEnabled()) { builder.withoutMetrics(); } if (!config.isJmxReportingEnabled()) { builder.withoutJMXReporting(); } } return builder.build(); } | CassandraClusterCreator extends AbstractServiceConnectorCreator<Cluster, CassandraServiceInfo> { @Override public Cluster create(CassandraServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { Builder builder = Cluster.builder() .addContactPoints(serviceInfo.getContactPoints().toArray(new String[0])) .withPort(serviceInfo.getPort()); if (StringUtils.hasText(serviceInfo.getUsername())) { builder.withCredentials(serviceInfo.getUsername(), serviceInfo.getPassword()); } if (serviceConnectorConfig instanceof CassandraClusterConfig) { CassandraClusterConfig config = (CassandraClusterConfig) serviceConnectorConfig; if (config.getCompression() != null) { builder.withCompression(config.getCompression()); } builder.withPoolingOptions(config.getPoolingOptions()); builder.withSocketOptions(config.getSocketOptions()); builder.withQueryOptions(config.getQueryOptions()); builder.withNettyOptions(config.getNettyOptions()); builder.withLoadBalancingPolicy(config.getLoadBalancingPolicy()); builder.withReconnectionPolicy(config.getReconnectionPolicy()); builder.withRetryPolicy(config.getRetryPolicy()); if (config.getProtocolVersion() != null) { builder.withProtocolVersion(config.getProtocolVersion()); } if (!config.isMetricsEnabled()) { builder.withoutMetrics(); } if (!config.isJmxReportingEnabled()) { builder.withoutJMXReporting(); } } return builder.build(); } } | CassandraClusterCreator extends AbstractServiceConnectorCreator<Cluster, CassandraServiceInfo> { @Override public Cluster create(CassandraServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { Builder builder = Cluster.builder() .addContactPoints(serviceInfo.getContactPoints().toArray(new String[0])) .withPort(serviceInfo.getPort()); if (StringUtils.hasText(serviceInfo.getUsername())) { builder.withCredentials(serviceInfo.getUsername(), serviceInfo.getPassword()); } if (serviceConnectorConfig instanceof CassandraClusterConfig) { CassandraClusterConfig config = (CassandraClusterConfig) serviceConnectorConfig; if (config.getCompression() != null) { builder.withCompression(config.getCompression()); } builder.withPoolingOptions(config.getPoolingOptions()); builder.withSocketOptions(config.getSocketOptions()); builder.withQueryOptions(config.getQueryOptions()); builder.withNettyOptions(config.getNettyOptions()); builder.withLoadBalancingPolicy(config.getLoadBalancingPolicy()); builder.withReconnectionPolicy(config.getReconnectionPolicy()); builder.withRetryPolicy(config.getRetryPolicy()); if (config.getProtocolVersion() != null) { builder.withProtocolVersion(config.getProtocolVersion()); } if (!config.isMetricsEnabled()) { builder.withoutMetrics(); } if (!config.isJmxReportingEnabled()) { builder.withoutJMXReporting(); } } return builder.build(); } } | CassandraClusterCreator extends AbstractServiceConnectorCreator<Cluster, CassandraServiceInfo> { @Override public Cluster create(CassandraServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { Builder builder = Cluster.builder() .addContactPoints(serviceInfo.getContactPoints().toArray(new String[0])) .withPort(serviceInfo.getPort()); if (StringUtils.hasText(serviceInfo.getUsername())) { builder.withCredentials(serviceInfo.getUsername(), serviceInfo.getPassword()); } if (serviceConnectorConfig instanceof CassandraClusterConfig) { CassandraClusterConfig config = (CassandraClusterConfig) serviceConnectorConfig; if (config.getCompression() != null) { builder.withCompression(config.getCompression()); } builder.withPoolingOptions(config.getPoolingOptions()); builder.withSocketOptions(config.getSocketOptions()); builder.withQueryOptions(config.getQueryOptions()); builder.withNettyOptions(config.getNettyOptions()); builder.withLoadBalancingPolicy(config.getLoadBalancingPolicy()); builder.withReconnectionPolicy(config.getReconnectionPolicy()); builder.withRetryPolicy(config.getRetryPolicy()); if (config.getProtocolVersion() != null) { builder.withProtocolVersion(config.getProtocolVersion()); } if (!config.isMetricsEnabled()) { builder.withoutMetrics(); } if (!config.isJmxReportingEnabled()) { builder.withoutJMXReporting(); } } return builder.build(); } @Override Cluster create(CassandraServiceInfo serviceInfo,
ServiceConnectorConfig serviceConnectorConfig); } | CassandraClusterCreator extends AbstractServiceConnectorCreator<Cluster, CassandraServiceInfo> { @Override public Cluster create(CassandraServiceInfo serviceInfo, ServiceConnectorConfig serviceConnectorConfig) { Builder builder = Cluster.builder() .addContactPoints(serviceInfo.getContactPoints().toArray(new String[0])) .withPort(serviceInfo.getPort()); if (StringUtils.hasText(serviceInfo.getUsername())) { builder.withCredentials(serviceInfo.getUsername(), serviceInfo.getPassword()); } if (serviceConnectorConfig instanceof CassandraClusterConfig) { CassandraClusterConfig config = (CassandraClusterConfig) serviceConnectorConfig; if (config.getCompression() != null) { builder.withCompression(config.getCompression()); } builder.withPoolingOptions(config.getPoolingOptions()); builder.withSocketOptions(config.getSocketOptions()); builder.withQueryOptions(config.getQueryOptions()); builder.withNettyOptions(config.getNettyOptions()); builder.withLoadBalancingPolicy(config.getLoadBalancingPolicy()); builder.withReconnectionPolicy(config.getReconnectionPolicy()); builder.withRetryPolicy(config.getRetryPolicy()); if (config.getProtocolVersion() != null) { builder.withProtocolVersion(config.getProtocolVersion()); } if (!config.isMetricsEnabled()) { builder.withoutMetrics(); } if (!config.isJmxReportingEnabled()) { builder.withoutJMXReporting(); } } return builder.build(); } @Override Cluster create(CassandraServiceInfo serviceInfo,
ServiceConnectorConfig serviceConnectorConfig); } |
@Test public void whenConnectionToEncodedUrlIsSuccessful() throws SQLException { MockDataSource delegateDataSource = pooledDataSourceRequiringEncodedUrl(); UrlDecodingDataSource urlDecodingDataSource = new UrlDecodingDataSource(delegateDataSource, "url"); Connection connection = urlDecodingDataSource.getConnection(); assertNotNull("Returned connection must not be null", connection); assertEquals(ENCODED_URL, delegateDataSource.url); assertEquals("Connection must be made using the pooled (delegate) data source", TRUE, connection.getClientInfo(IS_POOLED)); } | @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } | UrlDecodingDataSource extends DelegatingDataSource { @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } } | UrlDecodingDataSource extends DelegatingDataSource { @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } UrlDecodingDataSource(String jdbcUrl); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName, Function<String, DataSource> connectionTestDataSourceFactory); } | UrlDecodingDataSource extends DelegatingDataSource { @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } UrlDecodingDataSource(String jdbcUrl); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName, Function<String, DataSource> connectionTestDataSourceFactory); @Override Connection getConnection(); } | UrlDecodingDataSource extends DelegatingDataSource { @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } UrlDecodingDataSource(String jdbcUrl); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName, Function<String, DataSource> connectionTestDataSourceFactory); @Override Connection getConnection(); } |
@Test public void jdbcUrl() { RelationalServiceInfo serviceInfo = createServiceInfoWithJdbcUrl("bad: "jdbc:jdbcdbtype: assertEquals("jdbc:jdbcdbtype: } | @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } | RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } } | RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType); RelationalServiceInfo(String id, String uriString, String jdbcUrl, String jdbcUrlDatabaseType); } | RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType); RelationalServiceInfo(String id, String uriString, String jdbcUrl, String jdbcUrlDatabaseType); @ServiceProperty(category = "connection") String getJdbcUrl(); } | RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType); RelationalServiceInfo(String id, String uriString, String jdbcUrl, String jdbcUrlDatabaseType); @ServiceProperty(category = "connection") String getJdbcUrl(); static final String JDBC_PREFIX; } |
@Test public void whenConnectionToDecodedUrlIsSuccessful() throws SQLException { MockDataSource delegateDataSource = pooledDataSourceRequiringDecodedUrl(); UrlDecodingDataSource urlDecodingDataSource = new UrlDecodingDataSource(delegateDataSource, URL_PROPERTY_NAME, UrlDecodingDataSourceTest::dataSourceRequiringDecodedUrl); Connection connection = urlDecodingDataSource.getConnection(); assertNotNull("Returned connection must not be null", connection); assertEquals(DECODED_URL, delegateDataSource.url); assertEquals("Connection must be made using the pooled (delegate) data source", TRUE, connection.getClientInfo(IS_POOLED)); } | @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } | UrlDecodingDataSource extends DelegatingDataSource { @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } } | UrlDecodingDataSource extends DelegatingDataSource { @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } UrlDecodingDataSource(String jdbcUrl); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName, Function<String, DataSource> connectionTestDataSourceFactory); } | UrlDecodingDataSource extends DelegatingDataSource { @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } UrlDecodingDataSource(String jdbcUrl); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName, Function<String, DataSource> connectionTestDataSourceFactory); @Override Connection getConnection(); } | UrlDecodingDataSource extends DelegatingDataSource { @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } UrlDecodingDataSource(String jdbcUrl); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName, Function<String, DataSource> connectionTestDataSourceFactory); @Override Connection getConnection(); } |
@Test(expected = SQLException.class) public void whenNoConnectionIsSuccessful() throws SQLException { MockDataSource delegateDataSource = pooledDataSourceUnableToConnectToAnyUrl(); UrlDecodingDataSource urlDecodingDataSource = new UrlDecodingDataSource(delegateDataSource, URL_PROPERTY_NAME, UrlDecodingDataSourceTest::dataSourceUnableToConnectToAnyUrl); try { urlDecodingDataSource.getConnection(); } catch (SQLException e) { assertEquals(ENCODED_URL, delegateDataSource.url); throw e; } } | @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } | UrlDecodingDataSource extends DelegatingDataSource { @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } } | UrlDecodingDataSource extends DelegatingDataSource { @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } UrlDecodingDataSource(String jdbcUrl); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName, Function<String, DataSource> connectionTestDataSourceFactory); } | UrlDecodingDataSource extends DelegatingDataSource { @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } UrlDecodingDataSource(String jdbcUrl); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName, Function<String, DataSource> connectionTestDataSourceFactory); @Override Connection getConnection(); } | UrlDecodingDataSource extends DelegatingDataSource { @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } UrlDecodingDataSource(String jdbcUrl); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName, Function<String, DataSource> connectionTestDataSourceFactory); @Override Connection getConnection(); } |
@Test public void successfulUrlDecodedConnectionTestIsOnlyPerformedOnce() throws SQLException { MockDataSource delegateDataSource = pooledDataSourceRequiringDecodedUrl(); DataSource decodedUrlConnectionTestDataSource = mock(DataSource.class); when(decodedUrlConnectionTestDataSource.getConnection()).thenReturn(mock(Connection.class)); UrlDecodingDataSource urlDecodingDataSource = new UrlDecodingDataSource(delegateDataSource, URL_PROPERTY_NAME, url -> decodedUrlConnectionTestDataSource); urlDecodingDataSource.getConnection(); urlDecodingDataSource.getConnection(); verify(decodedUrlConnectionTestDataSource, times(1)).getConnection(); } | @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } | UrlDecodingDataSource extends DelegatingDataSource { @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } } | UrlDecodingDataSource extends DelegatingDataSource { @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } UrlDecodingDataSource(String jdbcUrl); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName, Function<String, DataSource> connectionTestDataSourceFactory); } | UrlDecodingDataSource extends DelegatingDataSource { @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } UrlDecodingDataSource(String jdbcUrl); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName, Function<String, DataSource> connectionTestDataSourceFactory); @Override Connection getConnection(); } | UrlDecodingDataSource extends DelegatingDataSource { @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } UrlDecodingDataSource(String jdbcUrl); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName, Function<String, DataSource> connectionTestDataSourceFactory); @Override Connection getConnection(); } |
@Test public void unsuccessfulUrlDecodedConnectionTestIsTriedAgain() throws SQLException { MockDataSource delegateDataSource = pooledDataSourceRequiringDecodedUrl(); DataSource decodedUrlConnectionTestDataSource = mock(DataSource.class); when(decodedUrlConnectionTestDataSource.getConnection()).thenThrow(new SQLException("unable to connect")); UrlDecodingDataSource urlDecodingDataSource = new UrlDecodingDataSource(delegateDataSource, URL_PROPERTY_NAME, url -> decodedUrlConnectionTestDataSource); try { urlDecodingDataSource.getConnection(); } catch (SQLException e) {} try { urlDecodingDataSource.getConnection(); } catch (SQLException e) {} verify(decodedUrlConnectionTestDataSource, times(2)).getConnection(); } | @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } | UrlDecodingDataSource extends DelegatingDataSource { @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } } | UrlDecodingDataSource extends DelegatingDataSource { @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } UrlDecodingDataSource(String jdbcUrl); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName, Function<String, DataSource> connectionTestDataSourceFactory); } | UrlDecodingDataSource extends DelegatingDataSource { @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } UrlDecodingDataSource(String jdbcUrl); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName, Function<String, DataSource> connectionTestDataSourceFactory); @Override Connection getConnection(); } | UrlDecodingDataSource extends DelegatingDataSource { @Override public Connection getConnection() throws SQLException { if (successfullyConnected) return super.getConnection(); synchronized (this) { Connection connection; try { connection = super.getConnection(); successfullyConnected = true; } catch (SQLException e) { logger.info("Database connection failed. Trying again with url-decoded jdbc url"); DataSource targetDataSource = getTargetDataSource(); if (targetDataSource == null) throw new IllegalStateException("target DataSource should never be null"); BeanWrapper dataSourceWrapper = new BeanWrapperImpl(targetDataSource); String decodedJdbcUrl = decode((String) dataSourceWrapper.getPropertyValue(urlPropertyName)); DataSource urlDecodedConnectionTestDataSource = connectionTestDataSourceFactory.apply(decodedJdbcUrl); urlDecodedConnectionTestDataSource.getConnection(); logger.info("Connection test successful. Continuing with url-decoded jdbc url"); dataSourceWrapper.setPropertyValue(urlPropertyName, decodedJdbcUrl); connection = super.getConnection(); successfullyConnected = true; } return connection; } } UrlDecodingDataSource(String jdbcUrl); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName); UrlDecodingDataSource(DataSource targetDataSource, String urlPropertyName, Function<String, DataSource> connectionTestDataSourceFactory); @Override Connection getConnection(); } |
@Test public void tagsMatch() { DummyServiceInfoCreator serviceInfoCreator = new DummyServiceInfoCreator(new Tags("firstTag", "secondTag")); assertAcceptedWithTags(serviceInfoCreator, "firstTag", "noMatchTag"); assertAcceptedWithTags(serviceInfoCreator, "noMatchTag", "secondTag"); assertAcceptedWithTags(serviceInfoCreator, "firstTag", "secondTag"); assertNotAcceptedWithTags(serviceInfoCreator, "noMatchTag"); assertNotAcceptedWithTags(serviceInfoCreator); } | @SuppressWarnings("unchecked") protected boolean tagsMatch(Map<String, Object> serviceData) { List<String> serviceTags = (List<String>) serviceData.get("tags"); return tags.containsOne(serviceTags); } | CloudFoundryServiceInfoCreator implements ServiceInfoCreator<SI, Map<String, Object>> { @SuppressWarnings("unchecked") protected boolean tagsMatch(Map<String, Object> serviceData) { List<String> serviceTags = (List<String>) serviceData.get("tags"); return tags.containsOne(serviceTags); } } | CloudFoundryServiceInfoCreator implements ServiceInfoCreator<SI, Map<String, Object>> { @SuppressWarnings("unchecked") protected boolean tagsMatch(Map<String, Object> serviceData) { List<String> serviceTags = (List<String>) serviceData.get("tags"); return tags.containsOne(serviceTags); } CloudFoundryServiceInfoCreator(Tags tags, String... uriSchemes); } | CloudFoundryServiceInfoCreator implements ServiceInfoCreator<SI, Map<String, Object>> { @SuppressWarnings("unchecked") protected boolean tagsMatch(Map<String, Object> serviceData) { List<String> serviceTags = (List<String>) serviceData.get("tags"); return tags.containsOne(serviceTags); } CloudFoundryServiceInfoCreator(Tags tags, String... uriSchemes); boolean accept(Map<String, Object> serviceData); String[] getUriSchemes(); String getDefaultUriScheme(); } | CloudFoundryServiceInfoCreator implements ServiceInfoCreator<SI, Map<String, Object>> { @SuppressWarnings("unchecked") protected boolean tagsMatch(Map<String, Object> serviceData) { List<String> serviceTags = (List<String>) serviceData.get("tags"); return tags.containsOne(serviceTags); } CloudFoundryServiceInfoCreator(Tags tags, String... uriSchemes); boolean accept(Map<String, Object> serviceData); String[] getUriSchemes(); String getDefaultUriScheme(); } |
@Test public void uriKeyMatchesScheme() { DummyServiceInfoCreator serviceInfoCreator = new DummyServiceInfoCreator(new Tags(), "amqp", "amqps"); assertAcceptedWithCredentials(serviceInfoCreator, "amqpUri", "https: assertAcceptedWithCredentials(serviceInfoCreator, "amqpsUri", "https: assertAcceptedWithCredentials(serviceInfoCreator, "amqpUrl", "https: assertAcceptedWithCredentials(serviceInfoCreator, "amqpsUrl", "https: assertAcceptedWithCredentials(serviceInfoCreator, "amqpuri", "https: assertAcceptedWithCredentials(serviceInfoCreator, "amqpsuri", "https: assertAcceptedWithCredentials(serviceInfoCreator, "amqpurl", "https: assertAcceptedWithCredentials(serviceInfoCreator, "amqpsurl", "https: } | protected boolean uriKeyMatchesScheme(Map<String, Object> serviceData) { if (uriSchemes == null) { return false; } Map<String, Object> credentials = getCredentials(serviceData); if (credentials != null) { for (String uriScheme : uriSchemes) { if (credentials.containsKey(uriScheme + "Uri") || credentials.containsKey(uriScheme + "uri") || credentials.containsKey(uriScheme + "Url") || credentials.containsKey(uriScheme + "url")) { return true; } } } return false; } | CloudFoundryServiceInfoCreator implements ServiceInfoCreator<SI, Map<String, Object>> { protected boolean uriKeyMatchesScheme(Map<String, Object> serviceData) { if (uriSchemes == null) { return false; } Map<String, Object> credentials = getCredentials(serviceData); if (credentials != null) { for (String uriScheme : uriSchemes) { if (credentials.containsKey(uriScheme + "Uri") || credentials.containsKey(uriScheme + "uri") || credentials.containsKey(uriScheme + "Url") || credentials.containsKey(uriScheme + "url")) { return true; } } } return false; } } | CloudFoundryServiceInfoCreator implements ServiceInfoCreator<SI, Map<String, Object>> { protected boolean uriKeyMatchesScheme(Map<String, Object> serviceData) { if (uriSchemes == null) { return false; } Map<String, Object> credentials = getCredentials(serviceData); if (credentials != null) { for (String uriScheme : uriSchemes) { if (credentials.containsKey(uriScheme + "Uri") || credentials.containsKey(uriScheme + "uri") || credentials.containsKey(uriScheme + "Url") || credentials.containsKey(uriScheme + "url")) { return true; } } } return false; } CloudFoundryServiceInfoCreator(Tags tags, String... uriSchemes); } | CloudFoundryServiceInfoCreator implements ServiceInfoCreator<SI, Map<String, Object>> { protected boolean uriKeyMatchesScheme(Map<String, Object> serviceData) { if (uriSchemes == null) { return false; } Map<String, Object> credentials = getCredentials(serviceData); if (credentials != null) { for (String uriScheme : uriSchemes) { if (credentials.containsKey(uriScheme + "Uri") || credentials.containsKey(uriScheme + "uri") || credentials.containsKey(uriScheme + "Url") || credentials.containsKey(uriScheme + "url")) { return true; } } } return false; } CloudFoundryServiceInfoCreator(Tags tags, String... uriSchemes); boolean accept(Map<String, Object> serviceData); String[] getUriSchemes(); String getDefaultUriScheme(); } | CloudFoundryServiceInfoCreator implements ServiceInfoCreator<SI, Map<String, Object>> { protected boolean uriKeyMatchesScheme(Map<String, Object> serviceData) { if (uriSchemes == null) { return false; } Map<String, Object> credentials = getCredentials(serviceData); if (credentials != null) { for (String uriScheme : uriSchemes) { if (credentials.containsKey(uriScheme + "Uri") || credentials.containsKey(uriScheme + "uri") || credentials.containsKey(uriScheme + "Url") || credentials.containsKey(uriScheme + "url")) { return true; } } } return false; } CloudFoundryServiceInfoCreator(Tags tags, String... uriSchemes); boolean accept(Map<String, Object> serviceData); String[] getUriSchemes(); String getDefaultUriScheme(); } |
@Test public void containsOne() { Tags tags = new Tags("test1", "test2"); assertTrue(tags.containsOne(Arrays.asList("test1", "testx"))); assertTrue(tags.containsOne(Arrays.asList("testx", "test2"))); assertTrue(tags.containsOne(Arrays.asList("TESTX", "TEST2"))); assertFalse(tags.containsOne(Arrays.asList("testx", "testy"))); } | public boolean containsOne(List<String> tags) { if (tags != null) { for (String value : values) { for (String tag : tags) { if (tag.equalsIgnoreCase(value)) { return true; } } } } return false; } | Tags { public boolean containsOne(List<String> tags) { if (tags != null) { for (String value : values) { for (String tag : tags) { if (tag.equalsIgnoreCase(value)) { return true; } } } } return false; } } | Tags { public boolean containsOne(List<String> tags) { if (tags != null) { for (String value : values) { for (String tag : tags) { if (tag.equalsIgnoreCase(value)) { return true; } } } } return false; } Tags(String... values); } | Tags { public boolean containsOne(List<String> tags) { if (tags != null) { for (String value : values) { for (String tag : tags) { if (tag.equalsIgnoreCase(value)) { return true; } } } } return false; } Tags(String... values); String[] getTags(); boolean containsOne(List<String> tags); boolean contains(String tag); boolean startsWith(String tag); } | Tags { public boolean containsOne(List<String> tags) { if (tags != null) { for (String value : values) { for (String tag : tags) { if (tag.equalsIgnoreCase(value)) { return true; } } } } return false; } Tags(String... values); String[] getTags(); boolean containsOne(List<String> tags); boolean contains(String tag); boolean startsWith(String tag); } |
@Test public void containsOneWithEmptyTags() { assertFalse(EMPTY_TAGS.containsOne(Arrays.asList("test"))); } | public boolean containsOne(List<String> tags) { if (tags != null) { for (String value : values) { for (String tag : tags) { if (tag.equalsIgnoreCase(value)) { return true; } } } } return false; } | Tags { public boolean containsOne(List<String> tags) { if (tags != null) { for (String value : values) { for (String tag : tags) { if (tag.equalsIgnoreCase(value)) { return true; } } } } return false; } } | Tags { public boolean containsOne(List<String> tags) { if (tags != null) { for (String value : values) { for (String tag : tags) { if (tag.equalsIgnoreCase(value)) { return true; } } } } return false; } Tags(String... values); } | Tags { public boolean containsOne(List<String> tags) { if (tags != null) { for (String value : values) { for (String tag : tags) { if (tag.equalsIgnoreCase(value)) { return true; } } } } return false; } Tags(String... values); String[] getTags(); boolean containsOne(List<String> tags); boolean contains(String tag); boolean startsWith(String tag); } | Tags { public boolean containsOne(List<String> tags) { if (tags != null) { for (String value : values) { for (String tag : tags) { if (tag.equalsIgnoreCase(value)) { return true; } } } } return false; } Tags(String... values); String[] getTags(); boolean containsOne(List<String> tags); boolean contains(String tag); boolean startsWith(String tag); } |
@Test public void contains() { Tags tags = new Tags("test1", "test2"); assertTrue(tags.contains("test1")); assertTrue(tags.contains("test2")); assertTrue(tags.contains("TEST2")); assertFalse(tags.contains("testx")); } | public boolean contains(String tag) { if (tag != null) { for (String value : values) { if (tag.equalsIgnoreCase(value)) { return true; } } } return false; } | Tags { public boolean contains(String tag) { if (tag != null) { for (String value : values) { if (tag.equalsIgnoreCase(value)) { return true; } } } return false; } } | Tags { public boolean contains(String tag) { if (tag != null) { for (String value : values) { if (tag.equalsIgnoreCase(value)) { return true; } } } return false; } Tags(String... values); } | Tags { public boolean contains(String tag) { if (tag != null) { for (String value : values) { if (tag.equalsIgnoreCase(value)) { return true; } } } return false; } Tags(String... values); String[] getTags(); boolean containsOne(List<String> tags); boolean contains(String tag); boolean startsWith(String tag); } | Tags { public boolean contains(String tag) { if (tag != null) { for (String value : values) { if (tag.equalsIgnoreCase(value)) { return true; } } } return false; } Tags(String... values); String[] getTags(); boolean containsOne(List<String> tags); boolean contains(String tag); boolean startsWith(String tag); } |
@Test public void containsWithEmptyTags() { assertFalse(EMPTY_TAGS.contains("test")); } | public boolean contains(String tag) { if (tag != null) { for (String value : values) { if (tag.equalsIgnoreCase(value)) { return true; } } } return false; } | Tags { public boolean contains(String tag) { if (tag != null) { for (String value : values) { if (tag.equalsIgnoreCase(value)) { return true; } } } return false; } } | Tags { public boolean contains(String tag) { if (tag != null) { for (String value : values) { if (tag.equalsIgnoreCase(value)) { return true; } } } return false; } Tags(String... values); } | Tags { public boolean contains(String tag) { if (tag != null) { for (String value : values) { if (tag.equalsIgnoreCase(value)) { return true; } } } return false; } Tags(String... values); String[] getTags(); boolean containsOne(List<String> tags); boolean contains(String tag); boolean startsWith(String tag); } | Tags { public boolean contains(String tag) { if (tag != null) { for (String value : values) { if (tag.equalsIgnoreCase(value)) { return true; } } } return false; } Tags(String... values); String[] getTags(); boolean containsOne(List<String> tags); boolean contains(String tag); boolean startsWith(String tag); } |
@Test public void jdbcFullUrl() { RelationalServiceInfo serviceInfo = createServiceInfo("dbtype: assertEquals("jdbc:jdbcdbtype: } | @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } | RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } } | RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType); RelationalServiceInfo(String id, String uriString, String jdbcUrl, String jdbcUrlDatabaseType); } | RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType); RelationalServiceInfo(String id, String uriString, String jdbcUrl, String jdbcUrlDatabaseType); @ServiceProperty(category = "connection") String getJdbcUrl(); } | RelationalServiceInfo extends UriBasedServiceInfo { @ServiceProperty(category = "connection") public String getJdbcUrl() { return jdbcUrl == null ? buildJdbcUrl() : jdbcUrl; } RelationalServiceInfo(String id, String uriString, String jdbcUrlDatabaseType); RelationalServiceInfo(String id, String uriString, String jdbcUrl, String jdbcUrlDatabaseType); @ServiceProperty(category = "connection") String getJdbcUrl(); static final String JDBC_PREFIX; } |
@Test public void startsWith() { Tags tags = new Tags("test"); assertTrue(tags.startsWith("test-123")); assertTrue(tags.startsWith("TEST-123")); assertFalse(tags.startsWith("abcd")); } | public boolean startsWith(String tag) { if (tag != null) { for (String value : values) { if (startsWithIgnoreCase(tag, value)) { return true; } } } return false; } | Tags { public boolean startsWith(String tag) { if (tag != null) { for (String value : values) { if (startsWithIgnoreCase(tag, value)) { return true; } } } return false; } } | Tags { public boolean startsWith(String tag) { if (tag != null) { for (String value : values) { if (startsWithIgnoreCase(tag, value)) { return true; } } } return false; } Tags(String... values); } | Tags { public boolean startsWith(String tag) { if (tag != null) { for (String value : values) { if (startsWithIgnoreCase(tag, value)) { return true; } } } return false; } Tags(String... values); String[] getTags(); boolean containsOne(List<String> tags); boolean contains(String tag); boolean startsWith(String tag); } | Tags { public boolean startsWith(String tag) { if (tag != null) { for (String value : values) { if (startsWithIgnoreCase(tag, value)) { return true; } } } return false; } Tags(String... values); String[] getTags(); boolean containsOne(List<String> tags); boolean contains(String tag); boolean startsWith(String tag); } |
Subsets and Splits