Skip to content

Commit

Permalink
Merge pull request #108 from zalando-nakadi/feature/add-asserts-to-test
Browse files Browse the repository at this point in the history
add asserts to ApplicationIT
  • Loading branch information
ePaul authored Dec 20, 2018
2 parents b598127 + 2f331d6 commit d9e5585
Showing 1 changed file with 28 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
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;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.assertThat;

@RunWith(SpringRunner.class)
@SpringBootTest(
// This line looks like that by intention: We want to test that the MockNakadiPublishingClient will be picked up
// 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 {
Expand All @@ -34,11 +39,30 @@ 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() {
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(200);

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


Expand Down

0 comments on commit d9e5585

Please sign in to comment.