From 57fb9cdc86671237a95eb989c0bc228923864983 Mon Sep 17 00:00:00 2001 From: Paul Ebermann Date: Wed, 19 Dec 2018 13:04:42 +0100 Subject: [PATCH 1/2] add asserts to ApplicationIT --- .../nakadiproducer/tests/ApplicationIT.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/nakadi-producer-starter-spring-boot-2-test/src/test/java/org/zalando/nakadiproducer/tests/ApplicationIT.java b/nakadi-producer-starter-spring-boot-2-test/src/test/java/org/zalando/nakadiproducer/tests/ApplicationIT.java index 60adf408..4afd2270 100644 --- a/nakadi-producer-starter-spring-boot-2-test/src/test/java/org/zalando/nakadiproducer/tests/ApplicationIT.java +++ b/nakadi-producer-starter-spring-boot-2-test/src/test/java/org/zalando/nakadiproducer/tests/ApplicationIT.java @@ -5,13 +5,18 @@ import org.junit.Test; import org.junit.contrib.java.lang.system.EnvironmentVariables; import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; +import org.zalando.nakadiproducer.transmission.MockNakadiPublishingClient; import java.io.File; +import java.util.List; import static io.restassured.RestAssured.given; +import static org.hamcrest.Matchers.hasSize; +import static org.junit.Assert.assertThat; @RunWith(SpringRunner.class) @SpringBootTest( @@ -25,6 +30,9 @@ public class ApplicationIT { @LocalManagementPort private int localManagementPort; + @Autowired + private MockNakadiPublishingClient mockClient; + @ClassRule public static final EnvironmentVariables environmentVariables = new EnvironmentVariables(); @@ -35,10 +43,16 @@ public static void fakeCredentialsDir() { } @Test - public void shouldSuccessfullyStartAndSnapshotCanBeTriggered() { + public void shouldSuccessfullyStartAndSnapshotCanBeTriggered() throws InterruptedException { given().baseUri("http://localhost:" + localManagementPort).contentType("application/json") .when().post("/actuator/snapshot-event-creation/eventtype") .then().statusCode(204); + + // leave some time for the scheduler to run + Thread.sleep(1200); + + List events = mockClient.getSentEvents("eventtype"); + assertThat(events, hasSize(2)); } From 2f331d626f7f6a29c0646693c6108d0a4dee407a Mon Sep 17 00:00:00 2001 From: Paul Ebermann Date: Wed, 19 Dec 2018 17:43:37 +0100 Subject: [PATCH 2/2] cleanup before and after the test --- .../nakadiproducer/tests/ApplicationIT.java | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/nakadi-producer-starter-spring-boot-2-test/src/test/java/org/zalando/nakadiproducer/tests/ApplicationIT.java b/nakadi-producer-starter-spring-boot-2-test/src/test/java/org/zalando/nakadiproducer/tests/ApplicationIT.java index 4afd2270..2b29af03 100644 --- a/nakadi-producer-starter-spring-boot-2-test/src/test/java/org/zalando/nakadiproducer/tests/ApplicationIT.java +++ b/nakadi-producer-starter-spring-boot-2-test/src/test/java/org/zalando/nakadiproducer/tests/ApplicationIT.java @@ -1,8 +1,6 @@ package org.zalando.nakadiproducer.tests; -import org.junit.BeforeClass; -import org.junit.ClassRule; -import org.junit.Test; +import org.junit.*; import org.junit.contrib.java.lang.system.EnvironmentVariables; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -10,6 +8,7 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import org.zalando.nakadiproducer.transmission.MockNakadiPublishingClient; +import org.zalando.nakadiproducer.transmission.impl.EventTransmitter; import java.io.File; import java.util.List; @@ -24,15 +23,13 @@ // by our starter *even if* it has been defined *after* the application itself. This has been a problem until // this commit. classes = { Application.class, MockNakadiConfig.class }, + properties = { "nakadi-producer.transmission-polling-delay=30"}, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT ) public class ApplicationIT { @LocalManagementPort private int localManagementPort; - @Autowired - private MockNakadiPublishingClient mockClient; - @ClassRule public static final EnvironmentVariables environmentVariables = new EnvironmentVariables(); @@ -42,6 +39,19 @@ public static void fakeCredentialsDir() { environmentVariables.set("CREDENTIALS_DIR", new File("src/main/test/tokens").getAbsolutePath()); } + @Autowired + private MockNakadiPublishingClient mockClient; + + @Autowired + private EventTransmitter eventTransmitter; + + @Before + @After + public void cleanUpMock() { + eventTransmitter.sendEvents(); + mockClient.clearSentEvents(); + } + @Test public void shouldSuccessfullyStartAndSnapshotCanBeTriggered() throws InterruptedException { given().baseUri("http://localhost:" + localManagementPort).contentType("application/json") @@ -49,7 +59,7 @@ public void shouldSuccessfullyStartAndSnapshotCanBeTriggered() throws Interrupte .then().statusCode(204); // leave some time for the scheduler to run - Thread.sleep(1200); + Thread.sleep(200); List events = mockClient.getSentEvents("eventtype"); assertThat(events, hasSize(2));