@Test
public void testBranchCommitInsertionQuery() {

    long count = 0;
    executeSuccess(queries.branchInsertionStatement(projectId, 0, originCommit, mergedIntoCommit));
    // We can't call on not existing branch
    executeFailure(queries.branchCommitInsertionQuery(projectId, 1, "sha", 1));
    assertEquals(count, getBranchCommitCount());
    // We can't call on not existing commit
    executeFailure(queries.branchCommitInsertionQuery(projectId, 0, "sha", 1));
    assertEquals(count, getBranchCommitCount());
    // We can insert a commit in a branch
    Commit branchCommit = prepareCommit("sha", 0);
    Commit anotherCommit = prepareCommit("another", 4);
    executeSuccess(queries.branchCommitInsertionQuery(projectId, 0, branchCommit.sha, 1));
    assertEquals(++count, getBranchCommitCount());
    executeSuccess(queries.branchCommitInsertionQuery(projectId, 0, anotherCommit.sha, 2));
    assertEquals(++count, getBranchCommitCount());
    // We can insert the same commit in another branch
    executeSuccess(queries.branchInsertionStatement(projectId, 1, originCommit, mergedIntoCommit));
    executeSuccess(queries.branchCommitInsertionQuery(projectId, 1, branchCommit.sha, 1));
    assertEquals(++count, getBranchCommitCount());
    executeSuccess(queries.branchCommitInsertionQuery(projectId, 1, anotherCommit.sha, 4));
    assertEquals(++count, getBranchCommitCount());
    // We can insert the same branch ordinal in another project
    int secondProjectID = createProject("anotherProject", projectQueries);
    executeSuccess(commitQueries.commitInsertionStatement(secondProjectID, originCommit, GitDiff.EMPTY));
    executeSuccess(commitQueries.commitInsertionStatement(secondProjectID, mergedIntoCommit, GitDiff.EMPTY));
    executeSuccess(commitQueries.commitInsertionStatement(secondProjectID, branchCommit, GitDiff.EMPTY));
    executeSuccess(commitQueries.commitInsertionStatement(secondProjectID, anotherCommit, GitDiff.EMPTY));
    executeSuccess(queries.branchInsertionStatement(secondProjectID, 0, originCommit, mergedIntoCommit));
    executeSuccess(queries.branchCommitInsertionQuery(secondProjectID, 0, branchCommit.sha, 1));
    assertEquals(++count, getBranchCommitCount());
    executeSuccess(queries.branchCommitInsertionQuery(secondProjectID, 0, anotherCommit.sha, 3));
    assertEquals(++count, getBranchCommitCount());
    // We can't insert the same ordinal, whichever the commit
    executeNothinhDone(queries.branchCommitInsertionQuery(projectId, 0, branchCommit.sha, 1));
    assertEquals(count, getBranchCommitCount());
    executeNothinhDone(queries.branchCommitInsertionQuery(projectId, 0, anotherCommit.sha, 2));
    assertEquals(count, getBranchCommitCount());
    // We can't insert the same commit, whichever the ordinal
    executeNothinhDone(queries.branchCommitInsertionQuery(projectId, 0, anotherCommit.sha, 1));
    assertEquals(count, getBranchCommitCount());
    executeNothinhDone(queries.branchCommitInsertionQuery(projectId, 0, branchCommit.sha, 2));
    assertEquals(count, getBranchCommitCount());
    executeNothinhDone(queries.branchCommitInsertionQuery(projectId, 0, anotherCommit.sha, 45));
    assertEquals(count, getBranchCommitCount());
    executeNothinhDone(queries.branchCommitInsertionQuery(projectId, 0, branchCommit.sha, 27));
    assertEquals(count, getBranchCommitCount());
}