Skip to content

Commit

Permalink
reverting test changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aludwiko committed Jun 27, 2023
1 parent f909bdb commit 899c3be
Showing 1 changed file with 6 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
package com.example.fibonacci;

import com.example.Main;
import com.google.protobuf.any.Any;
import kalix.javasdk.DeferredCall;
import kalix.javasdk.client.ComponentClient;
import kalix.spring.testkit.KalixIntegrationTestKitSupport;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.TestPropertySource;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientResponseException;
import reactor.core.publisher.Mono;

import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import static java.time.temporal.ChronoUnit.SECONDS;

Expand All @@ -31,18 +22,16 @@ public class FibonacciActionIntegrationTest extends KalixIntegrationTestKitSuppo
@Autowired
private WebClient webClient;

@Autowired
private ComponentClient componentClient;
private Duration timeout = Duration.of(5, SECONDS);

@Test
public void calculateNextNumber() {

Number response = execute(componentClient.forAction()
.call(FibonacciAction::getNumber)
.params(5L));
Mono<Number> response =
webClient.get()
.uri("/fibonacci/5/next")
.retrieve().bodyToMono(Number.class);

Assertions.assertEquals(8, response.value());
long next = response.block(Duration.of(5, SECONDS)).value();
Assertions.assertEquals(8, next);

}

Expand Down Expand Up @@ -77,12 +66,4 @@ public void wrongNumberReturnsError() {
Assertions.assertTrue(bodyErrorMessage.contains("Input number is not a Fibonacci number"));
}
}

private <T> T execute(DeferredCall<Any, T> deferredCall) {
try {
return deferredCall.execute().toCompletableFuture().get(timeout.toMillis(), TimeUnit.MILLISECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw new RuntimeException(e);
}
}
}

0 comments on commit 899c3be

Please sign in to comment.