package com.atlassian.stash.internal.scm.git.protocol.http;

import com.atlassian.event.api.EventPublisher;
import com.atlassian.bitbucket.event.repository.RepositoryEvent;
import com.atlassian.bitbucket.event.repository.RepositoryOtherWriteEvent;
import com.atlassian.bitbucket.i18n.I18nService;
import com.atlassian.bitbucket.repository.Repository;
import com.atlassian.bitbucket.scm.git.command.GitCommandBuilderFactory;
import com.atlassian.bitbucket.scm.git.GitScmConfig;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import static com.atlassian.stash.internal.scm.git.protocol.http.GitSmartRequestTestBase.onSuccessCaptureEvent;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.*;

@RunWith(MockitoJUnitRunner.class)
public class HttpOtherWriteTest {

    @Mock
    private GitCommandBuilderFactory builderFactory;
    @Mock
    private GitScmConfig config;
    @Mock
    private EventPublisher eventPublisher;
    @Mock
    private I18nService i18nService;
    @InjectMocks
    private HttpOtherWrite httpOtherWrite;
    @Mock
    private Repository repository;
    @Mock
    private HttpServletRequest request;
    @Mock
    private HttpServletResponse response;
    @Mock
    private ServletContext servletContext;

    @Test
    public void testOnSuccessPublishesEvent() throws Exception {
        RepositoryEvent event = onSuccessCaptureEvent(eventPublisher, httpOtherWrite);
        assertNotNull(event);
        assertThat(event, instanceOf(RepositoryOtherWriteEvent.class));
        assertSame(repository, event.getRepository());
        assertSame(httpOtherWrite, event.getSource());
    }

    @Test
    public void testIsOperationComplete() throws Exception {
        assertTrue(httpOtherWrite.isOperationComplete());
    }
}
