Java Examples for reactor.test.StepVerifier

The following java examples will help you to understand the usage of reactor.test.StepVerifier. These source code samples are taken from different open source projects.

Example 1
Project: reactor-master  File: DefaultApplicationsTest.java View source code
@Test
public void copySourceNoRestartOrgSpace() {
    requestApplications(this.cloudFoundryClient, "test-application-name", TEST_SPACE_ID, "test-metadata-id");
    requestSpace(this.cloudFoundryClient, TEST_SPACE_ID, TEST_ORGANIZATION_ID);
    requestOrganizations(this.cloudFoundryClient, "test-target-organization");
    requestOrganizationSpacesByName(this.cloudFoundryClient, "test-organization-resource-metadata-id", "test-target-space");
    requestApplications(this.cloudFoundryClient, "test-target-application-name", "test-space-resource-metadata-id", "test-metadata-id");
    requestCopyBits(this.cloudFoundryClient, "test-metadata-id", "test-metadata-id");
    requestJobSuccess(this.cloudFoundryClient, "test-copy-bits-id");
    this.applications.copySource(CopySourceApplicationRequest.builder().name("test-application-name").targetName("test-target-application-name").targetSpace("test-target-space").targetOrganization("test-target-organization").build()).as(StepVerifier::create).expectComplete().verify(Duration.ofSeconds(5));
}
Example 2
Project: reactor-core-master  File: FluxTests.java View source code
@Test
public void testDoOnEachSignal() {
    List<Signal<Integer>> signals = new ArrayList<>(4);
    List<Integer> values = new ArrayList<>(2);
    Flux<Integer> flux = Flux.just(1, 2).doOnEach(signals::add).doOnEach( s -> {
        if (s.isOnNext())
            values.add(s.get());
    });
    StepVerifier.create(flux).expectSubscription().expectNext(1, 2).expectComplete().verify();
    assertThat(signals.size(), is(3));
    assertThat("onNext signal are not reused", signals.get(0).get(), is(2));
    assertThat("onNext signal isn't last value", signals.get(1).get(), is(2));
    assertTrue("onComplete expected", signals.get(2).isOnComplete());
    assertThat("1st onNext value unexpected", values.get(0), is(1));
    assertThat("2nd onNext value unexpected", values.get(1), is(2));
}
Example 3
Project: java-buildpack-system-test-master  File: RedisAutoReconfigurationTest.java View source code
@Override
protected void test(Application application) {
    Mono.when(application.request("/redis/check-access"), this.service.getEndpoint(application), application.request("/redis/url")).as(StepVerifier::create).assertNext(consumer(( access,  expectedUrl,  actualUrl) -> {
        assertThat(access).isEqualTo("ok");
        assertThat(actualUrl).isEqualTo(expectedUrl);
    })).expectComplete().verify(Duration.ofMinutes(5));
}
Example 4
Project: spring-framework-master  File: ResourceWebHandlerTests.java View source code
@Test
public void getResourceHttpHeader() throws Exception {
    MockServerWebExchange exchange = MockServerHttpRequest.head("").toExchange();
    setPathWithinHandlerMapping(exchange, "foo.css");
    this.handler.handle(exchange).block(TIMEOUT);
    assertNull(exchange.getResponse().getStatusCode());
    HttpHeaders headers = exchange.getResponse().getHeaders();
    assertEquals(MediaType.parseMediaType("text/css"), headers.getContentType());
    assertEquals(17, headers.getContentLength());
    assertEquals("max-age=3600", headers.getCacheControl());
    assertTrue(headers.containsKey("Last-Modified"));
    assertEquals(headers.getLastModified() / 1000, resourceLastModifiedDate("test/foo.css") / 1000);
    assertEquals("bytes", headers.getFirst("Accept-Ranges"));
    assertEquals(1, headers.get("Accept-Ranges").size());
    StepVerifier.create(exchange.getResponse().getBody()).expectErrorMatches( ex -> ex.getMessage().startsWith("The body is not set.")).verify();
}
Example 5
Project: spring-security-master  File: ReactiveAuthenticationManagerAdapterTests.java View source code
@Test
public void authenticateWhenBadCredentialsThenError() {
    when(delegate.authenticate(any())).thenThrow(new BadCredentialsException("Failed"));
    when(authentication.isAuthenticated()).thenReturn(true);
    Mono<Authentication> result = manager.authenticate(authentication);
    StepVerifier.create(result).expectError(BadCredentialsException.class).verify();
}
Example 6
Project: spring-data-redis-master  File: DefaultReactiveZSetOperationsIntegrationTests.java View source code
// DATAREDIS-602
@Test
public void addAll() {
    K key = keyFactory.instance();
    V value1 = valueFactory.instance();
    V value2 = valueFactory.instance();
    List<DefaultTypedTuple<V>> tuples = Arrays.asList(new DefaultTypedTuple<>(value1, 42.1d), new DefaultTypedTuple<>(value2, 10d));
    StepVerifier.create(zSetOperations.addAll(key, tuples)).expectNext(2L).verifyComplete();
    List<DefaultTypedTuple<V>> updated = Arrays.asList(new DefaultTypedTuple<>(value1, 52.1d), new DefaultTypedTuple<>(value2, 10d));
    StepVerifier.create(zSetOperations.addAll(key, updated)).expectNext(0L).verifyComplete();
    StepVerifier.create(zSetOperations.score(key, value1)).expectNext(52.1d).verifyComplete();
}
Example 7
Project: spring-boot-master  File: AbstractReactiveWebServerFactoryTests.java View source code
@Test
public void startStopServer() {
    this.webServer = getFactory().getWebServer(new EchoHandler());
    this.webServer.start();
    assertThat(this.output.toString()).contains("started on port");
    Mono<String> result = getWebClient().post().uri("/test").contentType(MediaType.TEXT_PLAIN).body(BodyInserters.fromObject("Hello World")).exchange().flatMap( response -> response.bodyToMono(String.class));
    assertThat(result.block()).isEqualTo("Hello World");
    this.webServer.stop();
    Mono<ClientResponse> response = getWebClient().post().uri("/test").contentType(MediaType.TEXT_PLAIN).body(BodyInserters.fromObject("Hello World")).exchange();
    StepVerifier.create(response).expectError().verify();
}
Example 8
Project: spring-data-cassandra-master  File: ReactiveCqlTemplateUnitTests.java View source code
// DATACASS-335
@Test
public void executeCqlShouldExecuteDeferred() {
    when(session.execute(any(Statement.class))).thenReturn(Mono.just(reactiveResultSet));
    Mono<Boolean> mono = template.execute("UPDATE user SET a = 'b';");
    verifyZeroInteractions(session);
    StepVerifier.create(mono).expectNext(false).verifyComplete();
    verify(session).execute(any(Statement.class));
}
Example 9
Project: spring-data-mongodb-master  File: ReactiveMongoTemplateTests.java View source code
@Before
public void setUp() {
    StepVerifier.create(//
    template.dropCollection(//
    "people").mergeWith(//
    template.dropCollection(//
    "collection")).mergeWith(//
    template.dropCollection(//
    Person.class)).mergeWith(//
    template.dropCollection(//
    Venue.class)).mergeWith(template.dropCollection(PersonWithAList.class)).mergeWith(template.dropCollection(PersonWithIdPropertyOfTypeObjectId.class)).mergeWith(template.dropCollection(PersonWithVersionPropertyOfTypeInteger.class)).mergeWith(//
    template.dropCollection(//
    Sample.class))).verifyComplete();
}
Example 10
Project: spring-integration-master  File: ReactiveHttpRequestExecutingMessageHandlerTests.java View source code
@Test
public void testReactiveReturn() throws Throwable {
    ClientHttpConnector httpConnector = new HttpHandlerConnector(( request,  response) -> {
        response.setStatusCode(HttpStatus.OK);
        return Mono.empty().then(Mono.defer(response::setComplete));
    });
    WebClient webClient = WebClient.builder().clientConnector(httpConnector).build();
    String destinationUri = "http://www.springsource.org/spring-integration";
    ReactiveHttpRequestExecutingMessageHandler reactiveHandler = new ReactiveHttpRequestExecutingMessageHandler(destinationUri, webClient);
    FluxMessageChannel ackChannel = new FluxMessageChannel();
    reactiveHandler.setOutputChannel(ackChannel);
    reactiveHandler.handleMessage(MessageBuilder.withPayload("hello, world").build());
    reactiveHandler.handleMessage(MessageBuilder.withPayload("hello, world").build());
    StepVerifier.create(ackChannel, 2).assertNext( m -> assertThat(m, hasHeader(HttpHeaders.STATUS_CODE, HttpStatus.OK))).assertNext( m -> assertThat(m, hasHeader(HttpHeaders.STATUS_CODE, HttpStatus.OK))).then(() -> ((Subscriber<?>) TestUtils.getPropertyValue(ackChannel, "subscribers", List.class).get(0)).onComplete()).verifyComplete();
}