Last active
April 7, 2019 08:50
-
-
Save shivangi1015/229b270d4794b1238e73791e67a26c41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import akka.stream.javadsl.Source; | |
import akka.stream.testkit.TestSubscriber; | |
import akka.stream.testkit.javadsl.TestSink; | |
import com.lightbend.lagom.javadsl.persistence.PersistentEntityRegistry; | |
import com.lightbend.lagom.javadsl.testkit.ServiceTest; | |
import org.junit.BeforeClass; | |
import org.junit.Test; | |
import org.knoldus.hello.api.GreetingMessage; | |
import org.knoldus.hello.api.HelloEvent; | |
import org.knoldus.hello.api.HelloService; | |
import scala.concurrent.duration.FiniteDuration; | |
import java.util.concurrent.TimeUnit; | |
import static com.lightbend.lagom.javadsl.testkit.ServiceTest.defaultSetup; | |
import static com.lightbend.lagom.javadsl.testkit.ServiceTest.startServer; | |
import static org.junit.Assert.assertEquals; | |
public class ProducerTest { | |
private static ServiceTest.TestServer testServer; | |
private static HelloService service; | |
private static PersistentEntityRegistry persistentEntityRegistry; | |
@BeforeClass | |
public static void setUp() { | |
testServer = startServer(defaultSetup().withCassandra(true)); | |
service = testServer.client(HelloService.class); | |
persistentEntityRegistry = testServer.injector().instanceOf(PersistentEntityRegistry.class); | |
} | |
@Test | |
public void shouldEmitGreetingsMessageWhenHelloEntityEmitsEnEvent() { | |
service.useGreeting("user_id").invoke(new GreetingMessage("hi")).toCompletableFuture().join(); | |
Source<HelloEvent, ?> source = service.helloEvents().subscribe().atMostOnceSource(); | |
TestSubscriber.Probe<HelloEvent> probe = | |
source.runWith(TestSink.probe(testServer.system()), testServer.materializer()); | |
HelloEvent helloEvent = probe.request(1).expectNext(FiniteDuration.apply(25, TimeUnit.SECONDS)); | |
assertEquals("user_id", helloEvent.getName()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment