package it.com.atlassian.stash;

import com.atlassian.bitbucket.test.RepositoryTestHelper;
import org.junit.BeforeClass;
import org.springframework.core.io.ClassPathResource;

public abstract class MergeCommitsFuncTest extends BaseBrowserFuncTest {

    private static final String PROJECT_KEY_PREFIX = "MERGE-";
    private static final String REPO_SLUG_SUFFIX = "merge-commits-";

    private static RepositoryCoordinates coordinates;

    @BeforeClass
    public static void initRepository() throws Exception {
        coordinates = new RepositoryCoordinates();

        getClassTestContext()
                .project(coordinates.projectKey, "Merge Commits Project")
                .repository(coordinates.projectKey, coordinates.repoSlug, new ClassPathResource(RepositoryTestHelper.MERGE_COMMITS_REPOSITORY));
    }

    protected static String getMergeCommitsProjectKey() {
        return coordinates.projectKey;
    }

    protected static String getMergeCommitsRepoSlug() {
        return coordinates.repoSlug;
    }

    private static class RepositoryCoordinates {
        private final String projectKey;
        private final String repoSlug;

        private RepositoryCoordinates() {
            String suffix = Long.toString(System.currentTimeMillis() % 10000);
            this.projectKey = PROJECT_KEY_PREFIX + suffix;
            this.repoSlug = REPO_SLUG_SUFFIX + suffix;
        }
    }
}
