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

import com.atlassian.bitbucket.permission.Permission;
import com.atlassian.bitbucket.test.RepositoryTestHelper;
import com.atlassian.bitbucket.test.rest.RestAuthentication;
import com.atlassian.bitbucket.test.rest.commit.RestCommitHelper;
import it.com.atlassian.stash.BaseRestTest;
import org.junit.BeforeClass;
import org.springframework.core.io.ClassPathResource;

public abstract class BaseCommitCommentTest extends BaseRestTest {

    protected static final String CS_FILE = "modification/mod_file.txt";
    protected static final String CS_COMMENT_TEST = "cscommenttest";
    protected static final String CS_COMMENT_TEST_MERGE = "cscommenttest_merge";
    protected static final String CS_ID = "bf3346620ec9161977fc23dee1240a7991e64ca1";
    protected static final String COMMENTATOR = CS_COMMENT_TEST + "_commentator";
    protected static final String MERGE_ID = "f0a3d73385c21bff36ed0128613eaa302f9db262";
    protected static final String MERGE_FIRST_PARENT = "c7c7497cb7ec1a5d645f891c066a8d876f42459b";
    protected static final String MERGE_SECOND_PARENT = "b4d378388c2dc3840ff5dcf64b4ac0f1ffc17cb9";
    protected static final String PARENT_ID = "e26cab95a50f6e99d2c46c498a23cee307cc8e27";

    protected static RestCommitHelper commit;

    @BeforeClass
    public static void setup() throws Exception {
        getClassTestContext().project(CS_COMMENT_TEST)
                .repository(CS_COMMENT_TEST, CS_COMMENT_TEST,
                        new ClassPathResource(RepositoryTestHelper.DEFAULT_REPOSITORY))
                .user(COMMENTATOR)
                .projectPermission(CS_COMMENT_TEST, COMMENTATOR, Permission.PROJECT_READ);
        //Enable public access for the repository so we can verify commit comments in anonymous contexts too
        RepositoryTestHelper.setRepositoryPublicAccessEnabled(CS_COMMENT_TEST, CS_COMMENT_TEST, true);

        getClassTestContext()
                .project(CS_COMMENT_TEST_MERGE)
                .repository(CS_COMMENT_TEST_MERGE, CS_COMMENT_TEST_MERGE,
                        new ClassPathResource(RepositoryTestHelper.QA_RESOURCES_REPOSITORY))
                .projectPermission(CS_COMMENT_TEST_MERGE, COMMENTATOR, Permission.PROJECT_READ);

        commit = new RestCommitHelper(RestAuthentication.authenticated(COMMENTATOR, COMMENTATOR),
                CS_COMMENT_TEST, CS_COMMENT_TEST, CS_ID);
    }
}
