use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class ExternalIdNotesUpsertPreprocessorIT method replace.
@Test
public void replace() throws Exception {
Account.Id id = Account.id(sequences.nextAccountId());
ExternalId extId1 = extIdFactory.create("foo", "bar1", id);
ExternalId extId2 = extIdFactory.create("foo", "bar2", id);
accountsUpdateProvider.get().insert("test", id, u -> u.addExternalId(extId1));
testPreprocessor.reset();
try (Repository allUsersRepo = repoManager.openRepository(allUsers);
MetaDataUpdate md = metaDataUpdateFactory.create(allUsers)) {
ExternalIdNotes extIdNotes = extIdNotesFactory.load(allUsersRepo);
extIdNotes.replace(ImmutableSet.of(extId1), ImmutableSet.of(extId2));
extIdNotes.commit(md);
}
assertThat(testPreprocessor.upserted).containsExactly(extId2);
}
use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class ExternalIdNotesUpsertPreprocessorIT method replaceByKeys.
@Test
public void replaceByKeys() throws Exception {
Account.Id id = Account.id(sequences.nextAccountId());
ExternalId extId1 = extIdFactory.create("foo", "bar1", id);
ExternalId extId2 = extIdFactory.create("foo", "bar2", id);
accountsUpdateProvider.get().insert("test", id, u -> u.addExternalId(extId1));
testPreprocessor.reset();
try (Repository allUsersRepo = repoManager.openRepository(allUsers);
MetaDataUpdate md = metaDataUpdateFactory.create(allUsers)) {
ExternalIdNotes extIdNotes = extIdNotesFactory.load(allUsersRepo);
extIdNotes.replaceByKeys(ImmutableSet.of(extId1.key()), ImmutableSet.of(extId2));
extIdNotes.commit(md);
}
assertThat(testPreprocessor.upserted).containsExactly(extId2);
}
use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class ExternalIDCacheLoaderTest method performExternalIdUpdate.
private ObjectId performExternalIdUpdate(Consumer<ExternalIdNotes> update) throws Exception {
try (Repository repo = repoManager.openRepository(ALL_USERS)) {
PersonIdent updater = new PersonIdent("Foo bar", "foo@bar.com");
ExternalIdNotes extIdNotes = ExternalIdNotes.load(ALL_USERS, repo, externalIdFactory, false);
update.accept(extIdNotes);
try (MetaDataUpdate metaDataUpdate = new MetaDataUpdate(GitReferenceUpdated.DISABLED, null, repo)) {
metaDataUpdate.getCommitBuilder().setAuthor(updater);
metaDataUpdate.getCommitBuilder().setCommitter(updater);
return extIdNotes.commit(metaDataUpdate).getId();
}
}
}
use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class GroupConfigTest method ownerGroupUuidOfNewGroupMustNotBeEmpty.
@Test
public void ownerGroupUuidOfNewGroupMustNotBeEmpty() throws Exception {
InternalGroupCreation groupCreation = getPrefilledGroupCreationBuilder().build();
GroupDelta groupDelta = GroupDelta.builder().setOwnerGroupUUID(AccountGroup.uuid("")).build();
GroupConfig groupConfig = GroupConfig.createForNewGroup(projectName, repository, groupCreation);
groupConfig.setGroupDelta(groupDelta, auditLogFormatter);
try (MetaDataUpdate metaDataUpdate = createMetaDataUpdate()) {
Throwable thrown = assertThrows(Throwable.class, () -> groupConfig.commit(metaDataUpdate));
assertThat(thrown.getCause(), instanceOf(ConfigInvalidException.class));
assertThat(thrown).hasMessageThat().contains("Owner UUID of the group " + groupUuid);
}
}
use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class GroupConfigTest method timestampOfAuthorMatchesSpecifiedCreatedOnOfNewGroup.
// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
@Test
public void timestampOfAuthorMatchesSpecifiedCreatedOnOfNewGroup() throws Exception {
Instant authorTimestamp = toInstant(LocalDate.of(2017, Month.DECEMBER, 13).atTime(15, 5, 27));
Instant createdOn = toInstant(LocalDate.of(2016, Month.MARCH, 11).atTime(23, 49, 11));
InternalGroupCreation groupCreation = InternalGroupCreation.builder().setGroupUUID(groupUuid).setNameKey(groupName).setId(groupId).build();
GroupDelta groupDelta = GroupDelta.builder().setName(AccountGroup.nameKey("Another name")).setUpdatedOn(createdOn).build();
GroupConfig groupConfig = GroupConfig.createForNewGroup(projectName, repository, groupCreation);
groupConfig.setGroupDelta(groupDelta, auditLogFormatter);
PersonIdent authorIdent = new PersonIdent("Jane", "Jane@gerritcodereview.com", Date.from(authorTimestamp), timeZone);
try (MetaDataUpdate metaDataUpdate = createMetaDataUpdate()) {
metaDataUpdate.getCommitBuilder().setAuthor(authorIdent);
groupConfig.commit(metaDataUpdate);
}
RevCommit revCommit = getLatestCommitForGroup(groupUuid);
assertThat(revCommit.getAuthorIdent().getWhen().getTime()).isEqualTo(createdOn.toEpochMilli());
assertThat(revCommit.getAuthorIdent().getTimeZone().getRawOffset()).isEqualTo(timeZone.getRawOffset());
}
Aggregations