DashboardIT: Add tests for getting dashboard
Since we don't yet have an API to create dashboards, add a utility method in the test class to do that by directly writing a dummy dashboard config to the repository under test. Add basic tests to confirm that the get() methods work as expected. Change-Id: I2e933d6f50dda03d7c7f1cb4b0493e36e8f7c69e
This commit is contained in:
@@ -14,9 +14,19 @@
|
||||
|
||||
package com.google.gerrit.acceptance.api.project;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS;
|
||||
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.NoHttpd;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.extensions.api.projects.BranchInput;
|
||||
import com.google.gerrit.extensions.api.projects.DashboardInfo;
|
||||
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
|
||||
import com.google.gerrit.server.project.DashboardsCollection;
|
||||
import org.eclipse.jgit.junit.TestRepository;
|
||||
import org.eclipse.jgit.lib.Repository;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.junit.Test;
|
||||
|
||||
@NoHttpd
|
||||
@@ -32,4 +42,44 @@ public class DashboardIT extends AbstractDaemonTest {
|
||||
exception.expect(ResourceNotFoundException.class);
|
||||
gApi.projects().name(project.get()).dashboard("my:dashboard").get();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getDashboard() throws Exception {
|
||||
DashboardInfo info = createDashboard(DashboardsCollection.DEFAULT_DASHBOARD_NAME, "test");
|
||||
DashboardInfo result = gApi.projects().name(project.get()).dashboard(info.id).get();
|
||||
assertThat(result.id).isEqualTo(info.id);
|
||||
assertThat(result.path).isEqualTo(info.path);
|
||||
assertThat(result.ref).isEqualTo(info.ref);
|
||||
assertThat(result.project).isEqualTo(project.get());
|
||||
assertThat(result.definingProject).isEqualTo(project.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void cannotGetDashboardWithInheritedForNonDefault() throws Exception {
|
||||
DashboardInfo info = createDashboard(DashboardsCollection.DEFAULT_DASHBOARD_NAME, "test");
|
||||
exception.expect(ResourceNotFoundException.class);
|
||||
exception.expectMessage("inherited");
|
||||
gApi.projects().name(project.get()).dashboard(info.id).get(true);
|
||||
}
|
||||
|
||||
private DashboardInfo createDashboard(String ref, String path) throws Exception {
|
||||
DashboardInfo info = DashboardsCollection.newDashboardInfo(ref, path);
|
||||
String canonicalRef = DashboardsCollection.normalizeDashboardRef(info.ref);
|
||||
allow("refs/meta/dashboards/*", Permission.CREATE, REGISTERED_USERS);
|
||||
gApi.projects().name(project.get()).branch(canonicalRef).create(new BranchInput());
|
||||
try (Repository r = repoManager.openRepository(project)) {
|
||||
TestRepository<Repository>.CommitBuilder cb =
|
||||
new TestRepository<>(r).branch(canonicalRef).commit();
|
||||
String content =
|
||||
"[dashboard]\n"
|
||||
+ "Description = Test\n"
|
||||
+ "foreach = owner:self\n"
|
||||
+ "[section \"Mine\"]\n"
|
||||
+ "query = is:open";
|
||||
cb.add(info.path, content);
|
||||
RevCommit c = cb.create();
|
||||
gApi.projects().name(project.get()).commit(c.name());
|
||||
}
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user