use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class GroupConfigTest method timestampOfAuthorMatchesSpecifiedUpdatedOnOfUpdatedGroup.
@Test
// Instants
@SuppressWarnings("JdkObsolete")
public void timestampOfAuthorMatchesSpecifiedUpdatedOnOfUpdatedGroup() throws Exception {
Instant authorTimestamp = toInstant(LocalDate.of(2017, Month.DECEMBER, 13).atTime(15, 5, 27));
Instant updatedOn = toInstant(LocalDate.of(2016, Month.MARCH, 11).atTime(23, 49, 11));
createArbitraryGroup(groupUuid);
GroupDelta groupDelta = GroupDelta.builder().setName(AccountGroup.nameKey("Another name")).setUpdatedOn(updatedOn).build();
GroupConfig groupConfig = GroupConfig.loadForGroup(projectName, repository, groupUuid);
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(updatedOn.toEpochMilli());
assertThat(revCommit.getAuthorIdent().getTimeZone().getRawOffset()).isEqualTo(timeZone.getRawOffset());
}
use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class GroupConfigTest method nameOfNewGroupMustNotBeEmpty.
@Test
public void nameOfNewGroupMustNotBeEmpty() throws Exception {
InternalGroupCreation groupCreation = getPrefilledGroupCreationBuilder().setNameKey(AccountGroup.nameKey("")).build();
GroupConfig groupConfig = GroupConfig.createForNewGroup(projectName, repository, groupCreation);
try (MetaDataUpdate metaDataUpdate = createMetaDataUpdate()) {
Throwable thrown = assertThrows(Throwable.class, () -> groupConfig.commit(metaDataUpdate));
assertThat(thrown.getCause(), instanceOf(ConfigInvalidException.class));
assertThat(thrown).hasMessageThat().contains("Name of the group " + groupUuid);
}
}
use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class GroupConfigTest method idOfNewGroupMustNotBeNegative.
@Test
public void idOfNewGroupMustNotBeNegative() throws Exception {
InternalGroupCreation groupCreation = getPrefilledGroupCreationBuilder().setId(AccountGroup.id(-2)).build();
GroupConfig groupConfig = GroupConfig.createForNewGroup(projectName, repository, groupCreation);
try (MetaDataUpdate metaDataUpdate = createMetaDataUpdate()) {
Throwable thrown = assertThrows(Throwable.class, () -> groupConfig.commit(metaDataUpdate));
assertThat(thrown.getCause(), instanceOf(ConfigInvalidException.class));
assertThat(thrown).hasMessageThat().contains("ID of the group " + groupUuid);
}
}
use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class GroupConfigTest method createMetaDataUpdate.
// TODO(issue-15517): Fix the JdkObsolete issue with Date once JGit's PersonIdent class supports
// Instants
@SuppressWarnings("JdkObsolete")
private MetaDataUpdate createMetaDataUpdate() {
PersonIdent serverIdent = new PersonIdent("Gerrit Server", "noreply@gerritcodereview.com", Date.from(TimeUtil.now()), timeZone);
MetaDataUpdate metaDataUpdate = new MetaDataUpdate(GitReferenceUpdated.DISABLED, Project.nameKey("Test Repository"), repository);
metaDataUpdate.getCommitBuilder().setCommitter(serverIdent);
metaDataUpdate.getCommitBuilder().setAuthor(serverIdent);
return metaDataUpdate;
}
use of com.google.gerrit.server.git.meta.MetaDataUpdate in project gerrit by GerritCodeReview.
the class ExternalIdIT method shouldTolerateDuplicateExternalIdsWhenInMigrationMode.
@Test
@GerritConfig(name = "auth.userNameCaseInsensitive", value = "true")
@GerritConfig(name = "auth.userNameCaseInsensitiveMigrationMode", value = "true")
public void shouldTolerateDuplicateExternalIdsWhenInMigrationMode() throws Exception {
Account.Id firstAccountId = Account.id(1);
Account.Id secondAccountId = Account.id(2);
try (Repository allUsersRepo = repoManager.openRepository(allUsers);
MetaDataUpdate md = metaDataUpdateFactory.create(allUsers)) {
ExternalIdNotes extIdNotes = externalIdNotesFactory.load(allUsersRepo);
createExternalId(md, extIdNotes, SCHEME_GERRIT, "janedoe", firstAccountId, CASE_SENSITIVE_USERNAME);
createExternalId(md, extIdNotes, SCHEME_GERRIT, "JaneDoe", secondAccountId, CASE_SENSITIVE_USERNAME);
ExternalId.Key firstAccountExternalId = externalIdKeyFactory.create(SCHEME_GERRIT, "janedoe", CASE_INSENSITIVE_USERNAME);
assertThat(externalIds.get(firstAccountExternalId).get().accountId()).isEqualTo(firstAccountId);
ExternalId.Key secondAccountExternalId = externalIdKeyFactory.create(SCHEME_GERRIT, "JaneDoe", CASE_INSENSITIVE_USERNAME);
assertThat(externalIds.get(secondAccountExternalId).get().accountId()).isEqualTo(secondAccountId);
}
}
Aggregations