use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class ExternalIdIT method createCaseInsensitiveExternalId_DuplicateKey.
@Test
@GerritConfig(name = "auth.userNameCaseInsensitive", value = "true")
public void createCaseInsensitiveExternalId_DuplicateKey() throws Exception {
try (Repository allUsersRepo = repoManager.openRepository(allUsers);
MetaDataUpdate md = metaDataUpdateFactory.create(allUsers)) {
ExternalIdNotes extIdNotes = externalIdNotesFactory.load(allUsersRepo);
testCaseInsensitiveExternalIdKey(md, extIdNotes, SCHEME_USERNAME, "JohnDoe", Account.id(42));
assertThrows(DuplicateExternalIdKeyException.class, () -> extIdNotes.insert(externalIdFactory.create(SCHEME_USERNAME, "johndoe", Account.id(23))));
}
}
use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class RestApiServletIT method xGerritUpdatedRefSetMultipleHeadersForSubmitTopic.
@Test
@GerritConfig(name = "change.submitWholeTopic", value = "true")
public void xGerritUpdatedRefSetMultipleHeadersForSubmitTopic() throws Exception {
String secondProject = "secondProject";
projectOperations.newProject().name(secondProject).create();
TestRepository<InMemoryRepository> secondRepo = cloneProject(Project.nameKey("secondProject"), admin);
String topic = "topic";
String branch = "refs/heads/master";
Result change1 = createChange(testRepo, branch, "first change", "a.txt", "message", topic);
Result change2 = createChange(secondRepo, branch, "second change", "b.txt", "message", topic);
String metaRef1 = RefNames.changeMetaRef(change1.getChange().getId());
String metaRef2 = RefNames.changeMetaRef(change2.getChange().getId());
gApi.changes().id(change1.getChangeId()).current().review(ReviewInput.approve());
gApi.changes().id(change2.getChangeId()).current().review(ReviewInput.approve());
Project.NameKey project1 = change1.getChange().project();
Project.NameKey project2 = change2.getChange().project();
try (Repository repository1 = repoManager.openRepository(project1);
Repository repository2 = repoManager.openRepository(project2)) {
ObjectId originalFirstMetaRefSha1 = getMetaRefSha1(change1);
ObjectId originalSecondMetaRefSha1 = getMetaRefSha1(change2);
ObjectId originalDestinationBranchSha1Project1 = repository1.resolve(change1.getChange().change().getDest().branch());
ObjectId originalDestinationBranchSha1Project2 = repository2.resolve(change2.getChange().change().getDest().branch());
RestResponse response = adminRestSession.postWithHeaders("/changes/" + change2.getChangeId() + "/submit", /* content = */
null, X_GERRIT_UPDATED_REF_ENABLED_HEADER);
response.assertOK();
assertThat(gApi.changes().id(change1.getChangeId()).get().status).isEqualTo(ChangeStatus.MERGED);
ObjectId firstMetaRefSha1 = getMetaRefSha1(change1);
ObjectId secondMetaRefSha1 = getMetaRefSha1(change2);
List<String> headers = response.getHeaders(X_GERRIT_UPDATED_REF);
String branchSha1Project1 = repository1.getRefDatabase().exactRef(change1.getChange().change().getDest().branch()).getObjectId().name();
String branchSha1Project2 = repository2.getRefDatabase().exactRef(change2.getChange().change().getDest().branch()).getObjectId().name();
// During submit, all relevant meta refs of the latest patchset are updated + the destination
// branch/es.
// TODO(paiking): This doesn't work well for torn submissions: If the changes are in
// different projects in the same topic, and we tried to submit those changes together, it's
// possible that the first submission only submitted one of the changes, and then the retry
// submitted the other change. If that happens, when the user retries, they will not get the
// meta ref updates for the change that got submitted on the previous submission attempt.
// Ideally, submit should be idempotent and always return all meta refs on all submission
// attempts.
assertThat(headers).containsExactly(String.format("%s~%s~%s~%s", Url.encode(project1.get()), Url.encode(metaRef1), originalFirstMetaRefSha1.getName(), firstMetaRefSha1.getName()), String.format("%s~%s~%s~%s", Url.encode(project2.get()), Url.encode(metaRef2), originalSecondMetaRefSha1.getName(), secondMetaRefSha1.getName()), String.format("%s~%s~%s~%s", Url.encode(project1.get()), Url.encode(branch), originalDestinationBranchSha1Project1.getName(), branchSha1Project1), String.format("%s~%s~%s~%s", Url.encode(project2.get()), Url.encode(branch), originalDestinationBranchSha1Project2.getName(), branchSha1Project2));
}
}
use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class TraceIT method traceAccount.
@Test
@GerritConfig(name = "tracing.issue123.account", value = "1000000")
public void traceAccount() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener = new TraceValidatingProjectCreationValidationListener();
try (Registration registration = extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = adminRestSession.put("/projects/new15");
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
assertThat(projectCreationListener.traceId).isEqualTo("issue123");
assertThat(projectCreationListener.isLoggingForced).isTrue();
assertThat(projectCreationListener.tags.get("project")).containsExactly("new15");
}
}
use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class TraceIT method traceProject.
@Test
@GerritConfig(name = "tracing.issue123.projectPattern", value = "new12")
public void traceProject() throws Exception {
TraceValidatingProjectCreationValidationListener projectCreationListener = new TraceValidatingProjectCreationValidationListener();
try (Registration registration = extensionRegistry.newRegistration().add(projectCreationListener)) {
RestResponse response = adminRestSession.put("/projects/new12");
assertThat(response.getStatusCode()).isEqualTo(SC_CREATED);
assertThat(response.getHeader(RestApiServlet.X_GERRIT_TRACE)).isNull();
assertThat(projectCreationListener.traceId).isEqualTo("issue123");
assertThat(projectCreationListener.isLoggingForced).isTrue();
assertThat(projectCreationListener.tags.get("project")).containsExactly("new12");
}
}
use of com.google.gerrit.acceptance.config.GerritConfig in project gerrit by GerritCodeReview.
the class CancellationIT method nonMatchingServerDeadlineIsIgnored_projectPattern.
@Test
@GerritConfig(name = "deadline.default.timeout", value = "1ms")
@GerritConfig(name = "deadline.default.projectPattern", value = ".*foo.*")
public void nonMatchingServerDeadlineIsIgnored_projectPattern() throws Exception {
testTicker.useFakeTicker().setAutoIncrementStep(Duration.ofMillis(2));
RestResponse response = adminRestSession.putWithHeaders("/projects/" + name("new"));
response.assertCreated();
}
Aggregations