@Test public void writeInternalWhenOAuth2ErrorThenWriteErrorResponse() throws Exception { OAuth2Error oauth2Error = new OAuth2Error("unauthorized_client", "The client is not authorized", "https://tools.ietf.org/html/rfc6749#section-5.2"); MockHttpOutputMessage outputMessage = new MockHttpOutputMessage(); this.messageConverter.writeInternal(oauth2Error, outputMessage); String errorResponse = outputMessage.getBodyAsString(); assertThat(errorResponse).contains("\"error\":\"unauthorized_client\""); assertThat(errorResponse).contains("\"error_description\":\"The client is not authorized\""); assertThat(errorResponse).contains("\"error_uri\":\"https://tools.ietf.org/html/rfc6749#section-5.2\""); }
@Test public void returnsExceptionWithNoCauseForSqlException() { Exception sqlException = new SQLException("mySqlExceptionMessage"); Exception e = JdbcConnectorException.createException(sqlException); assertThat(e.getCause()).isNull(); assertThat(e.getMessage()).contains("mySqlExceptionMessage") .contains(this.getClass().getCanonicalName() + "." + testName.getMethodName()); }
@Test public void configureWhenAddFilterUnregisteredThenThrowsBeanCreationException() throws Exception { Throwable thrown = catchThrowable(() -> this.spring.register(UnregisteredFilterConfig.class).autowire() ); assertThat(thrown).isInstanceOf(BeanCreationException.class); assertThat(thrown.getMessage()).contains("The Filter class " + UnregisteredFilter.class.getName() + " does not have a registered order and cannot be added without a specified order." + " Consider using addFilterBefore or addFilterAfter instead."); }
@Test public void executeReturnsResultForExceptionWithoutMessage() { when(service.getMappingForRegion(any())).thenThrow(new NullPointerException()); function.execute(context); ArgumentCaptor<CliFunctionResult> argument = ArgumentCaptor.forClass(CliFunctionResult.class); verify(resultSender, times(1)).lastResult(argument.capture()); assertThat(argument.getValue().getStatusMessage()) .contains(NullPointerException.class.getName()); }
@Test public void executeReturnsResultForExceptionWithoutMessage() { when(service.getRegionMappings()).thenThrow(new NullPointerException()); function.execute(context); ArgumentCaptor<CliFunctionResult> argument = ArgumentCaptor.forClass(CliFunctionResult.class); verify(resultSender, times(1)).lastResult(argument.capture()); assertThat(argument.getValue().getStatusMessage()) .contains(NullPointerException.class.getName()); }
@Test public void executeReportsErrorIfMappingNotFound() { function.execute(context); ArgumentCaptor<CliFunctionResult> argument = ArgumentCaptor.forClass(CliFunctionResult.class); verify(resultSender, times(1)).lastResult(argument.capture()); assertThat(argument.getValue().getStatusMessage()) .contains("JDBC mapping for region \"" + regionName + "\" not found"); } }
@Test public void monoCheckpointEmpty() { StringWriter sw = new StringWriter(); Mono<Object> tested = Mono.just(1) .map(i -> null) .filter(Objects::nonNull) .checkpoint() .doOnError(t -> t.printStackTrace(new PrintWriter(sw))); StepVerifier.create(tested) .verifyError(); String debugStack = sw.toString(); assertThat(debugStack).contains("Assembly trace from producer [reactor.core.publisher.MonoFilterFuseable] :"); }
@Test public void listDataSourceWithNoClusterConfigurationServerFails() { doReturn(null).when(command).getConfigurationPersistenceService(); ResultModel result = command.listDataSources(); assertThat(result.getStatus()).isEqualTo(Status.ERROR); assertThat(result.toString()).contains("Cluster configuration service must be enabled."); }
@Test public void cookies() { WebTestClient webTestClient = WebTestClient .bindToController(new CookieController()) .build(); WebDriver driver = WebTestClientHtmlUnitDriverBuilder .webTestClientSetup(webTestClient).build(); driver.get("http://localhost/cookie"); assertThat(driver.getPageSource()).contains("theCookie"); driver.get("http://localhost/cookie/delete"); assertThat(driver.getPageSource()).contains("null"); }
@Test public void configureWhenProtectingLoginPageThenWarningLogged() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); redirectLogsTo(baos, DefaultFilterChainValidator.class); this.spring.configLocations(xml("ProtectedLoginPage")).autowire(); assertThat(baos.toString()).contains("[WARN]"); }
@Test public void toStringContainsJavaVersionWhenStarting() { TestLauncher.TestState status = launcher.status(); String result = status.toString(); assertThat(result).contains(TO_STRING_PROCESS_ID); }
@Test public void toStringContainsJvmArgumentsWhenStarting() { TestLauncher.TestState status = launcher.status(); String result = status.toString(); assertThat(result).contains(TO_STRING_JVM_ARGUMENTS); }
@Test public void createsMappingReturnsStatusERRORWhenClusterConfigIsDisabled() { results.add(successFunctionResult); doReturn(null).when(createRegionMappingCommand).getConfigurationPersistenceService(); ResultModel result = createRegionMappingCommand.createMapping(regionName, dataSourceName, tableName, pdxClass, false, null, null, null); assertThat(result.getStatus()).isSameAs(Result.Status.ERROR); assertThat(result.toString()).contains("Cluster Configuration must be enabled."); }
@Test public void helloWorld() { WebTestClient webTestClient = WebTestClient .bindToController(new HelloWorldController()) .build(); WebDriver driver = WebTestClientHtmlUnitDriverBuilder .webTestClientSetup(webTestClient).build(); driver.get("http://localhost/"); assertThat(driver.getPageSource()).contains("Hello World"); }