Merge branch 'stable-2.15'

* stable-2.15:
  Fix "Group members can't be added as reviewers" after merging
  Set version to 2.15-SNAPSHOT
  ProjectLevelConfig: Import Collectors.toList static
  Merge parent config values with child values
  Set version to 2.14.8-SNAPSHOT
  Fix the missing DB entry in Gerrit DB
  Fix unit test "addGroupAsReviewersWhenANotPerfectMatchedUserExist"

Change-Id: I18e635f55f69892b1c5c9f203030f4181973fa3c
This commit is contained in:
David Pursehouse
2018-03-15 10:14:46 +09:00
6 changed files with 219 additions and 29 deletions

View File

@@ -168,7 +168,6 @@ import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.transport.PushResult;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@NoHttpd
@@ -1506,7 +1505,6 @@ public class ChangeIT extends AbstractDaemonTest {
assertThat(sender.getMessages()).hasSize(1);
}
@Ignore
@Test
public void addReviewerThatIsNotPerfectMatch() throws Exception {
TestTimeUtil.resetWithClockStep(1, SECONDS);
@@ -1551,7 +1549,6 @@ public class ChangeIT extends AbstractDaemonTest {
assertThat(rsrc.getChange().getLastUpdatedOn()).isNotEqualTo(oldTs);
}
@Ignore
@Test
public void addGroupAsReviewersWhenANotPerfectMatchedUserExists() throws Exception {
TestTimeUtil.resetWithClockStep(1, SECONDS);
@@ -1560,16 +1557,17 @@ public class ChangeIT extends AbstractDaemonTest {
String oldETag = rsrc.getETag();
Timestamp oldTs = rsrc.getChange().getLastUpdatedOn();
//create a group named "us" with one user: testUser
TestAccount testUser = accountCreator.create("testUser", "testUser@test.com", "testUser");
String testGroup =
createGroupWithRealName(user.fullName.substring(0, user.fullName.length() / 2));
//create a group named "kobe" with one user: lee
TestAccount testUser = accountCreator.create("kobebryant", "kobebryant@test.com", "kobebryant");
TestAccount myGroupUser = accountCreator.create("lee", "lee@test.com", "lee");
String testGroup = createGroupWithRealName("kobe");
GroupApi groupApi = gApi.groups().id(testGroup);
groupApi.description("test group");
groupApi.addMembers(testUser.fullName);
groupApi.addMembers(myGroupUser.fullName);
//ensure that user "user" is not in the group
groupApi.removeMembers(user.fullName);
groupApi.removeMembers(testUser.fullName);
AddReviewerInput in = new AddReviewerInput();
in.reviewer = testGroup;
@@ -1578,11 +1576,11 @@ public class ChangeIT extends AbstractDaemonTest {
List<Message> messages = sender.getMessages();
assertThat(messages).hasSize(1);
Message m = messages.get(0);
assertThat(m.rcpt()).containsExactly(testUser.emailAddress);
assertThat(m.body()).contains("Hello " + testUser.fullName + ",\n");
assertThat(m.rcpt()).containsExactly(myGroupUser.emailAddress);
assertThat(m.body()).contains("Hello " + myGroupUser.fullName + ",\n");
assertThat(m.body()).contains("I'd like you to do a code review.");
assertThat(m.body()).contains("Change subject: " + PushOneCommit.SUBJECT + "\n");
assertMailReplyTo(m, testUser.email);
assertMailReplyTo(m, myGroupUser.email);
ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
// When NoteDb is enabled adding a reviewer records that user as reviewer
@@ -1592,7 +1590,7 @@ public class ChangeIT extends AbstractDaemonTest {
Collection<AccountInfo> reviewers = c.reviewers.get(REVIEWER);
assertThat(reviewers).isNotNull();
assertThat(reviewers).hasSize(1);
assertThat(reviewers.iterator().next()._accountId).isEqualTo(testUser.getId().get());
assertThat(reviewers.iterator().next()._accountId).isEqualTo(myGroupUser.getId().get());
// Ensure ETag and lastUpdatedOn are updated.
rsrc = parseResource(r);

View File

@@ -22,6 +22,7 @@ import com.google.gerrit.acceptance.PushOneCommit;
import com.google.gerrit.reviewdb.client.Project;
import com.google.gerrit.reviewdb.client.RefNames;
import com.google.gerrit.server.project.ProjectState;
import java.util.Arrays;
import org.eclipse.jgit.junit.TestRepository;
import org.eclipse.jgit.lib.Config;
import org.junit.Before;
@@ -114,4 +115,67 @@ public class ProjectLevelConfigIT extends AbstractDaemonTest {
assertThat(state.getConfig(configName).get().toText()).isEqualTo(cfg.toText());
}
@Test
public void withMergedInheritance() throws Exception {
String configName = "test.config";
Config parentCfg = new Config();
parentCfg.setString("s1", null, "k1", "parentValue1");
parentCfg.setString("s1", null, "k2", "parentValue2");
parentCfg.setString("s2", "ss", "k3", "parentValue3");
parentCfg.setString("s2", "ss", "k4", "parentValue4");
pushFactory
.create(
db,
admin.getIdent(),
testRepo,
"Create Project Level Config",
configName,
parentCfg.toText())
.to(RefNames.REFS_CONFIG)
.assertOkStatus();
Project.NameKey childProject = createProject("child", project);
TestRepository<?> childTestRepo = cloneProject(childProject);
fetch(childTestRepo, RefNames.REFS_CONFIG + ":refs/heads/config");
childTestRepo.reset("refs/heads/config");
Config cfg = new Config();
cfg.setString("s1", null, "k1", "parentValue1");
cfg.setString("s1", null, "k2", "parentValue2");
cfg.setString("s2", "ss", "k3", "parentValue3");
cfg.setString("s2", "ss", "k4", "parentValue4");
cfg.setString("s1", null, "k1", "childValue1");
cfg.setString("s2", "ss", "k3", "childValue2");
cfg.setString("s3", null, "k5", "childValue3");
cfg.setString("s3", "ss", "k6", "childValue4");
pushFactory
.create(
db,
admin.getIdent(),
childTestRepo,
"Create Project Level Config",
configName,
cfg.toText())
.to(RefNames.REFS_CONFIG)
.assertOkStatus();
ProjectState state = projectCache.get(childProject);
Config expectedCfg = new Config();
expectedCfg.setStringList("s1", null, "k1", Arrays.asList("childValue1", "parentValue1"));
expectedCfg.setString("s1", null, "k2", "parentValue2");
expectedCfg.setStringList("s2", "ss", "k3", Arrays.asList("childValue2", "parentValue3"));
expectedCfg.setString("s2", "ss", "k4", "parentValue4");
expectedCfg.setString("s3", null, "k5", "childValue3");
expectedCfg.setString("s3", "ss", "k6", "childValue4");
assertThat(state.getConfig(configName).getWithInheritance(true).toText())
.isEqualTo(expectedCfg.toText());
assertThat(state.getConfig(configName).get().toText()).isEqualTo(cfg.toText());
}
}