package org.zalando.nakadiproducer.tests;

import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.contrib.java.lang.system.EnvironmentVariables;
import org.junit.runner.RunWith;
import org.springframework.boot.actuate.autoconfigure.web.server.LocalManagementPort;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.File;

import static io.restassured.RestAssured.given;

@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 },
        webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT
)
public class ApplicationIT {
    @LocalManagementPort
    private int localManagementPort;

    @ClassRule
    public static final EnvironmentVariables environmentVariables
            = new EnvironmentVariables();

    @BeforeClass
    public static void fakeCredentialsDir() {
        environmentVariables.set("CREDENTIALS_DIR", new File("src/main/test/tokens").getAbsolutePath());
    }

    @Test
    public void shouldSuccessfullyStartAndSnapshotCanBeTriggered() {
        given().baseUri("http://localhost:" + localManagementPort).contentType("application/json")
        .when().post("/actuator/snapshot-event-creation/eventtype")
        .then().statusCode(204);
    }


}

@@ -214,16 +214,79 @@
 unWith;%0A
+import org.springframework.beans.factory.annotation.Autowired;%0A
 import o
@@ -489,77 +489,263 @@
 er;%0A
-%0Aimport java.io.File;%0A%0Aimport static io.restassured.RestAssured.given
+import org.zalando.nakadiproducer.transmission.MockNakadiPublishingClient;%0A%0Aimport java.io.File;%0Aimport java.util.List;%0A%0Aimport static io.restassured.RestAssured.given;%0Aimport static org.hamcrest.Matchers.hasSize;%0Aimport static org.junit.Assert.assertThat
 ;%0A%0A@
@@ -1278,16 +1278,83 @@
 tPort;%0A%0A
+    @Autowired%0A    private MockNakadiPublishingClient mockClient;%0A%0A
     @Cla
@@ -1720,16 +1720,44 @@
 ggered()
+ throws InterruptedException
  %7B%0A     
@@ -1950,16 +1950,207 @@
 de(204);
+%0A%0A        // leave some time for the scheduler to run%0A        Thread.sleep(1200);%0A%0A        List%3CString%3E events = mockClient.getSentEvents(%22eventtype%22);%0A        assertThat(events, hasSize(2));
 %0A    %7D%0A%0A

add asserts to ApplicationIT