Skip to content

Commit

Permalink
cleanup before and after the test
Browse files Browse the repository at this point in the history
  • Loading branch information
ePaul committed Dec 19, 2018
1 parent 57fb9cd commit 2f331d6
Showing 1 changed file with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
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;
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 org.zalando.nakadiproducer.transmission.impl.EventTransmitter;

import java.io.File;
import java.util.List;
Expand All @@ -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();
Expand All @@ -42,14 +39,27 @@ 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")
.when().post("/actuator/snapshot-event-creation/eventtype")
.then().statusCode(204);

// leave some time for the scheduler to run
Thread.sleep(1200);
Thread.sleep(200);

List<String> events = mockClient.getSentEvents("eventtype");
assertThat(events, hasSize(2));
Expand Down

0 comments on commit 2f331d6

Please sign in to comment.