Search in sources :

Example 91 with ChangeData

use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.

the class PermissionBackendConditionIT method changePermissions_sameResourceDifferentUserDoesNotEqual.

@Test
public void changePermissions_sameResourceDifferentUserDoesNotEqual() throws Exception {
    ChangeData change = createChange().getChange();
    BooleanCondition cond1 = pb.user(user()).change(change).testCond(ChangePermission.READ);
    BooleanCondition cond2 = pb.user(admin()).change(change).testCond(ChangePermission.READ);
    assertNotEquals(cond1, cond2);
    assertNotEquals(cond1.hashCode(), cond2.hashCode());
}
Also used : BooleanCondition(com.google.gerrit.extensions.conditions.BooleanCondition) ChangeData(com.google.gerrit.server.query.change.ChangeData) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 92 with ChangeData

use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.

the class SubmitRequirementsEvaluatorIT method byAuthorEmail.

@Test
public void byAuthorEmail() throws Exception {
    TestAccount user2 = accountCreator.create("Foo", "user@example.com", "User", /* displayName = */
    null);
    requestScopeOperations.setApiUser(user2.id());
    ChangeInfo info = gApi.changes().create(new ChangeInput(project.get(), "master", "Test Change")).get();
    ChangeData cd = changeQueryProvider.get().byLegacyChangeId(Change.Id.tryParse(Integer.toString(info._number)).get()).get(0);
    // Match by email works
    checkSubmitRequirementResult(cd, /* submittabilityExpr= */
    "authoremail:\"^.*@example\\.com\"", SubmitRequirementResult.Status.SATISFIED);
    checkSubmitRequirementResult(cd, /* submittabilityExpr= */
    "authoremail:\"^user@.*\\.com\"", SubmitRequirementResult.Status.SATISFIED);
    // Match by name does not work
    checkSubmitRequirementResult(cd, /* submittabilityExpr= */
    "authoremail:\"^Foo$\"", SubmitRequirementResult.Status.UNSATISFIED);
    checkSubmitRequirementResult(cd, /* submittabilityExpr= */
    "authoremail:\"^User$\"", SubmitRequirementResult.Status.UNSATISFIED);
}
Also used : ChangeInfo(com.google.gerrit.extensions.common.ChangeInfo) ChangeInput(com.google.gerrit.extensions.common.ChangeInput) TestAccount(com.google.gerrit.acceptance.TestAccount) ChangeData(com.google.gerrit.server.query.change.ChangeData) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 93 with ChangeData

use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.

the class SubmitRequirementsEvaluatorIT method byFileEdits_addedContent_matching.

@Test
public void byFileEdits_addedContent_matching() throws Exception {
    Change.Id parent = changeOperations.newChange().file(FILE_NAME).content(CONTENT).create();
    Change.Id childId = changeOperations.newChange().file(FILE_NAME).content(CONTENT + "line 4\n").childOf().change(parent).create();
    SubmitRequirementExpression exp = SubmitRequirementExpression.create("file:\"'^.*\\.txt',withDiffContaining='line 4'\"");
    ChangeData childChangeData = changeQueryProvider.get().byLegacyChangeId(childId).get(0);
    SubmitRequirementExpressionResult srResult = evaluator.evaluateExpression(exp, childChangeData);
    assertThat(srResult.status()).isEqualTo(SubmitRequirementExpressionResult.Status.PASS);
}
Also used : SubmitRequirementExpression(com.google.gerrit.entities.SubmitRequirementExpression) SubmitRequirementExpressionResult(com.google.gerrit.entities.SubmitRequirementExpressionResult) Change(com.google.gerrit.entities.Change) ChangeData(com.google.gerrit.server.query.change.ChangeData) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 94 with ChangeData

use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.

the class SubmitRequirementsEvaluatorIT method byFileEdits_notMatchingWithFilePath.

@Test
public void byFileEdits_notMatchingWithFilePath() throws Exception {
    Change.Id parent = changeOperations.newChange().file(FILE_NAME).content(CONTENT).create();
    Change.Id childId = changeOperations.newChange().file(FILE_NAME).content(CONTENT.replace("line 3\n", "line three\n")).childOf().change(parent).create();
    // commit edit only matches with files ending with ".java". Since our modified file name ends
    // with ".txt", the applicability expression will not match.
    SubmitRequirementExpression exp = SubmitRequirementExpression.create("file:\"'^.*\\.java',withDiffContaining='three'\"");
    ChangeData childChangeData = changeQueryProvider.get().byLegacyChangeId(childId).get(0);
    SubmitRequirementExpressionResult srResult = evaluator.evaluateExpression(exp, childChangeData);
    assertThat(srResult.status()).isEqualTo(SubmitRequirementExpressionResult.Status.FAIL);
}
Also used : SubmitRequirementExpression(com.google.gerrit.entities.SubmitRequirementExpression) SubmitRequirementExpressionResult(com.google.gerrit.entities.SubmitRequirementExpressionResult) Change(com.google.gerrit.entities.Change) ChangeData(com.google.gerrit.server.query.change.ChangeData) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 95 with ChangeData

use of com.google.gerrit.server.query.change.ChangeData in project gerrit by GerritCodeReview.

the class SubmitRequirementsEvaluatorIT method byFileEdits_modifiedContent_nonMatching.

@Test
public void byFileEdits_modifiedContent_nonMatching() throws Exception {
    Change.Id parent = changeOperations.newChange().file(FILE_NAME).content(CONTENT).create();
    Change.Id childId = changeOperations.newChange().file(FILE_NAME).content(CONTENT.replace("line 3\n", "line three\n")).childOf().change(parent).create();
    SubmitRequirementExpression exp = SubmitRequirementExpression.create("file:\"'^.*\\.txt',withDiffContaining='ten'\"");
    ChangeData childChangeData = changeQueryProvider.get().byLegacyChangeId(childId).get(0);
    SubmitRequirementExpressionResult srResult = evaluator.evaluateExpression(exp, childChangeData);
    assertThat(srResult.status()).isEqualTo(SubmitRequirementExpressionResult.Status.FAIL);
}
Also used : SubmitRequirementExpression(com.google.gerrit.entities.SubmitRequirementExpression) SubmitRequirementExpressionResult(com.google.gerrit.entities.SubmitRequirementExpressionResult) Change(com.google.gerrit.entities.Change) ChangeData(com.google.gerrit.server.query.change.ChangeData) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Aggregations

ChangeData (com.google.gerrit.server.query.change.ChangeData)208 Test (org.junit.Test)75 Change (com.google.gerrit.entities.Change)58 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)57 RevCommit (org.eclipse.jgit.revwalk.RevCommit)53 ObjectId (org.eclipse.jgit.lib.ObjectId)45 ArrayList (java.util.ArrayList)41 IOException (java.io.IOException)33 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)27 PatchSet (com.google.gerrit.entities.PatchSet)26 StorageException (com.google.gerrit.exceptions.StorageException)25 Inject (com.google.inject.Inject)25 HashMap (java.util.HashMap)25 Map (java.util.Map)24 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)23 List (java.util.List)23 Project (com.google.gerrit.entities.Project)21 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)21 OrmException (com.google.gwtorm.server.OrmException)20 Repository (org.eclipse.jgit.lib.Repository)20