package it.com.atlassian.stash.rest.mirror;

import com.atlassian.bitbucket.test.rest.server.stub.mirror.StubMirror;
import it.com.atlassian.stash.rest.webhook.BaseWebHookCallbackTest;
import org.hamcrest.Matcher;
import org.junit.BeforeClass;

import java.io.IOException;
import java.util.function.Supplier;

import static it.com.atlassian.stash.rest.webhook.WebHookCallbackHelper.assertWebHookCallbackArrivedOn;

/**
 * Tests that callbacks occur against a mirror registered to receive web hook events.
 */
public class MirroringWebHookCallbackTest extends BaseWebHookCallbackTest {

    private static StubMirror stubMirror;

    @BeforeClass
    public static void installMirror() throws IOException {
        stubMirror = new StubMirror(MirroringWebHookCallbackTest.class.getSimpleName());
        stubMirror.configureDefaultResponders();

        getClassTestContext().install(stubMirror);
    }

    @Override
    protected void assertWebHookCallbackArrived(String eventId, Supplier<Matcher<String>> matcherSupplier) {
        assertWebHookCallbackArrivedOn(stubMirror, eventId, matcherSupplier);
    }
}