package com.atlassian.bitbucket.scm.git.protocol;

import org.junit.Test;

import java.nio.charset.StandardCharsets;

import static com.atlassian.bitbucket.scm.git.protocol.GitScmRequestType.*;
import static com.atlassian.bitbucket.scm.git.protocol.GitTestData.*;
import static org.junit.Assert.assertEquals;

/**
 * Tests {@link UploadPackRequestAnalyzer}}
 */
public class UploadPackRequestAnalyzerTest {

    @Test
    public void testNotInitialized() {
        assertEquals(UNKNOWN, new UploadPackRequestAnalyzer().getType());
    }

    @Test
    public void testClone() {
        assertEquals(CLONE, analyse(CLONE_INPUT));
    }

    @Test
    public void testFetch() {
        assertEquals(FETCH, analyse(FETCH_INPUT));
    }

    @Test
    public void testRefs() {
        assertEquals(REFS, analyse(REFS_INPUT));
    }

    @Test
    public void testShallowClone() {
        assertEquals(SHALLOW_CLONE, analyse(SHALLOW_CLONE_INPUT));
    }

    @Test
    public void testShallowFetch() {
        assertEquals(SHALLOW_FETCH, analyse(SHALLOW_FETCH_INPUT));
    }

    @Test
    public void testShallowNegotiation() {
        assertEquals(NEGOTIATION, analyse(SHALLOW_CLONE_NEGOTIATION_INPUT));
    }

    private GitScmRequestType analyse(String content) {
        UploadPackRequestAnalyzer analyzer = new UploadPackRequestAnalyzer();
        analyzer.process(content.getBytes(StandardCharsets.UTF_8));
        return analyzer.getType();
    }
}
