Acceptance tests: Remove duplicated JSON container classes
This change makes it possible to reuse server side classes for both input and output JSON container classes. To solve the mismatch between server-side CamelCase and lower case with underscore the field naming policy is set to FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES in GsonBuilder in RestSession in acceptance framework. Now we can remove dozen of duplicated classes in acceptance framework. Change-Id: Icdc7f63a38c304f3a744a7a12b768cda2504a55e
This commit is contained in:
@@ -20,6 +20,7 @@ java_library(
|
||||
'//lib:args4j',
|
||||
'//lib:gson',
|
||||
'//lib:guava',
|
||||
'//lib:gwtjsonrpc',
|
||||
'//lib:gwtorm',
|
||||
'//lib:h2',
|
||||
'//lib:jsch',
|
||||
|
@@ -14,6 +14,9 @@
|
||||
|
||||
package com.google.gerrit.acceptance;
|
||||
|
||||
import com.google.gerrit.server.OutputFormat;
|
||||
import com.google.gson.Gson;
|
||||
|
||||
import org.eclipse.jgit.lib.Config;
|
||||
import org.junit.Rule;
|
||||
import org.junit.rules.TestRule;
|
||||
@@ -66,4 +69,8 @@ public abstract class AbstractDaemonTest {
|
||||
private void afterTest() throws Exception {
|
||||
server.stop();
|
||||
}
|
||||
|
||||
protected static Gson newGson() {
|
||||
return OutputFormat.JSON_COMPACT.newGson();
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@ package com.google.gerrit.acceptance;
|
||||
|
||||
import com.google.common.base.CharMatcher;
|
||||
import com.google.common.base.Charsets;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gerrit.server.OutputFormat;
|
||||
|
||||
import org.apache.http.auth.AuthScope;
|
||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||
@@ -56,7 +56,7 @@ public class RestSession {
|
||||
if (content != null) {
|
||||
put.addHeader(new BasicHeader("Content-Type", "application/json"));
|
||||
put.setEntity(new StringEntity(
|
||||
new Gson().toJson(content),
|
||||
OutputFormat.JSON_COMPACT.newGson().toJson(content),
|
||||
Charsets.UTF_8.name()));
|
||||
}
|
||||
return new RestResponse(getClient().execute(put));
|
||||
@@ -71,7 +71,7 @@ public class RestSession {
|
||||
if (content != null) {
|
||||
post.addHeader(new BasicHeader("Content-Type", "application/json"));
|
||||
post.setEntity(new StringEntity(
|
||||
new Gson().toJson(content),
|
||||
OutputFormat.JSON_COMPACT.newGson().toJson(content),
|
||||
Charsets.UTF_8.name()));
|
||||
}
|
||||
return new RestResponse(getClient().execute(post));
|
||||
|
@@ -18,6 +18,7 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.server.account.AccountInfo;
|
||||
|
||||
public class AccountAssert {
|
||||
|
||||
|
@@ -1,21 +0,0 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.rest.account;
|
||||
|
||||
public class AccountInfo {
|
||||
public Integer _account_id;
|
||||
public String name;
|
||||
public String email;
|
||||
}
|
@@ -5,7 +5,6 @@ acceptance_tests(
|
||||
deps = [
|
||||
':util',
|
||||
'//gerrit-acceptance-tests:lib',
|
||||
'//gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/rest/change:util',
|
||||
],
|
||||
)
|
||||
|
||||
@@ -13,7 +12,6 @@ java_library(
|
||||
name = 'util',
|
||||
srcs = [
|
||||
'AccountAssert.java',
|
||||
'AccountInfo.java',
|
||||
'CapabilityInfo.java',
|
||||
],
|
||||
deps = [
|
||||
|
@@ -23,8 +23,7 @@ import com.google.gerrit.acceptance.RestResponse;
|
||||
import com.google.gerrit.acceptance.RestSession;
|
||||
import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.extensions.restapi.Url;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gerrit.server.account.AccountInfo;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.apache.http.HttpStatus;
|
||||
@@ -80,9 +79,7 @@ public class GetAccountIT extends AbstractDaemonTest {
|
||||
throws IOException {
|
||||
RestResponse r = session.get(url);
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
AccountInfo account =
|
||||
(new Gson()).fromJson(r.getReader(),
|
||||
new TypeToken<AccountInfo>() {}.getType());
|
||||
assertAccountInfo(expectedAccount, account);
|
||||
assertAccountInfo(expectedAccount, newGson()
|
||||
.fromJson(r.getReader(), AccountInfo.class));
|
||||
}
|
||||
}
|
||||
|
@@ -22,9 +22,7 @@ import com.google.gerrit.acceptance.RestResponse;
|
||||
import com.google.gerrit.acceptance.RestSession;
|
||||
import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.reviewdb.client.AccountDiffPreference;
|
||||
import com.google.gerrit.reviewdb.client.AccountDiffPreference.Whitespace;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gerrit.server.account.GetDiffPreferences.DiffPreferencesInfo;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
@@ -60,26 +58,25 @@ public class GetDiffPreferencesIT extends AbstractDaemonTest {
|
||||
RestResponse r = session.get("/accounts/" + admin.email + "/preferences.diff");
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
DiffPreferencesInfo diffPreferences =
|
||||
(new Gson()).fromJson(r.getReader(),
|
||||
new TypeToken<DiffPreferencesInfo>() {}.getType());
|
||||
newGson().fromJson(r.getReader(), DiffPreferencesInfo.class);
|
||||
assertDiffPreferences(new AccountDiffPreference(admin.id), diffPreferences);
|
||||
}
|
||||
|
||||
private static void assertDiffPreferences(AccountDiffPreference expected, DiffPreferencesInfo actual) {
|
||||
assertEquals(expected.getContext(), actual.context);
|
||||
assertEquals(expected.isExpandAllComments(), toBoolean(actual.expand_all_comments));
|
||||
assertEquals(expected.getIgnoreWhitespace(), actual.ignore_whitespace);
|
||||
assertEquals(expected.isIntralineDifference(), toBoolean(actual.intraline_difference));
|
||||
assertEquals(expected.getLineLength(), actual.line_length);
|
||||
assertEquals(expected.isManualReview(), toBoolean(actual.manual_review));
|
||||
assertEquals(expected.isRetainHeader(), toBoolean(actual.retain_header));
|
||||
assertEquals(expected.isShowLineEndings(), toBoolean(actual.show_line_endings));
|
||||
assertEquals(expected.isShowTabs(), toBoolean(actual.show_tabs));
|
||||
assertEquals(expected.isShowWhitespaceErrors(), toBoolean(actual.show_whitespace_errors));
|
||||
assertEquals(expected.isSkipDeleted(), toBoolean(actual.skip_deleted));
|
||||
assertEquals(expected.isSkipUncommented(), toBoolean(actual.skip_uncommented));
|
||||
assertEquals(expected.isSyntaxHighlighting(), toBoolean(actual.syntax_highlighting));
|
||||
assertEquals(expected.getTabSize(), actual.tab_size);
|
||||
assertEquals(expected.isExpandAllComments(), toBoolean(actual.expandAllComments));
|
||||
assertEquals(expected.getIgnoreWhitespace(), actual.ignoreWhitespace);
|
||||
assertEquals(expected.isIntralineDifference(), toBoolean(actual.intralineDifference));
|
||||
assertEquals(expected.getLineLength(), actual.lineLength);
|
||||
assertEquals(expected.isManualReview(), toBoolean(actual.manualReview));
|
||||
assertEquals(expected.isRetainHeader(), toBoolean(actual.retainHeader));
|
||||
assertEquals(expected.isShowLineEndings(), toBoolean(actual.showLineEndings));
|
||||
assertEquals(expected.isShowTabs(), toBoolean(actual.showTabs));
|
||||
assertEquals(expected.isShowWhitespaceErrors(), toBoolean(actual.showWhitespaceErrors));
|
||||
assertEquals(expected.isSkipDeleted(), toBoolean(actual.skipDeleted));
|
||||
assertEquals(expected.isSkipUncommented(), toBoolean(actual.skipUncommented));
|
||||
assertEquals(expected.isSyntaxHighlighting(), toBoolean(actual.syntaxHighlighting));
|
||||
assertEquals(expected.getTabSize(), actual.tabSize);
|
||||
}
|
||||
|
||||
private static boolean toBoolean(Boolean b) {
|
||||
@@ -88,21 +85,4 @@ public class GetDiffPreferencesIT extends AbstractDaemonTest {
|
||||
}
|
||||
return b.booleanValue();
|
||||
}
|
||||
|
||||
static class DiffPreferencesInfo {
|
||||
short context;
|
||||
Boolean expand_all_comments;
|
||||
Whitespace ignore_whitespace;
|
||||
Boolean intraline_difference;
|
||||
int line_length;
|
||||
Boolean manual_review;
|
||||
Boolean retain_header;
|
||||
Boolean show_line_endings;
|
||||
Boolean show_tabs;
|
||||
Boolean show_whitespace_errors;
|
||||
Boolean skip_deleted;
|
||||
Boolean skip_uncommented;
|
||||
Boolean syntax_highlighting;
|
||||
int tab_size;
|
||||
}
|
||||
}
|
||||
|
@@ -24,17 +24,15 @@ import static org.junit.Assert.assertTrue;
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.AccountCreator;
|
||||
import com.google.gerrit.acceptance.PushOneCommit;
|
||||
import com.google.gerrit.acceptance.PushOneCommit.Result;
|
||||
import com.google.gerrit.acceptance.RestResponse;
|
||||
import com.google.gerrit.acceptance.RestSession;
|
||||
import com.google.gerrit.acceptance.SshSession;
|
||||
import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.acceptance.PushOneCommit.Result;
|
||||
import com.google.gerrit.acceptance.rest.change.ChangeInfo;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gerrit.server.change.ChangeJson.ChangeInfo;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
@@ -46,7 +44,6 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class StarredChangesIT extends AbstractDaemonTest {
|
||||
|
||||
@@ -101,10 +98,8 @@ public class StarredChangesIT extends AbstractDaemonTest {
|
||||
}
|
||||
|
||||
private ChangeInfo getChange(String changeId) throws IOException {
|
||||
RestResponse r = session.get("/changes/?q=" + changeId);
|
||||
List<ChangeInfo> c = (new Gson()).fromJson(r.getReader(),
|
||||
new TypeToken<List<ChangeInfo>>() {}.getType());
|
||||
return c.get(0);
|
||||
RestResponse r = session.get("/changes/" + changeId + "/detail");
|
||||
return newGson().fromJson(r.getReader(), ChangeInfo.class);
|
||||
}
|
||||
|
||||
private void starChange(boolean on, Change.Id id) throws IOException {
|
||||
|
@@ -33,6 +33,7 @@ import com.google.gerrit.acceptance.SshSession;
|
||||
import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.common.changes.ListChangesOption;
|
||||
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
||||
import com.google.gerrit.extensions.api.changes.SubmitInput;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.Project.InheritableBoolean;
|
||||
@@ -41,10 +42,8 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.change.ChangeJson.ChangeInfo;
|
||||
import com.google.gerrit.server.change.ChangeJson.LabelInfo;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gerrit.server.project.PutConfig;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gwtjsonrpc.server.SqlTimestampDeserializer;
|
||||
import com.google.gwtorm.server.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
@@ -64,7 +63,6 @@ import org.junit.Test;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public abstract class AbstractSubmit extends AbstractDaemonTest {
|
||||
|
||||
@@ -131,17 +129,17 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
||||
}
|
||||
|
||||
private void setSubmitType(SubmitType submitType) throws IOException {
|
||||
ProjectConfigInput in = new ProjectConfigInput();
|
||||
in.submit_type = submitType;
|
||||
in.use_content_merge = InheritableBoolean.FALSE;
|
||||
PutConfig.Input in = new PutConfig.Input();
|
||||
in.submitType = submitType;
|
||||
in.useContentMerge = InheritableBoolean.FALSE;
|
||||
RestResponse r = session.put("/projects/" + project.get() + "/config", in);
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
r.consume();
|
||||
}
|
||||
|
||||
protected void setUseContentMerge() throws IOException {
|
||||
ProjectConfigInput in = new ProjectConfigInput();
|
||||
in.use_content_merge = InheritableBoolean.TRUE;
|
||||
PutConfig.Input in = new PutConfig.Input();
|
||||
in.useContentMerge = InheritableBoolean.TRUE;
|
||||
RestResponse r = session.put("/projects/" + project.get() + "/config", in);
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
r.consume();
|
||||
@@ -170,9 +168,9 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
||||
|
||||
private void submit(String changeId, int expectedStatus) throws IOException {
|
||||
approve(changeId);
|
||||
RestResponse r =
|
||||
session.post("/changes/" + changeId + "/submit",
|
||||
SubmitInput.waitForMerge());
|
||||
SubmitInput subm = new SubmitInput();
|
||||
subm.waitForMerge = true;
|
||||
RestResponse r = session.post("/changes/" + changeId + "/submit", subm);
|
||||
assertEquals(expectedStatus, r.getStatusCode());
|
||||
if (expectedStatus == HttpStatus.SC_OK) {
|
||||
ChangeInfo change =
|
||||
@@ -290,10 +288,4 @@ public abstract class AbstractSubmit extends AbstractDaemonTest {
|
||||
fmt.flush();
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
private static Gson newGson() {
|
||||
return new GsonBuilder()
|
||||
.registerTypeAdapter(Timestamp.class, new SqlTimestampDeserializer())
|
||||
.create();
|
||||
}
|
||||
}
|
||||
|
@@ -1,21 +0,0 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.rest.change;
|
||||
|
||||
public class AccountInfo {
|
||||
public Integer _account_id;
|
||||
public String name;
|
||||
public String email;
|
||||
}
|
@@ -1,28 +1,16 @@
|
||||
include_defs('//gerrit-acceptance-tests/tests.defs')
|
||||
|
||||
UTIL_SRCS = [
|
||||
'AccountInfo.java',
|
||||
'ChangeInfo.java',
|
||||
'ChangeMessageInfo.java',
|
||||
'GroupInfo.java',
|
||||
'ProjectConfigInput.java',
|
||||
'SubmitInput.java',
|
||||
'SuggestReviewerInfo.java',
|
||||
]
|
||||
|
||||
SUBMIT_UTIL_SRCS = [
|
||||
'AbstractSubmit.java',
|
||||
'AbstractSubmitByMerge.java',
|
||||
]
|
||||
|
||||
NON_TEST = UTIL_SRCS + SUBMIT_UTIL_SRCS
|
||||
SUBMIT_TESTS = glob(['Submit*IT.java'], excludes = NON_TEST)
|
||||
OTHER_TESTS = glob(['*IT.java'], excludes = SUBMIT_TESTS + NON_TEST)
|
||||
SUBMIT_TESTS = glob(['Submit*IT.java'], excludes = SUBMIT_UTIL_SRCS)
|
||||
OTHER_TESTS = glob(['*IT.java'], excludes = SUBMIT_TESTS + SUBMIT_UTIL_SRCS)
|
||||
|
||||
acceptance_tests(
|
||||
srcs = OTHER_TESTS,
|
||||
deps = [
|
||||
':util',
|
||||
'//gerrit-acceptance-tests:lib',
|
||||
],
|
||||
)
|
||||
@@ -39,18 +27,6 @@ java_library(
|
||||
name = 'submit_util',
|
||||
srcs = SUBMIT_UTIL_SRCS,
|
||||
deps = [
|
||||
':util',
|
||||
'//gerrit-acceptance-tests:lib',
|
||||
'//lib:gwtjsonrpc',
|
||||
],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = 'util',
|
||||
srcs = UTIL_SRCS,
|
||||
deps = [
|
||||
'//lib:guava',
|
||||
'//gerrit-reviewdb:server',
|
||||
],
|
||||
visibility = ['//gerrit-acceptance-tests/...'],
|
||||
)
|
||||
|
@@ -1,28 +0,0 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.rest.change;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ChangeInfo {
|
||||
String id;
|
||||
String project;
|
||||
String branch;
|
||||
List<ChangeMessageInfo> messages;
|
||||
Change.Status status;
|
||||
public Boolean starred;
|
||||
}
|
@@ -1,19 +0,0 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.rest.change;
|
||||
|
||||
public class ChangeMessageInfo {
|
||||
String message;
|
||||
}
|
@@ -28,9 +28,11 @@ import com.google.gerrit.acceptance.RestResponse;
|
||||
import com.google.gerrit.acceptance.RestSession;
|
||||
import com.google.gerrit.acceptance.SshSession;
|
||||
import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.extensions.api.changes.ReviewInput;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gerrit.server.change.ChangeJson.ChangeInfo;
|
||||
import com.google.gerrit.server.change.ChangeJson.ChangeMessageInfo;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gwtorm.server.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
@@ -42,6 +44,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class ChangeMessagesIT extends AbstractDaemonTest {
|
||||
@@ -95,7 +98,7 @@ public class ChangeMessagesIT extends AbstractDaemonTest {
|
||||
ChangeInfo c = getChangeWithMessages(changeId);
|
||||
assertNotNull(c.messages);
|
||||
assertEquals(1, c.messages.size());
|
||||
assertEquals("Uploaded patch set 1.", c.messages.get(0).message);
|
||||
assertEquals("Uploaded patch set 1.", c.messages.iterator().next().message);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -109,9 +112,10 @@ public class ChangeMessagesIT extends AbstractDaemonTest {
|
||||
ChangeInfo c = getChangeWithMessages(changeId);
|
||||
assertNotNull(c.messages);
|
||||
assertEquals(3, c.messages.size());
|
||||
assertEquals("Uploaded patch set 1.", c.messages.get(0).message);
|
||||
assertMessage(firstMessage, c.messages.get(1).message);
|
||||
assertMessage(secondMessage, c.messages.get(2).message);
|
||||
Iterator<ChangeMessageInfo> it = c.messages.iterator();
|
||||
assertEquals("Uploaded patch set 1.", it.next().message);
|
||||
assertMessage(firstMessage, it.next().message);
|
||||
assertMessage(secondMessage, it.next().message);
|
||||
}
|
||||
|
||||
private String createChange() throws GitAPIException,
|
||||
@@ -133,7 +137,7 @@ public class ChangeMessagesIT extends AbstractDaemonTest {
|
||||
RestResponse r =
|
||||
session.get("/changes/?q=" + changeId
|
||||
+ (includeMessages ? "&o=MESSAGES" : ""));
|
||||
List<ChangeInfo> c = (new Gson()).fromJson(r.getReader(),
|
||||
List<ChangeInfo> c = newGson().fromJson(r.getReader(),
|
||||
new TypeToken<List<ChangeInfo>>() {}.getType());
|
||||
return c.get(0);
|
||||
}
|
||||
@@ -147,9 +151,4 @@ public class ChangeMessagesIT extends AbstractDaemonTest {
|
||||
in.message = msg;
|
||||
session.post("/changes/" + changeId + "/revisions/1/review", in).consume();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private class ReviewInput {
|
||||
String message;
|
||||
}
|
||||
}
|
||||
|
@@ -33,7 +33,7 @@ import com.google.gerrit.acceptance.SshSession;
|
||||
import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gerrit.server.change.ChangeJson.ChangeInfo;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gwtorm.server.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
@@ -129,7 +129,7 @@ public class ConflictsOperatorIT extends AbstractDaemonTest {
|
||||
session.get("/changes/?q=conflicts:" + change.getChangeId());
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
Set<ChangeInfo> changes =
|
||||
(new Gson()).fromJson(r.getReader(),
|
||||
newGson().fromJson(r.getReader(),
|
||||
new TypeToken<Set<ChangeInfo>>() {}.getType());
|
||||
r.consume();
|
||||
return ImmutableSet.copyOf(Iterables.transform(changes,
|
||||
|
@@ -31,8 +31,7 @@ import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gerrit.server.change.ChangeJson.ChangeInfo;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
@@ -44,7 +43,6 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class DeleteDraftChangeIT extends AbstractDaemonTest {
|
||||
|
||||
@@ -132,10 +130,8 @@ public class DeleteDraftChangeIT extends AbstractDaemonTest {
|
||||
}
|
||||
|
||||
private ChangeInfo getChange(String changeId) throws IOException {
|
||||
RestResponse r = session.get("/changes/?q=" + changeId);
|
||||
List<ChangeInfo> c = (new Gson()).fromJson(r.getReader(),
|
||||
new TypeToken<List<ChangeInfo>>() {}.getType());
|
||||
return c.get(0);
|
||||
RestResponse r = session.get("/changes/" + changeId + "/detail");
|
||||
return newGson().fromJson(r.getReader(), ChangeInfo.class);
|
||||
}
|
||||
|
||||
private String createChange() throws GitAPIException,
|
||||
|
@@ -32,8 +32,7 @@ import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gerrit.server.change.ChangeJson.ChangeInfo;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
@@ -45,7 +44,6 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
public class DeleteDraftPatchSetIT extends AbstractDaemonTest {
|
||||
|
||||
@@ -144,10 +142,8 @@ public class DeleteDraftPatchSetIT extends AbstractDaemonTest {
|
||||
}
|
||||
|
||||
private ChangeInfo getChange(String changeId) throws IOException {
|
||||
RestResponse r = session.get("/changes/?q=" + changeId);
|
||||
List<ChangeInfo> c = (new Gson()).fromJson(r.getReader(),
|
||||
new TypeToken<List<ChangeInfo>>() {}.getType());
|
||||
return c.get(0);
|
||||
RestResponse r = session.get("/changes/" + changeId + "/detail");
|
||||
return newGson().fromJson(r.getReader(), ChangeInfo.class);
|
||||
}
|
||||
|
||||
private PatchSet getCurrentPatchSet(String changeId) throws OrmException {
|
||||
|
@@ -1,20 +0,0 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.rest.change;
|
||||
|
||||
public class GroupInfo {
|
||||
public String id;
|
||||
public String name;
|
||||
}
|
@@ -1,23 +0,0 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.rest.change;
|
||||
|
||||
import com.google.gerrit.reviewdb.client.Project.InheritableBoolean;
|
||||
import com.google.gerrit.reviewdb.client.Project.SubmitType;
|
||||
|
||||
public class ProjectConfigInput {
|
||||
public SubmitType submit_type;
|
||||
public InheritableBoolean use_content_merge;
|
||||
}
|
@@ -1,25 +0,0 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.rest.change;
|
||||
|
||||
public class SubmitInput {
|
||||
boolean wait_for_merge;
|
||||
|
||||
public static SubmitInput waitForMerge() {
|
||||
SubmitInput in = new SubmitInput();
|
||||
in.wait_for_merge = true;
|
||||
return in;
|
||||
}
|
||||
}
|
@@ -1,20 +0,0 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.rest.change;
|
||||
|
||||
public class SuggestReviewerInfo {
|
||||
public AccountInfo account;
|
||||
public GroupInfo group;
|
||||
}
|
@@ -29,7 +29,7 @@ import com.google.gerrit.acceptance.SshSession;
|
||||
import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gerrit.server.change.SuggestReviewers.SuggestedReviewerInfo;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gwtorm.server.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
@@ -92,7 +92,7 @@ public class SuggestReviewersIT extends AbstractDaemonTest {
|
||||
public void suggestReviewersNoResult1() throws GitAPIException, IOException,
|
||||
Exception {
|
||||
String changeId = createChange(admin);
|
||||
List<SuggestReviewerInfo> reviewers = suggestReviewers(changeId, "u", 6);
|
||||
List<SuggestedReviewerInfo> reviewers = suggestReviewers(changeId, "u", 6);
|
||||
assertEquals(reviewers.size(), 0);
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ public class SuggestReviewersIT extends AbstractDaemonTest {
|
||||
public void suggestReviewersNoResult2() throws GitAPIException, IOException,
|
||||
Exception {
|
||||
String changeId = createChange(admin);
|
||||
List<SuggestReviewerInfo> reviewers = suggestReviewers(changeId, "u", 6);
|
||||
List<SuggestedReviewerInfo> reviewers = suggestReviewers(changeId, "u", 6);
|
||||
assertEquals(reviewers.size(), 0);
|
||||
}
|
||||
|
||||
@@ -114,7 +114,7 @@ public class SuggestReviewersIT extends AbstractDaemonTest {
|
||||
public void suggestReviewersNoResult3() throws GitAPIException, IOException,
|
||||
Exception {
|
||||
String changeId = createChange(admin);
|
||||
List<SuggestReviewerInfo> reviewers = suggestReviewers(changeId, "u", 6);
|
||||
List<SuggestedReviewerInfo> reviewers = suggestReviewers(changeId, "u", 6);
|
||||
assertEquals(reviewers.size(), 0);
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ public class SuggestReviewersIT extends AbstractDaemonTest {
|
||||
public void suggestReviewersChange() throws GitAPIException,
|
||||
IOException, Exception {
|
||||
String changeId = createChange(admin);
|
||||
List<SuggestReviewerInfo> reviewers = suggestReviewers(changeId, "u", 6);
|
||||
List<SuggestedReviewerInfo> reviewers = suggestReviewers(changeId, "u", 6);
|
||||
assertEquals(reviewers.size(), 6);
|
||||
reviewers = suggestReviewers(changeId, "u", 5);
|
||||
assertEquals(reviewers.size(), 5);
|
||||
@@ -130,10 +130,10 @@ public class SuggestReviewersIT extends AbstractDaemonTest {
|
||||
assertEquals(reviewers.size(), 1);
|
||||
}
|
||||
|
||||
private List<SuggestReviewerInfo> suggestReviewers(String changeId,
|
||||
private List<SuggestedReviewerInfo> suggestReviewers(String changeId,
|
||||
String query, int n)
|
||||
throws IOException {
|
||||
return new Gson().fromJson(
|
||||
return newGson().fromJson(
|
||||
session.get("/changes/"
|
||||
+ changeId
|
||||
+ "/suggest_reviewers?q="
|
||||
@@ -141,7 +141,7 @@ public class SuggestReviewersIT extends AbstractDaemonTest {
|
||||
+ "&n="
|
||||
+ n)
|
||||
.getReader(),
|
||||
new TypeToken<List<SuggestReviewerInfo>>() {}
|
||||
new TypeToken<List<SuggestedReviewerInfo>>() {}
|
||||
.getType());
|
||||
}
|
||||
|
||||
|
@@ -29,14 +29,17 @@ import com.google.gerrit.acceptance.AccountCreator;
|
||||
import com.google.gerrit.acceptance.RestResponse;
|
||||
import com.google.gerrit.acceptance.RestSession;
|
||||
import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.acceptance.rest.account.AccountInfo;
|
||||
import com.google.gerrit.reviewdb.client.Account;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroupById;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroupMember;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.account.AccountInfo;
|
||||
import com.google.gerrit.server.account.GroupCache;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gerrit.server.group.AddIncludedGroups;
|
||||
import com.google.gerrit.server.group.AddMembers;
|
||||
import com.google.gerrit.server.group.CreateGroup;
|
||||
import com.google.gerrit.server.group.GroupJson.GroupInfo;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.ResultSet;
|
||||
@@ -98,8 +101,7 @@ public class AddRemoveGroupMembersIT extends AbstractDaemonTest {
|
||||
TestAccount u = accounts.create("user", "user@example.com", "Full Name");
|
||||
RestResponse r = PUT("/groups/Administrators/members/user");
|
||||
assertEquals(HttpStatus.SC_CREATED, r.getStatusCode());
|
||||
AccountInfo ai = (new Gson()).fromJson(r.getReader(),
|
||||
new TypeToken<AccountInfo>() {}.getType());
|
||||
AccountInfo ai = newGson().fromJson(r.getReader(), AccountInfo.class);
|
||||
assertAccountInfo(u, ai);
|
||||
assertMembers("Administrators", admin, u);
|
||||
r.consume();
|
||||
@@ -120,12 +122,12 @@ public class AddRemoveGroupMembersIT extends AbstractDaemonTest {
|
||||
group("users");
|
||||
TestAccount u1 = accounts.create("u1", "u1@example.com", "Full Name 1");
|
||||
TestAccount u2 = accounts.create("u2", "u2@example.com", "Full Name 2");
|
||||
MembersInput input = new MembersInput();
|
||||
input.members = Lists.newLinkedList();
|
||||
input.members.add(u1.username);
|
||||
input.members.add(u2.username);
|
||||
List<String> members = Lists.newLinkedList();
|
||||
members.add(u1.username);
|
||||
members.add(u2.username);
|
||||
AddMembers.Input input = AddMembers.Input.fromMembers(members);
|
||||
RestResponse r = POST("/groups/users/members", input);
|
||||
List<AccountInfo> ai = (new Gson()).fromJson(r.getReader(),
|
||||
List<AccountInfo> ai = newGson().fromJson(r.getReader(),
|
||||
new TypeToken<List<AccountInfo>>() {}.getType());
|
||||
assertMembers(ai, u1, u2);
|
||||
}
|
||||
@@ -135,7 +137,7 @@ public class AddRemoveGroupMembersIT extends AbstractDaemonTest {
|
||||
group("newGroup");
|
||||
RestResponse r = PUT("/groups/Administrators/groups/newGroup");
|
||||
assertEquals(HttpStatus.SC_CREATED, r.getStatusCode());
|
||||
GroupInfo i = (new Gson()).fromJson(r.getReader(), new TypeToken<GroupInfo>() {}.getType());
|
||||
GroupInfo i = newGson().fromJson(r.getReader(), GroupInfo.class);
|
||||
r.consume();
|
||||
assertGroupInfo(groupCache.get(new AccountGroup.NameKey("newGroup")), i);
|
||||
assertIncludes("Administrators", "newGroup");
|
||||
@@ -157,12 +159,12 @@ public class AddRemoveGroupMembersIT extends AbstractDaemonTest {
|
||||
public void addMultipleIncludes() throws Exception {
|
||||
group("newGroup1");
|
||||
group("newGroup2");
|
||||
GroupsInput input = new GroupsInput();
|
||||
input.groups = Lists.newLinkedList();
|
||||
input.groups.add("newGroup1");
|
||||
input.groups.add("newGroup2");
|
||||
List<String> groups = Lists.newLinkedList();
|
||||
groups.add("newGroup1");
|
||||
groups.add("newGroup2");
|
||||
AddIncludedGroups.Input input = AddIncludedGroups.Input.fromGroups(groups);
|
||||
RestResponse r = POST("/groups/Administrators/groups", input);
|
||||
List<GroupInfo> gi = (new Gson()).fromJson(r.getReader(),
|
||||
List<GroupInfo> gi = newGson().fromJson(r.getReader(),
|
||||
new TypeToken<List<GroupInfo>>() {}.getType());
|
||||
assertIncludes(gi, "newGroup1", "newGroup2");
|
||||
}
|
||||
@@ -177,16 +179,18 @@ public class AddRemoveGroupMembersIT extends AbstractDaemonTest {
|
||||
return r.getStatusCode();
|
||||
}
|
||||
|
||||
private RestResponse POST(String endPoint, MembersInput mi) throws IOException {
|
||||
private RestResponse POST(String endPoint, AddMembers.Input mi)
|
||||
throws IOException {
|
||||
return session.post(endPoint, mi);
|
||||
}
|
||||
|
||||
private RestResponse POST(String endPoint, GroupsInput gi) throws IOException {
|
||||
private RestResponse POST(String endPoint, AddIncludedGroups.Input gi)
|
||||
throws IOException {
|
||||
return session.post(endPoint, gi);
|
||||
}
|
||||
|
||||
private void group(String name) throws IOException {
|
||||
GroupInput in = new GroupInput();
|
||||
CreateGroup.Input in = new CreateGroup.Input();
|
||||
session.put("/groups/" + name, in).consume();
|
||||
}
|
||||
|
||||
|
@@ -10,17 +10,11 @@ acceptance_tests(
|
||||
|
||||
java_library(
|
||||
name = 'util',
|
||||
srcs = [
|
||||
'GroupAssert.java',
|
||||
'GroupInfo.java',
|
||||
'GroupInput.java',
|
||||
'GroupOptionsInfo.java',
|
||||
'GroupsInput.java',
|
||||
'MembersInput.java',
|
||||
],
|
||||
srcs = ['GroupAssert.java'],
|
||||
deps = [
|
||||
'//gerrit-extension-api:api',
|
||||
'//gerrit-reviewdb:server',
|
||||
'//gerrit-server:server',
|
||||
'//lib:gwtorm',
|
||||
'//lib:junit',
|
||||
],
|
||||
|
@@ -15,7 +15,6 @@
|
||||
package com.google.gerrit.acceptance.rest.group;
|
||||
|
||||
import static com.google.gerrit.acceptance.rest.group.GroupAssert.assertGroupInfo;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
@@ -26,8 +25,8 @@ import com.google.gerrit.acceptance.RestSession;
|
||||
import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.server.account.GroupCache;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gerrit.server.group.CreateGroup;
|
||||
import com.google.gerrit.server.group.GroupJson.GroupInfo;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
@@ -61,7 +60,7 @@ public class CreateGroupIT extends AbstractDaemonTest {
|
||||
public void testCreateGroup() throws IOException {
|
||||
final String newGroupName = "newGroup";
|
||||
RestResponse r = session.put("/groups/" + newGroupName);
|
||||
GroupInfo g = (new Gson()).fromJson(r.getReader(), new TypeToken<GroupInfo>() {}.getType());
|
||||
GroupInfo g = newGson().fromJson(r.getReader(), GroupInfo.class);
|
||||
assertEquals(newGroupName, g.name);
|
||||
AccountGroup group = groupCache.get(new AccountGroup.NameKey(newGroupName));
|
||||
assertNotNull(group);
|
||||
@@ -71,17 +70,17 @@ public class CreateGroupIT extends AbstractDaemonTest {
|
||||
@Test
|
||||
public void testCreateGroupWithProperties() throws IOException {
|
||||
final String newGroupName = "newGroup";
|
||||
GroupInput in = new GroupInput();
|
||||
CreateGroup.Input in = new CreateGroup.Input();
|
||||
in.description = "Test description";
|
||||
in.visible_to_all = true;
|
||||
in.owner_id = groupCache.get(new AccountGroup.NameKey("Administrators")).getGroupUUID().get();
|
||||
in.visibleToAll = true;
|
||||
in.ownerId = groupCache.get(new AccountGroup.NameKey("Administrators")).getGroupUUID().get();
|
||||
RestResponse r = session.put("/groups/" + newGroupName, in);
|
||||
GroupInfo g = (new Gson()).fromJson(r.getReader(), new TypeToken<GroupInfo>() {}.getType());
|
||||
GroupInfo g = newGson().fromJson(r.getReader(), GroupInfo.class);
|
||||
assertEquals(newGroupName, g.name);
|
||||
AccountGroup group = groupCache.get(new AccountGroup.NameKey(newGroupName));
|
||||
assertEquals(in.description, group.getDescription());
|
||||
assertEquals(in.visible_to_all, group.isVisibleToAll());
|
||||
assertEquals(in.owner_id, group.getOwnerGroupUUID().get());
|
||||
assertEquals(in.visibleToAll, group.isVisibleToAll());
|
||||
assertEquals(in.ownerId, group.getOwnerGroupUUID().get());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -25,7 +25,7 @@ import com.google.gerrit.acceptance.SshSession;
|
||||
import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gerrit.server.group.GroupJson.GroupInfo;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.SchemaFactory;
|
||||
@@ -76,9 +76,9 @@ public class DefaultGroupsIT extends AbstractDaemonTest {
|
||||
public void defaultGroupsCreated_rest() throws IOException {
|
||||
RestSession session = new RestSession(server, admin);
|
||||
RestResponse r = session.get("/groups/");
|
||||
Gson gson = new Gson();
|
||||
Map<String, GroupInfo> result =
|
||||
gson.fromJson(r.getReader(), new TypeToken<Map<String, GroupInfo>>() {}.getType());
|
||||
newGson().fromJson(r.getReader(),
|
||||
new TypeToken<Map<String, GroupInfo>>() {}.getType());
|
||||
Set<String> names = result.keySet();
|
||||
assertTrue(names.contains("Administrators"));
|
||||
assertTrue(names.contains("Non-Interactive Users"));
|
||||
|
@@ -23,7 +23,7 @@ import com.google.gerrit.acceptance.RestSession;
|
||||
import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.server.account.GroupCache;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gerrit.server.group.GroupJson.GroupInfo;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
@@ -64,9 +64,10 @@ public class GetGroupIT extends AbstractDaemonTest {
|
||||
testGetGroup("/groups/" + adminGroup.getId().get(), adminGroup);
|
||||
}
|
||||
|
||||
private void testGetGroup(String url, AccountGroup expectedGroup) throws IOException {
|
||||
private void testGetGroup(String url, AccountGroup expectedGroup)
|
||||
throws IOException {
|
||||
RestResponse r = session.get(url);
|
||||
GroupInfo group = (new Gson()).fromJson(r.getReader(), new TypeToken<GroupInfo>() {}.getType());
|
||||
GroupInfo group = newGson().fromJson(r.getReader(), GroupInfo.class);
|
||||
assertGroupInfo(expectedGroup, group);
|
||||
}
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ import static org.junit.Assert.assertTrue;
|
||||
|
||||
import com.google.gerrit.extensions.restapi.Url;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.server.group.GroupJson.GroupInfo;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@@ -37,11 +38,11 @@ public class GroupAssert {
|
||||
assertEquals(group.getName(), info.name);
|
||||
}
|
||||
assertEquals(group.getGroupUUID().get(), Url.decode(info.id));
|
||||
assertEquals(Integer.valueOf(group.getId().get()), info.group_id);
|
||||
assertEquals(Integer.valueOf(group.getId().get()), info.groupId);
|
||||
assertEquals("#/admin/groups/uuid-" + Url.encode(group.getGroupUUID().get()), info.url);
|
||||
assertEquals(group.isVisibleToAll(), toBoolean(info.options.visible_to_all));
|
||||
assertEquals(group.isVisibleToAll(), toBoolean(info.options.visibleToAll));
|
||||
assertEquals(group.getDescription(), info.description);
|
||||
assertEquals(group.getOwnerGroupUUID().get(), Url.decode(info.owner_id));
|
||||
assertEquals(group.getOwnerGroupUUID().get(), Url.decode(info.ownerId));
|
||||
}
|
||||
|
||||
public static boolean toBoolean(Boolean b) {
|
||||
|
@@ -1,25 +0,0 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.rest.group;
|
||||
|
||||
public class GroupInfo {
|
||||
public String id;
|
||||
public String name;
|
||||
public String url;
|
||||
public GroupOptionsInfo options;
|
||||
public String description;
|
||||
public Integer group_id;
|
||||
public String owner_id;
|
||||
}
|
@@ -1,21 +0,0 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.rest.group;
|
||||
|
||||
public class GroupInput {
|
||||
String description;
|
||||
Boolean visible_to_all;
|
||||
String owner_id;
|
||||
}
|
@@ -1,19 +0,0 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.rest.group;
|
||||
|
||||
public class GroupOptionsInfo {
|
||||
public Boolean visible_to_all;
|
||||
}
|
@@ -28,9 +28,13 @@ import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.extensions.restapi.Url;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.server.account.GroupCache;
|
||||
import com.google.gerrit.server.group.GroupJson.GroupInfo;
|
||||
import com.google.gerrit.server.group.GroupOptionsInfo;
|
||||
import com.google.gerrit.server.group.PutDescription;
|
||||
import com.google.gerrit.server.group.PutName;
|
||||
import com.google.gerrit.server.group.PutOptions;
|
||||
import com.google.gerrit.server.group.PutOwner;
|
||||
import com.google.gerrit.server.group.SystemGroupBackend;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import org.apache.http.HttpStatus;
|
||||
@@ -64,7 +68,7 @@ public class GroupPropertiesIT extends AbstractDaemonTest {
|
||||
|
||||
// get name
|
||||
RestResponse r = session.get(url);
|
||||
String name = (new Gson()).fromJson(r.getReader(), new TypeToken<String>() {}.getType());
|
||||
String name = newGson().fromJson(r.getReader(), String.class);
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
assertEquals("Administrators", name);
|
||||
r.consume();
|
||||
@@ -74,24 +78,24 @@ public class GroupPropertiesIT extends AbstractDaemonTest {
|
||||
r = session.put("/groups/" + newGroupName);
|
||||
r.consume();
|
||||
assertEquals(HttpStatus.SC_CREATED, r.getStatusCode());
|
||||
GroupNameInput in = new GroupNameInput();
|
||||
PutName.Input in = new PutName.Input();
|
||||
in.name = newGroupName;
|
||||
r = session.put(url, in);
|
||||
assertEquals(HttpStatus.SC_CONFLICT, r.getStatusCode());
|
||||
r.consume();
|
||||
|
||||
// set name to same name
|
||||
in = new GroupNameInput();
|
||||
in = new PutName.Input();
|
||||
in.name = "Administrators";
|
||||
r = session.put(url, in);
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
r.consume();
|
||||
|
||||
// rename
|
||||
in = new GroupNameInput();
|
||||
in = new PutName.Input();
|
||||
in.name = "Admins";
|
||||
r = session.put(url, in);
|
||||
String newName = (new Gson()).fromJson(r.getReader(), new TypeToken<String>() {}.getType());
|
||||
String newName = newGson().fromJson(r.getReader(), String.class);
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
assertNotNull(groupCache.get(new AccountGroup.NameKey(in.name)));
|
||||
assertNull(groupCache.get(adminGroupName));
|
||||
@@ -107,16 +111,16 @@ public class GroupPropertiesIT extends AbstractDaemonTest {
|
||||
|
||||
// get description
|
||||
RestResponse r = session.get(url);
|
||||
String description = (new Gson()).fromJson(r.getReader(), new TypeToken<String>() {}.getType());
|
||||
String description = newGson().fromJson(r.getReader(), String.class);
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
assertEquals(adminGroup.getDescription(), description);
|
||||
r.consume();
|
||||
|
||||
// set description
|
||||
GroupDescriptionInput in = new GroupDescriptionInput();
|
||||
PutDescription.Input in = new PutDescription.Input();
|
||||
in.description = "All users that can administrate the Gerrit Server.";
|
||||
r = session.put(url, in);
|
||||
String newDescription = (new Gson()).fromJson(r.getReader(), new TypeToken<String>() {}.getType());
|
||||
String newDescription = newGson().fromJson(r.getReader(), String.class);
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
assertEquals(in.description, newDescription);
|
||||
adminGroup = groupCache.get(adminGroupName);
|
||||
@@ -130,7 +134,7 @@ public class GroupPropertiesIT extends AbstractDaemonTest {
|
||||
assertNull(adminGroup.getDescription());
|
||||
|
||||
// set description to empty string
|
||||
in = new GroupDescriptionInput();
|
||||
in = new PutDescription.Input();
|
||||
in.description = "";
|
||||
r = session.put(url, in);
|
||||
assertEquals(HttpStatus.SC_NO_CONTENT, r.getStatusCode());
|
||||
@@ -146,20 +150,20 @@ public class GroupPropertiesIT extends AbstractDaemonTest {
|
||||
|
||||
// get options
|
||||
RestResponse r = session.get(url);
|
||||
GroupOptionsInfo options = (new Gson()).fromJson(r.getReader(), new TypeToken<GroupOptionsInfo>() {}.getType());
|
||||
GroupOptionsInfo options = newGson().fromJson(r.getReader(), GroupOptionsInfo.class);
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
assertEquals(adminGroup.isVisibleToAll(), toBoolean(options.visible_to_all));
|
||||
assertEquals(adminGroup.isVisibleToAll(), toBoolean(options.visibleToAll));
|
||||
r.consume();
|
||||
|
||||
// set options
|
||||
GroupOptionsInput in = new GroupOptionsInput();
|
||||
in.visible_to_all = !adminGroup.isVisibleToAll();
|
||||
PutOptions.Input in = new PutOptions.Input();
|
||||
in.visibleToAll = !adminGroup.isVisibleToAll();
|
||||
r = session.put(url, in);
|
||||
GroupOptionsInfo newOptions = (new Gson()).fromJson(r.getReader(), new TypeToken<GroupOptionsInfo>() {}.getType());
|
||||
GroupOptionsInfo newOptions = newGson().fromJson(r.getReader(), GroupOptionsInfo.class);
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
assertEquals(in.visible_to_all, toBoolean(newOptions.visible_to_all));
|
||||
assertEquals(in.visibleToAll, toBoolean(newOptions.visibleToAll));
|
||||
adminGroup = groupCache.get(adminGroupName);
|
||||
assertEquals(in.visible_to_all, adminGroup.isVisibleToAll());
|
||||
assertEquals(in.visibleToAll, adminGroup.isVisibleToAll());
|
||||
r.consume();
|
||||
}
|
||||
|
||||
@@ -171,16 +175,16 @@ public class GroupPropertiesIT extends AbstractDaemonTest {
|
||||
|
||||
// get owner
|
||||
RestResponse r = session.get(url);
|
||||
GroupInfo options = (new Gson()).fromJson(r.getReader(), new TypeToken<GroupInfo>() {}.getType());
|
||||
GroupInfo options = newGson().fromJson(r.getReader(), GroupInfo.class);
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
assertGroupInfo(groupCache.get(adminGroup.getOwnerGroupUUID()), options);
|
||||
r.consume();
|
||||
|
||||
// set owner by name
|
||||
GroupOwnerInput in = new GroupOwnerInput();
|
||||
PutOwner.Input in = new PutOwner.Input();
|
||||
in.owner = "Registered Users";
|
||||
r = session.put(url, in);
|
||||
GroupInfo newOwner = (new Gson()).fromJson(r.getReader(), new TypeToken<GroupInfo>() {}.getType());
|
||||
GroupInfo newOwner = newGson().fromJson(r.getReader(), GroupInfo.class);
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
assertEquals(in.owner, newOwner.name);
|
||||
assertEquals(
|
||||
@@ -192,7 +196,7 @@ public class GroupPropertiesIT extends AbstractDaemonTest {
|
||||
r.consume();
|
||||
|
||||
// set owner by UUID
|
||||
in = new GroupOwnerInput();
|
||||
in = new PutOwner.Input();
|
||||
in.owner = adminGroup.getGroupUUID().get();
|
||||
r = session.put(url, in);
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
@@ -201,26 +205,10 @@ public class GroupPropertiesIT extends AbstractDaemonTest {
|
||||
r.consume();
|
||||
|
||||
// set non existing owner
|
||||
in = new GroupOwnerInput();
|
||||
in = new PutOwner.Input();
|
||||
in.owner = "Non-Existing Group";
|
||||
r = session.put(url, in);
|
||||
assertEquals(HttpStatus.SC_UNPROCESSABLE_ENTITY, r.getStatusCode());
|
||||
r.consume();
|
||||
}
|
||||
|
||||
private static class GroupNameInput {
|
||||
String name;
|
||||
}
|
||||
|
||||
private static class GroupDescriptionInput {
|
||||
String description;
|
||||
}
|
||||
|
||||
private static class GroupOptionsInput {
|
||||
Boolean visible_to_all;
|
||||
}
|
||||
|
||||
private static class GroupOwnerInput {
|
||||
String owner;
|
||||
}
|
||||
}
|
||||
|
@@ -1,21 +0,0 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.rest.group;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class GroupsInput {
|
||||
List<String> groups;
|
||||
}
|
@@ -25,7 +25,8 @@ import com.google.gerrit.acceptance.RestResponse;
|
||||
import com.google.gerrit.acceptance.RestSession;
|
||||
import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gerrit.server.group.CreateGroup;
|
||||
import com.google.gerrit.server.group.GroupJson.GroupInfo;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
@@ -84,15 +85,14 @@ public class ListGroupIncludesIT extends AbstractDaemonTest {
|
||||
private List<GroupInfo> GET(String endpoint) throws IOException {
|
||||
RestResponse r = session.get(endpoint);
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
return (new Gson()).fromJson(r.getReader(),
|
||||
return newGson().fromJson(r.getReader(),
|
||||
new TypeToken<List<GroupInfo>>() {}.getType());
|
||||
}
|
||||
|
||||
private GroupInfo GET_ONE(String endpoint) throws IOException {
|
||||
RestResponse r = session.get(endpoint);
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
return (new Gson()).fromJson(r.getReader(),
|
||||
new TypeToken<GroupInfo>() {}.getType());
|
||||
return newGson().fromJson(r.getReader(), GroupInfo.class);
|
||||
}
|
||||
|
||||
private void PUT(String endpoint) throws IOException {
|
||||
@@ -100,8 +100,8 @@ public class ListGroupIncludesIT extends AbstractDaemonTest {
|
||||
}
|
||||
|
||||
private void group(String name, String ownerGroup) throws IOException {
|
||||
GroupInput in = new GroupInput();
|
||||
in.owner_id = ownerGroup;
|
||||
CreateGroup.Input in = new CreateGroup.Input();
|
||||
in.ownerId = ownerGroup;
|
||||
session.put("/groups/" + name, in).consume();
|
||||
}
|
||||
|
||||
|
@@ -24,9 +24,9 @@ import com.google.gerrit.acceptance.AccountCreator;
|
||||
import com.google.gerrit.acceptance.RestResponse;
|
||||
import com.google.gerrit.acceptance.RestSession;
|
||||
import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.acceptance.rest.account.AccountInfo;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gerrit.server.account.AccountInfo;
|
||||
import com.google.gerrit.server.group.CreateGroup;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
@@ -94,15 +94,14 @@ public class ListGroupMembersIT extends AbstractDaemonTest {
|
||||
private List<AccountInfo> GET(String endpoint) throws IOException {
|
||||
RestResponse r = session.get(endpoint);
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
return (new Gson()).fromJson(r.getReader(),
|
||||
return newGson().fromJson(r.getReader(),
|
||||
new TypeToken<List<AccountInfo>>() {}.getType());
|
||||
}
|
||||
|
||||
private AccountInfo GET_ONE(String endpoint) throws IOException {
|
||||
RestResponse r = session.get(endpoint);
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
return (new Gson()).fromJson(r.getReader(),
|
||||
new TypeToken<AccountInfo>() {}.getType());
|
||||
return newGson().fromJson(r.getReader(), AccountInfo.class);
|
||||
}
|
||||
|
||||
private void PUT(String endpoint) throws IOException {
|
||||
@@ -111,8 +110,8 @@ public class ListGroupMembersIT extends AbstractDaemonTest {
|
||||
|
||||
private void group(String name, String ownerGroup)
|
||||
throws IOException {
|
||||
GroupInput in = new GroupInput();
|
||||
in.owner_id = ownerGroup;
|
||||
CreateGroup.Input in = new CreateGroup.Input();
|
||||
in.ownerId = ownerGroup;
|
||||
session.put("/groups/" + name, in).consume();
|
||||
}
|
||||
|
||||
|
@@ -30,7 +30,8 @@ import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.common.Nullable;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.server.account.GroupCache;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gerrit.server.group.CreateGroup;
|
||||
import com.google.gerrit.server.group.GroupJson.GroupInfo;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
@@ -75,7 +76,8 @@ public class ListGroupsIT extends AbstractDaemonTest {
|
||||
});
|
||||
RestResponse r = session.get("/groups/");
|
||||
Map<String, GroupInfo> result =
|
||||
(new Gson()).fromJson(r.getReader(), new TypeToken<Map<String, GroupInfo>>() {}.getType());
|
||||
newGson().fromJson(r.getReader(),
|
||||
new TypeToken<Map<String, GroupInfo>>() {}.getType());
|
||||
assertGroups(expectedGroups, result.keySet());
|
||||
}
|
||||
|
||||
@@ -86,17 +88,18 @@ public class ListGroupsIT extends AbstractDaemonTest {
|
||||
RestSession userSession = new RestSession(server, user);
|
||||
|
||||
String newGroupName = "newGroup";
|
||||
GroupInput in = new GroupInput();
|
||||
CreateGroup.Input in = new CreateGroup.Input();
|
||||
in.description = "a hidden group";
|
||||
in.visible_to_all = false;
|
||||
in.owner_id = groupCache.get(new AccountGroup.NameKey("Administrators"))
|
||||
in.visibleToAll = false;
|
||||
in.ownerId = groupCache.get(new AccountGroup.NameKey("Administrators"))
|
||||
.getGroupUUID().get();
|
||||
session.put("/groups/" + newGroupName, in).consume();
|
||||
|
||||
Set<String> expectedGroups = Sets.newHashSet(newGroupName);
|
||||
RestResponse r = userSession.get("/groups/");
|
||||
Map<String, GroupInfo> result =
|
||||
(new Gson()).fromJson(r.getReader(), new TypeToken<Map<String, GroupInfo>>() {}.getType());
|
||||
newGson().fromJson(r.getReader(),
|
||||
new TypeToken<Map<String, GroupInfo>>() {}.getType());
|
||||
assertTrue("no groups visible", result.isEmpty());
|
||||
|
||||
assertEquals(HttpStatus.SC_CREATED, session.put(
|
||||
@@ -104,7 +107,8 @@ public class ListGroupsIT extends AbstractDaemonTest {
|
||||
).getStatusCode());
|
||||
|
||||
r = userSession.get("/groups/");
|
||||
result = (new Gson()).fromJson(r.getReader(), new TypeToken<Map<String, GroupInfo>>() {}.getType());
|
||||
result = newGson().fromJson(r.getReader(),
|
||||
new TypeToken<Map<String, GroupInfo>>() {}.getType());
|
||||
assertGroups(expectedGroups, result.keySet());
|
||||
}
|
||||
|
||||
@@ -114,7 +118,8 @@ public class ListGroupsIT extends AbstractDaemonTest {
|
||||
AccountGroup adminGroup = groupCache.get(new AccountGroup.NameKey("Administrators"));
|
||||
RestResponse r = session.get("/groups/?q=" + adminGroup.getName());
|
||||
Map<String, GroupInfo> result =
|
||||
(new Gson()).fromJson(r.getReader(), new TypeToken<Map<String, GroupInfo>>() {}.getType());
|
||||
newGson().fromJson(r.getReader(),
|
||||
new TypeToken<Map<String, GroupInfo>>() {}.getType());
|
||||
GroupInfo adminGroupInfo = result.get(adminGroup.getName());
|
||||
assertGroupInfo(adminGroup, adminGroupInfo);
|
||||
}
|
||||
|
@@ -1,21 +0,0 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.rest.group;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MembersInput {
|
||||
List<String> members;
|
||||
}
|
@@ -13,11 +13,11 @@ java_library(
|
||||
name = 'branch',
|
||||
srcs = [
|
||||
'BranchAssert.java',
|
||||
'BranchInfo.java',
|
||||
],
|
||||
deps = [
|
||||
'//lib:guava',
|
||||
'//lib:junit',
|
||||
'//gerrit-server:server',
|
||||
],
|
||||
)
|
||||
|
||||
@@ -25,7 +25,6 @@ java_library(
|
||||
name = 'project',
|
||||
srcs = [
|
||||
'ProjectAssert.java',
|
||||
'ProjectInfo.java',
|
||||
],
|
||||
deps = [
|
||||
'//gerrit-extension-api:api',
|
||||
|
@@ -21,6 +21,7 @@ import static org.junit.Assert.assertTrue;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.gerrit.server.project.ListBranches.BranchInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -50,7 +51,7 @@ public class BranchAssert {
|
||||
if (expected.revision != null) {
|
||||
assertEquals(expected.revision, actual.revision);
|
||||
}
|
||||
assertEquals(expected.can_delete, toBoolean(actual.can_delete));
|
||||
assertEquals(expected.canDelete, toBoolean(actual.canDelete));
|
||||
}
|
||||
|
||||
private static boolean toBoolean(Boolean b) {
|
||||
|
@@ -1,35 +0,0 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.rest.project;
|
||||
|
||||
public class BranchInfo {
|
||||
public String ref;
|
||||
public String revision;
|
||||
public Boolean can_delete;
|
||||
|
||||
public BranchInfo() {
|
||||
}
|
||||
|
||||
public BranchInfo(String ref, String revision, boolean canDelete) {
|
||||
this.ref = ref;
|
||||
this.revision = revision;
|
||||
this.can_delete = canDelete;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ref;
|
||||
}
|
||||
}
|
@@ -29,16 +29,16 @@ import com.google.gerrit.acceptance.RestSession;
|
||||
import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
import com.google.gerrit.reviewdb.client.Project.InheritableBoolean;
|
||||
import com.google.gerrit.reviewdb.client.Project.SubmitType;
|
||||
import com.google.gerrit.reviewdb.client.RefNames;
|
||||
import com.google.gerrit.server.account.GroupCache;
|
||||
import com.google.gerrit.server.git.GitRepositoryManager;
|
||||
import com.google.gerrit.server.group.SystemGroupBackend;
|
||||
import com.google.gerrit.server.project.CreateProject;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
import com.google.gerrit.server.project.ProjectJson.ProjectInfo;
|
||||
import com.google.gerrit.server.project.ProjectState;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
@@ -56,7 +56,6 @@ import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class CreateProjectIT extends AbstractDaemonTest {
|
||||
@@ -88,7 +87,7 @@ public class CreateProjectIT extends AbstractDaemonTest {
|
||||
final String newProjectName = "newProject";
|
||||
RestResponse r = session.put("/projects/" + newProjectName);
|
||||
assertEquals(HttpStatus.SC_CREATED, r.getStatusCode());
|
||||
ProjectInfo p = (new Gson()).fromJson(r.getReader(), new TypeToken<ProjectInfo>() {}.getType());
|
||||
ProjectInfo p = newGson().fromJson(r.getReader(), ProjectInfo.class);
|
||||
assertEquals(newProjectName, p.name);
|
||||
ProjectState projectState = projectCache.get(new Project.NameKey(newProjectName));
|
||||
assertNotNull(projectState);
|
||||
@@ -98,7 +97,7 @@ public class CreateProjectIT extends AbstractDaemonTest {
|
||||
|
||||
@Test
|
||||
public void testCreateProjectWithNameMismatch_BadRequest() throws IOException {
|
||||
ProjectInput in = new ProjectInput();
|
||||
CreateProject.Input in = new CreateProject.Input();
|
||||
in.name = "otherName";
|
||||
RestResponse r = session.put("/projects/someName", in);
|
||||
assertEquals(HttpStatus.SC_BAD_REQUEST, r.getStatusCode());
|
||||
@@ -107,24 +106,24 @@ public class CreateProjectIT extends AbstractDaemonTest {
|
||||
@Test
|
||||
public void testCreateProjectWithProperties() throws IOException {
|
||||
final String newProjectName = "newProject";
|
||||
ProjectInput in = new ProjectInput();
|
||||
CreateProject.Input in = new CreateProject.Input();
|
||||
in.description = "Test description";
|
||||
in.submit_type = SubmitType.CHERRY_PICK;
|
||||
in.use_contributor_agreements = InheritableBoolean.TRUE;
|
||||
in.use_signed_off_by = InheritableBoolean.TRUE;
|
||||
in.use_content_merge = InheritableBoolean.TRUE;
|
||||
in.require_change_id = InheritableBoolean.TRUE;
|
||||
in.submitType = SubmitType.CHERRY_PICK;
|
||||
in.useContributorAgreements = InheritableBoolean.TRUE;
|
||||
in.useSignedOffBy = InheritableBoolean.TRUE;
|
||||
in.useContentMerge = InheritableBoolean.TRUE;
|
||||
in.requireChangeId = InheritableBoolean.TRUE;
|
||||
RestResponse r = session.put("/projects/" + newProjectName, in);
|
||||
ProjectInfo p = (new Gson()).fromJson(r.getReader(), new TypeToken<ProjectInfo>() {}.getType());
|
||||
ProjectInfo p = newGson().fromJson(r.getReader(), ProjectInfo.class);
|
||||
assertEquals(newProjectName, p.name);
|
||||
Project project = projectCache.get(new Project.NameKey(newProjectName)).getProject();
|
||||
assertProjectInfo(project, p);
|
||||
assertEquals(in.description, project.getDescription());
|
||||
assertEquals(in.submit_type, project.getSubmitType());
|
||||
assertEquals(in.use_contributor_agreements, project.getUseContributorAgreements());
|
||||
assertEquals(in.use_signed_off_by, project.getUseSignedOffBy());
|
||||
assertEquals(in.use_content_merge, project.getUseContentMerge());
|
||||
assertEquals(in.require_change_id, project.getRequireChangeID());
|
||||
assertEquals(in.submitType, project.getSubmitType());
|
||||
assertEquals(in.useContributorAgreements, project.getUseContributorAgreements());
|
||||
assertEquals(in.useSignedOffBy, project.getUseSignedOffBy());
|
||||
assertEquals(in.useContentMerge, project.getUseContentMerge());
|
||||
assertEquals(in.requireChangeId, project.getRequireChangeID());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -133,7 +132,7 @@ public class CreateProjectIT extends AbstractDaemonTest {
|
||||
RestResponse r = session.put("/projects/" + parentName);
|
||||
r.consume();
|
||||
final String childName = "child";
|
||||
ProjectInput in = new ProjectInput();
|
||||
CreateProject.Input in = new CreateProject.Input();
|
||||
in.parent = parentName;
|
||||
r = session.put("/projects/" + childName, in);
|
||||
Project project = projectCache.get(new Project.NameKey(childName)).getProject();
|
||||
@@ -142,7 +141,7 @@ public class CreateProjectIT extends AbstractDaemonTest {
|
||||
|
||||
public void testCreateChildProjectUnderNonExistingParent_UnprocessableEntity()
|
||||
throws IOException {
|
||||
ProjectInput in = new ProjectInput();
|
||||
CreateProject.Input in = new CreateProject.Input();
|
||||
in.parent = "non-existing-project";
|
||||
RestResponse r = session.put("/projects/child", in);
|
||||
assertEquals(HttpStatus.SC_UNPROCESSABLE_ENTITY, r.getStatusCode());
|
||||
@@ -151,7 +150,7 @@ public class CreateProjectIT extends AbstractDaemonTest {
|
||||
@Test
|
||||
public void testCreateProjectWithOwner() throws IOException {
|
||||
final String newProjectName = "newProject";
|
||||
ProjectInput in = new ProjectInput();
|
||||
CreateProject.Input in = new CreateProject.Input();
|
||||
in.owners = Lists.newArrayListWithCapacity(3);
|
||||
in.owners.add("Anonymous Users"); // by name
|
||||
in.owners.add(SystemGroupBackend.REGISTERED_USERS.get()); // by UUID
|
||||
@@ -168,7 +167,7 @@ public class CreateProjectIT extends AbstractDaemonTest {
|
||||
|
||||
public void testCreateProjectWithNonExistingOwner_UnprocessableEntity()
|
||||
throws IOException {
|
||||
ProjectInput in = new ProjectInput();
|
||||
CreateProject.Input in = new CreateProject.Input();
|
||||
in.owners = Collections.singletonList("non-existing-group");
|
||||
RestResponse r = session.put("/projects/newProject", in);
|
||||
assertEquals(HttpStatus.SC_UNPROCESSABLE_ENTITY, r.getStatusCode());
|
||||
@@ -177,8 +176,8 @@ public class CreateProjectIT extends AbstractDaemonTest {
|
||||
@Test
|
||||
public void testCreatePermissionOnlyProject() throws IOException {
|
||||
final String newProjectName = "newProject";
|
||||
ProjectInput in = new ProjectInput();
|
||||
in.permissions_only = true;
|
||||
CreateProject.Input in = new CreateProject.Input();
|
||||
in.permissionsOnly = true;
|
||||
session.put("/projects/" + newProjectName, in);
|
||||
assertHead(newProjectName, RefNames.REFS_CONFIG);
|
||||
}
|
||||
@@ -186,8 +185,8 @@ public class CreateProjectIT extends AbstractDaemonTest {
|
||||
@Test
|
||||
public void testCreateProjectWithEmptyCommit() throws IOException {
|
||||
final String newProjectName = "newProject";
|
||||
ProjectInput in = new ProjectInput();
|
||||
in.create_empty_commit = true;
|
||||
CreateProject.Input in = new CreateProject.Input();
|
||||
in.createEmptyCommit = true;
|
||||
session.put("/projects/" + newProjectName, in);
|
||||
assertEmptyCommit(newProjectName, "refs/heads/master");
|
||||
}
|
||||
@@ -195,8 +194,8 @@ public class CreateProjectIT extends AbstractDaemonTest {
|
||||
@Test
|
||||
public void testCreateProjectWithBranches() throws IOException {
|
||||
final String newProjectName = "newProject";
|
||||
ProjectInput in = new ProjectInput();
|
||||
in.create_empty_commit = true;
|
||||
CreateProject.Input in = new CreateProject.Input();
|
||||
in.createEmptyCommit = true;
|
||||
in.branches = Lists.newArrayListWithCapacity(3);
|
||||
in.branches.add("refs/heads/test");
|
||||
in.branches.add("refs/heads/master");
|
||||
@@ -256,20 +255,4 @@ public class CreateProjectIT extends AbstractDaemonTest {
|
||||
repo.close();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class ProjectInput {
|
||||
String name;
|
||||
String parent;
|
||||
String description;
|
||||
boolean permissions_only;
|
||||
boolean create_empty_commit;
|
||||
SubmitType submit_type;
|
||||
List<String> branches;
|
||||
List<String> owners;
|
||||
InheritableBoolean use_contributor_agreements;
|
||||
InheritableBoolean use_signed_off_by;
|
||||
InheritableBoolean use_content_merge;
|
||||
InheritableBoolean require_change_id;
|
||||
}
|
||||
}
|
||||
|
@@ -27,8 +27,7 @@ import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.config.AllProjectsName;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gerrit.server.project.ProjectJson.ProjectInfo;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import com.jcraft.jsch.JSchException;
|
||||
@@ -88,8 +87,7 @@ public class GetChildProjectIT extends AbstractDaemonTest {
|
||||
RestResponse r = GET("/projects/" + allProjects.get() + "/children/" + child.get());
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
ProjectInfo childInfo =
|
||||
(new Gson()).fromJson(r.getReader(),
|
||||
new TypeToken<ProjectInfo>() {}.getType());
|
||||
newGson().fromJson(r.getReader(), ProjectInfo.class);
|
||||
assertProjectInfo(projectCache.get(child).getProject(), childInfo);
|
||||
}
|
||||
|
||||
@@ -120,7 +118,7 @@ public class GetChildProjectIT extends AbstractDaemonTest {
|
||||
+ "?recursive");
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
ProjectInfo grandChildInfo =
|
||||
(new Gson()).fromJson(r.getReader(), new TypeToken<ProjectInfo>() {}.getType());
|
||||
newGson().fromJson(r.getReader(), ProjectInfo.class);
|
||||
assertProjectInfo(projectCache.get(grandChild).getProject(), grandChildInfo);
|
||||
}
|
||||
|
||||
|
@@ -36,8 +36,8 @@ import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.git.MetaDataUpdate;
|
||||
import com.google.gerrit.server.git.ProjectConfig;
|
||||
import com.google.gerrit.server.group.SystemGroupBackend;
|
||||
import com.google.gerrit.server.project.ListBranches.BranchInfo;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.SchemaFactory;
|
||||
@@ -123,15 +123,12 @@ public class ListBranchesIT extends AbstractDaemonTest {
|
||||
Project.NameKey emptyProject = new Project.NameKey("empty");
|
||||
createProject(sshSession, emptyProject.get(), null, false);
|
||||
RestResponse r = session.get("/projects/" + emptyProject.get() + "/branches");
|
||||
List<BranchInfo> result =
|
||||
(new Gson()).fromJson(r.getReader(),
|
||||
new TypeToken<List<BranchInfo>>() {}.getType());
|
||||
List<BranchInfo> expected = Lists.asList(
|
||||
new BranchInfo("refs/meta/config", null, false),
|
||||
new BranchInfo[] {
|
||||
new BranchInfo("HEAD", null, false)
|
||||
});
|
||||
assertBranches(expected, result);
|
||||
assertBranches(expected, toBranchInfoList(r));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -141,9 +138,6 @@ public class ListBranchesIT extends AbstractDaemonTest {
|
||||
pushTo("refs/heads/dev");
|
||||
String devCommit = git.getRepository().getRef("master").getTarget().getObjectId().getName();
|
||||
RestResponse r = session.get("/projects/" + project.get() + "/branches");
|
||||
List<BranchInfo> result =
|
||||
(new Gson()).fromJson(r.getReader(),
|
||||
new TypeToken<List<BranchInfo>>() {}.getType());
|
||||
List<BranchInfo> expected = Lists.asList(
|
||||
new BranchInfo("refs/meta/config", null, false),
|
||||
new BranchInfo[] {
|
||||
@@ -151,6 +145,7 @@ public class ListBranchesIT extends AbstractDaemonTest {
|
||||
new BranchInfo("refs/heads/master", masterCommit, false),
|
||||
new BranchInfo("refs/heads/dev", devCommit, true)
|
||||
});
|
||||
List<BranchInfo> result = toBranchInfoList(r);
|
||||
assertBranches(expected, result);
|
||||
|
||||
// verify correct sorting
|
||||
@@ -170,16 +165,13 @@ public class ListBranchesIT extends AbstractDaemonTest {
|
||||
String masterCommit = git.getRepository().getRef("master").getTarget().getObjectId().getName();
|
||||
pushTo("refs/heads/dev");
|
||||
RestResponse r = session.get("/projects/" + project.get() + "/branches");
|
||||
List<BranchInfo> result =
|
||||
(new Gson()).fromJson(r.getReader(),
|
||||
new TypeToken<List<BranchInfo>>() {}.getType());
|
||||
// refs/meta/config is hidden since user is no project owner
|
||||
List<BranchInfo> expected = Lists.asList(
|
||||
new BranchInfo("HEAD", "master", false),
|
||||
new BranchInfo[] {
|
||||
new BranchInfo("refs/heads/master", masterCommit, false),
|
||||
});
|
||||
assertBranches(expected, result);
|
||||
assertBranches(expected, toBranchInfoList(r));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -192,12 +184,9 @@ public class ListBranchesIT extends AbstractDaemonTest {
|
||||
pushTo("refs/heads/dev");
|
||||
String devCommit = git.getRepository().getRef("master").getTarget().getObjectId().getName();
|
||||
RestResponse r = session.get("/projects/" + project.get() + "/branches");
|
||||
List<BranchInfo> result =
|
||||
(new Gson()).fromJson(r.getReader(),
|
||||
new TypeToken<List<BranchInfo>>() {}.getType());
|
||||
// refs/meta/config is hidden since user is no project owner
|
||||
assertBranches(Collections.singletonList(new BranchInfo("refs/heads/dev",
|
||||
devCommit, false)), result);
|
||||
devCommit, false)), toBranchInfoList(r));
|
||||
}
|
||||
|
||||
private RestResponse GET(String endpoint) throws IOException {
|
||||
@@ -219,6 +208,14 @@ public class ListBranchesIT extends AbstractDaemonTest {
|
||||
projectCache.evict(config.getProject());
|
||||
}
|
||||
|
||||
private static List<BranchInfo> toBranchInfoList(RestResponse r)
|
||||
throws IOException {
|
||||
List<BranchInfo> result =
|
||||
newGson().fromJson(r.getReader(),
|
||||
new TypeToken<List<BranchInfo>>() {}.getType());
|
||||
return result;
|
||||
}
|
||||
|
||||
private PushOneCommit.Result pushTo(String ref) throws GitAPIException,
|
||||
IOException {
|
||||
PushOneCommit push = pushFactory.create(db, admin.getIdent());
|
||||
|
@@ -15,11 +15,10 @@
|
||||
package com.google.gerrit.acceptance.rest.project;
|
||||
|
||||
import static com.google.gerrit.acceptance.GitUtil.createProject;
|
||||
import static com.google.gerrit.acceptance.rest.project.ProjectAssert.assertProjects;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static com.google.gerrit.acceptance.rest.project.ProjectAssert.assertProjects;
|
||||
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.AccountCreator;
|
||||
import com.google.gerrit.acceptance.RestResponse;
|
||||
@@ -28,7 +27,8 @@ import com.google.gerrit.acceptance.SshSession;
|
||||
import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.config.AllProjectsName;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gerrit.server.project.ProjectJson.ProjectInfo;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import com.jcraft.jsch.JSchException;
|
||||
@@ -70,10 +70,7 @@ public class ListChildProjectsIT extends AbstractDaemonTest {
|
||||
public void listNoChildren() throws IOException {
|
||||
RestResponse r = GET("/projects/" + allProjects.get() + "/children/");
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
List<ProjectInfo> children =
|
||||
(new Gson()).fromJson(r.getReader(),
|
||||
new TypeToken<List<ProjectInfo>>() {}.getType());
|
||||
assertTrue(children.isEmpty());
|
||||
assertTrue(toProjectInfoList(r).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -88,10 +85,7 @@ public class ListChildProjectsIT extends AbstractDaemonTest {
|
||||
|
||||
RestResponse r = GET("/projects/" + allProjects.get() + "/children/");
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
List<ProjectInfo> children =
|
||||
(new Gson()).fromJson(r.getReader(),
|
||||
new TypeToken<List<ProjectInfo>>() {}.getType());
|
||||
assertProjects(Arrays.asList(child1, child2), children);
|
||||
assertProjects(Arrays.asList(child1, child2), toProjectInfoList(r));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -112,10 +106,14 @@ public class ListChildProjectsIT extends AbstractDaemonTest {
|
||||
|
||||
RestResponse r = GET("/projects/" + child1.get() + "/children/?recursive");
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
List<ProjectInfo> children =
|
||||
(new Gson()).fromJson(r.getReader(),
|
||||
assertProjects(Arrays.asList(child1_1, child1_2, child1_1_1, child1_1_1_1),
|
||||
toProjectInfoList(r));
|
||||
}
|
||||
|
||||
private static List<ProjectInfo> toProjectInfoList(RestResponse r)
|
||||
throws IOException {
|
||||
return newGson().fromJson(r.getReader(),
|
||||
new TypeToken<List<ProjectInfo>>() {}.getType());
|
||||
assertProjects(Arrays.asList(child1_1, child1_2, child1_1_1, child1_1_1_1), children);
|
||||
}
|
||||
|
||||
private RestResponse GET(String endpoint) throws IOException {
|
||||
|
@@ -24,6 +24,7 @@ import com.google.common.collect.Iterables;
|
||||
import com.google.gerrit.extensions.restapi.Url;
|
||||
import com.google.gerrit.reviewdb.client.AccountGroup;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.project.ProjectJson.ProjectInfo;
|
||||
import com.google.gerrit.server.project.ProjectState;
|
||||
|
||||
import java.util.List;
|
||||
|
@@ -1,27 +0,0 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.rest.project;
|
||||
|
||||
public class ProjectInfo {
|
||||
public String id;
|
||||
public String name;
|
||||
public String parent;
|
||||
public String description;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
@@ -26,8 +26,7 @@ import com.google.gerrit.acceptance.SshSession;
|
||||
import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.server.config.AllProjectsNameProvider;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gerrit.server.project.SetParent;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import com.jcraft.jsch.JSchException;
|
||||
@@ -79,7 +78,7 @@ public class SetParentIT extends AbstractDaemonTest {
|
||||
createProject(sshSession, parent, null, true);
|
||||
RestResponse r =
|
||||
userSession.put("/projects/" + project + "/parent",
|
||||
new ParentInput(parent));
|
||||
newParentInput(parent));
|
||||
assertEquals(HttpStatus.SC_FORBIDDEN, r.getStatusCode());
|
||||
r.consume();
|
||||
}
|
||||
@@ -90,15 +89,14 @@ public class SetParentIT extends AbstractDaemonTest {
|
||||
createProject(sshSession, parent, null, true);
|
||||
RestResponse r =
|
||||
adminSession.put("/projects/" + project + "/parent",
|
||||
new ParentInput(parent));
|
||||
newParentInput(parent));
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
r.consume();
|
||||
|
||||
r = adminSession.get("/projects/" + project + "/parent");
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
String newParent =
|
||||
(new Gson()).fromJson(r.getReader(),
|
||||
new TypeToken<String>() {}.getType());
|
||||
newGson().fromJson(r.getReader(), String.class);
|
||||
assertEquals(parent, newParent);
|
||||
r.consume();
|
||||
}
|
||||
@@ -107,7 +105,7 @@ public class SetParentIT extends AbstractDaemonTest {
|
||||
public void setParentForAllProjects_Conflict() throws IOException {
|
||||
RestResponse r =
|
||||
adminSession.put("/projects/" + allProjects.get() + "/parent",
|
||||
new ParentInput(project));
|
||||
newParentInput(project));
|
||||
assertEquals(HttpStatus.SC_CONFLICT, r.getStatusCode());
|
||||
r.consume();
|
||||
}
|
||||
@@ -116,21 +114,21 @@ public class SetParentIT extends AbstractDaemonTest {
|
||||
public void setInvalidParent_Conflict() throws IOException, JSchException {
|
||||
RestResponse r =
|
||||
adminSession.put("/projects/" + project + "/parent",
|
||||
new ParentInput(project));
|
||||
newParentInput(project));
|
||||
assertEquals(HttpStatus.SC_CONFLICT, r.getStatusCode());
|
||||
r.consume();
|
||||
|
||||
String child = "child";
|
||||
createProject(sshSession, child, new Project.NameKey(project), true);
|
||||
r = adminSession.put("/projects/" + project + "/parent",
|
||||
new ParentInput(child));
|
||||
newParentInput(child));
|
||||
assertEquals(HttpStatus.SC_CONFLICT, r.getStatusCode());
|
||||
r.consume();
|
||||
|
||||
String grandchild = "grandchild";
|
||||
createProject(sshSession, grandchild, new Project.NameKey(child), true);
|
||||
r = adminSession.put("/projects/" + project + "/parent",
|
||||
new ParentInput(grandchild));
|
||||
newParentInput(grandchild));
|
||||
assertEquals(HttpStatus.SC_CONFLICT, r.getStatusCode());
|
||||
r.consume();
|
||||
}
|
||||
@@ -139,17 +137,14 @@ public class SetParentIT extends AbstractDaemonTest {
|
||||
public void setNonExistingParent_UnprocessibleEntity() throws IOException {
|
||||
RestResponse r =
|
||||
adminSession.put("/projects/" + project + "/parent",
|
||||
new ParentInput("non-existing"));
|
||||
newParentInput("non-existing"));
|
||||
assertEquals(HttpStatus.SC_UNPROCESSABLE_ENTITY, r.getStatusCode());
|
||||
r.consume();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static class ParentInput {
|
||||
String parent;
|
||||
|
||||
ParentInput(String parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
SetParent.Input newParentInput(String project) {
|
||||
SetParent.Input in = new SetParent.Input();
|
||||
in.parent = project;
|
||||
return in;
|
||||
}
|
||||
}
|
||||
|
@@ -3,19 +3,6 @@ include_defs('//gerrit-acceptance-tests/tests.defs')
|
||||
acceptance_tests(
|
||||
srcs = glob(['*IT.java']),
|
||||
deps = [
|
||||
':util',
|
||||
'//gerrit-acceptance-tests:lib',
|
||||
'//lib:gwtjsonrpc',
|
||||
],
|
||||
)
|
||||
|
||||
java_library(
|
||||
name = 'util',
|
||||
srcs = [
|
||||
'ChangeAndCommit.java',
|
||||
'RelatedInfo.java',
|
||||
],
|
||||
deps = [
|
||||
'//gerrit-server:server',
|
||||
],
|
||||
)
|
||||
|
@@ -1,24 +0,0 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.server.change;
|
||||
|
||||
import com.google.gerrit.server.change.ChangeJson.CommitInfo;
|
||||
|
||||
public class ChangeAndCommit {
|
||||
public String changeId;
|
||||
public CommitInfo commit;
|
||||
public Integer _changeNumber;
|
||||
public Integer _revisionNumber;
|
||||
}
|
@@ -26,17 +26,17 @@ import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.AccountCreator;
|
||||
import com.google.gerrit.acceptance.GitUtil.Commit;
|
||||
import com.google.gerrit.acceptance.PushOneCommit;
|
||||
import com.google.gerrit.acceptance.RestSession;
|
||||
import com.google.gerrit.acceptance.SshSession;
|
||||
import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.acceptance.GitUtil.Commit;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
import com.google.gerrit.reviewdb.client.PatchSet;
|
||||
import com.google.gerrit.reviewdb.client.Project;
|
||||
import com.google.gerrit.reviewdb.server.ReviewDb;
|
||||
import com.google.gerrit.server.OutputFormat;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.google.gerrit.server.change.GetRelated.ChangeAndCommit;
|
||||
import com.google.gerrit.server.change.GetRelated.RelatedInfo;
|
||||
import com.google.gwtorm.server.OrmException;
|
||||
import com.google.gwtorm.server.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
@@ -189,10 +189,8 @@ public class GetRelatedIT extends AbstractDaemonTest {
|
||||
private List<ChangeAndCommit> getRelated(PatchSet.Id ps) throws IOException {
|
||||
String url = String.format("/changes/%d/revisions/%d/related",
|
||||
ps.getParentKey().get(), ps.get());
|
||||
RelatedInfo related = OutputFormat.JSON_COMPACT.newGson().fromJson(
|
||||
session.get(url).getReader(),
|
||||
new TypeToken<RelatedInfo>() {}.getType());
|
||||
return related.changes;
|
||||
return newGson().fromJson(session.get(url).getReader(),
|
||||
RelatedInfo.class).changes;
|
||||
}
|
||||
|
||||
private PatchSet.Id getPatchSetId(Commit c) throws OrmException {
|
||||
|
@@ -1,21 +0,0 @@
|
||||
// Copyright (C) 2013 The Android Open Source Project
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.server.change;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class RelatedInfo {
|
||||
public List<ChangeAndCommit> changes;
|
||||
}
|
@@ -4,6 +4,5 @@ acceptance_tests(
|
||||
srcs = glob(['*IT.java']),
|
||||
deps = [
|
||||
'//gerrit-acceptance-tests:lib',
|
||||
'//lib:gwtjsonrpc',
|
||||
],
|
||||
)
|
||||
|
@@ -47,9 +47,6 @@ import com.google.gerrit.server.git.MetaDataUpdate;
|
||||
import com.google.gerrit.server.git.ProjectConfig;
|
||||
import com.google.gerrit.server.group.SystemGroupBackend;
|
||||
import com.google.gerrit.server.project.ProjectCache;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gwtjsonrpc.server.SqlTimestampDeserializer;
|
||||
import com.google.gwtorm.server.SchemaFactory;
|
||||
import com.google.inject.Inject;
|
||||
import com.google.inject.util.Providers;
|
||||
@@ -62,7 +59,6 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.sql.Timestamp;
|
||||
|
||||
public class LabelTypeIT extends AbstractDaemonTest {
|
||||
@Inject
|
||||
@@ -397,10 +393,4 @@ public class LabelTypeIT extends AbstractDaemonTest {
|
||||
assertEquals(HttpStatus.SC_OK, r.getStatusCode());
|
||||
return newGson().fromJson(r.getReader(), ChangeInfo.class);
|
||||
}
|
||||
|
||||
private static Gson newGson() {
|
||||
return new GsonBuilder()
|
||||
.registerTypeAdapter(Timestamp.class, new SqlTimestampDeserializer())
|
||||
.create();
|
||||
}
|
||||
}
|
||||
|
@@ -51,7 +51,7 @@ public class GetDiffPreferences implements RestReadView<AccountResource> {
|
||||
return DiffPreferencesInfo.parse(a);
|
||||
}
|
||||
|
||||
static class DiffPreferencesInfo {
|
||||
public static class DiffPreferencesInfo {
|
||||
static DiffPreferencesInfo parse(AccountDiffPreference p) {
|
||||
DiffPreferencesInfo info = new DiffPreferencesInfo();
|
||||
info.context = p.getContext();
|
||||
@@ -74,22 +74,22 @@ public class GetDiffPreferences implements RestReadView<AccountResource> {
|
||||
return info;
|
||||
}
|
||||
|
||||
short context;
|
||||
Boolean expandAllComments;
|
||||
Whitespace ignoreWhitespace;
|
||||
Boolean intralineDifference;
|
||||
int lineLength;
|
||||
Boolean manualReview;
|
||||
Boolean retainHeader;
|
||||
Boolean showLineEndings;
|
||||
Boolean showTabs;
|
||||
Boolean showWhitespaceErrors;
|
||||
Boolean skipDeleted;
|
||||
Boolean skipUncommented;
|
||||
Boolean syntaxHighlighting;
|
||||
Boolean hideTopMenu;
|
||||
Boolean hideLineNumbers;
|
||||
Boolean renderEntireFile;
|
||||
int tabSize;
|
||||
public short context;
|
||||
public Boolean expandAllComments;
|
||||
public Whitespace ignoreWhitespace;
|
||||
public Boolean intralineDifference;
|
||||
public int lineLength;
|
||||
public Boolean manualReview;
|
||||
public Boolean retainHeader;
|
||||
public Boolean showLineEndings;
|
||||
public Boolean showTabs;
|
||||
public Boolean showWhitespaceErrors;
|
||||
public Boolean skipDeleted;
|
||||
public Boolean skipUncommented;
|
||||
public Boolean syntaxHighlighting;
|
||||
public Boolean hideTopMenu;
|
||||
public Boolean hideLineNumbers;
|
||||
public Boolean renderEntireFile;
|
||||
public int tabSize;
|
||||
}
|
||||
}
|
||||
|
@@ -279,16 +279,16 @@ public class GetRelated implements RestReadView<RevisionResource> {
|
||||
return p;
|
||||
}
|
||||
|
||||
static class RelatedInfo {
|
||||
List<ChangeAndCommit> changes;
|
||||
public static class RelatedInfo {
|
||||
public List<ChangeAndCommit> changes;
|
||||
}
|
||||
|
||||
static class ChangeAndCommit {
|
||||
String changeId;
|
||||
CommitInfo commit;
|
||||
Integer _changeNumber;
|
||||
Integer _revisionNumber;
|
||||
Integer _currentRevisionNumber;
|
||||
public static class ChangeAndCommit {
|
||||
public String changeId;
|
||||
public CommitInfo commit;
|
||||
public Integer _changeNumber;
|
||||
public Integer _revisionNumber;
|
||||
public Integer _currentRevisionNumber;
|
||||
|
||||
ChangeAndCommit(@Nullable Change change, @Nullable PatchSet ps, RevCommit c) {
|
||||
if (change != null) {
|
||||
|
@@ -54,7 +54,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
class SuggestReviewers implements RestReadView<ChangeResource> {
|
||||
public class SuggestReviewers implements RestReadView<ChangeResource> {
|
||||
|
||||
private static final String MAX_SUFFIX = "\u9fa5";
|
||||
private static final int MAX = 10;
|
||||
@@ -268,7 +268,7 @@ class SuggestReviewers implements RestReadView<ChangeResource> {
|
||||
return false;
|
||||
}
|
||||
|
||||
static class SuggestedReviewerInfo implements Comparable<SuggestedReviewerInfo> {
|
||||
public static class SuggestedReviewerInfo implements Comparable<SuggestedReviewerInfo> {
|
||||
String kind = "gerritcodereview#suggestedreviewer";
|
||||
AccountInfo account;
|
||||
GroupBaseInfo group;
|
||||
|
@@ -47,7 +47,7 @@ public class AddIncludedGroups implements RestModifyView<GroupResource, Input> {
|
||||
@DefaultInput
|
||||
String _oneGroup;
|
||||
|
||||
List<String> groups;
|
||||
public List<String> groups;
|
||||
|
||||
public static Input fromGroups(List<String> groups) {
|
||||
Input in = new Input();
|
||||
|
@@ -46,12 +46,12 @@ import org.eclipse.jgit.lib.Config;
|
||||
import java.util.Collections;
|
||||
|
||||
@RequiresCapability(GlobalCapability.CREATE_GROUP)
|
||||
class CreateGroup implements RestModifyView<TopLevelResource, Input> {
|
||||
static class Input {
|
||||
String name;
|
||||
String description;
|
||||
Boolean visibleToAll;
|
||||
String ownerId;
|
||||
public class CreateGroup implements RestModifyView<TopLevelResource, Input> {
|
||||
public static class Input {
|
||||
public String name;
|
||||
public String description;
|
||||
public Boolean visibleToAll;
|
||||
public String ownerId;
|
||||
}
|
||||
|
||||
static interface Factory {
|
||||
|
@@ -31,9 +31,9 @@ import com.google.inject.Inject;
|
||||
import java.util.Collections;
|
||||
|
||||
public class PutDescription implements RestModifyView<GroupResource, Input> {
|
||||
static class Input {
|
||||
public static class Input {
|
||||
@DefaultInput
|
||||
String description;
|
||||
public String description;
|
||||
}
|
||||
|
||||
private final GroupCache groupCache;
|
||||
|
@@ -31,9 +31,9 @@ import com.google.gwtorm.server.OrmException;
|
||||
import com.google.inject.Inject;
|
||||
|
||||
public class PutName implements RestModifyView<GroupResource, Input> {
|
||||
static class Input {
|
||||
public static class Input {
|
||||
@DefaultInput
|
||||
String name;
|
||||
public String name;
|
||||
}
|
||||
|
||||
private final PerformRenameGroup.Factory performRenameGroupFactory;
|
||||
|
@@ -29,8 +29,8 @@ import com.google.inject.Inject;
|
||||
import java.util.Collections;
|
||||
|
||||
public class PutOptions implements RestModifyView<GroupResource, Input> {
|
||||
static class Input {
|
||||
Boolean visibleToAll;
|
||||
public static class Input {
|
||||
public Boolean visibleToAll;
|
||||
}
|
||||
|
||||
private final GroupCache groupCache;
|
||||
|
@@ -35,9 +35,9 @@ import com.google.inject.Provider;
|
||||
import java.util.Collections;
|
||||
|
||||
public class PutOwner implements RestModifyView<GroupResource, Input> {
|
||||
static class Input {
|
||||
public static class Input {
|
||||
@DefaultInput
|
||||
String owner;
|
||||
public String owner;
|
||||
}
|
||||
|
||||
private final Provider<GroupsCollection> groupsCollection;
|
||||
|
@@ -164,11 +164,7 @@ public class CreateBranch implements RestModifyView<ProjectResource, Input> {
|
||||
}
|
||||
}
|
||||
|
||||
BranchInfo b = new BranchInfo();
|
||||
b.ref = ref;
|
||||
b.revision = revid.getName();
|
||||
b.setCanDelete(refControl.canDelete());
|
||||
return b;
|
||||
return new BranchInfo(ref, revid.getName(), refControl.canDelete());
|
||||
} catch (IOException err) {
|
||||
log.error("Cannot create branch \"" + name + "\"", err);
|
||||
throw err;
|
||||
|
@@ -98,12 +98,9 @@ public class ListBranches implements RestReadView<ProjectResource> {
|
||||
target = target.substring(Constants.R_HEADS.length());
|
||||
}
|
||||
|
||||
BranchInfo b = new BranchInfo();
|
||||
b.ref = ref.getName();
|
||||
b.revision = target;
|
||||
BranchInfo b = new BranchInfo(ref.getName(), target, false);
|
||||
|
||||
if (Constants.HEAD.equals(ref.getName())) {
|
||||
b.setCanDelete(false);
|
||||
headBranch = b;
|
||||
} else {
|
||||
b.setCanDelete(targetRefControl.canDelete());
|
||||
@@ -141,13 +138,9 @@ public class ListBranches implements RestReadView<ProjectResource> {
|
||||
|
||||
private static BranchInfo createBranchInfo(Ref ref, RefControl refControl,
|
||||
Set<String> targets) {
|
||||
BranchInfo b = new BranchInfo();
|
||||
b.ref = ref.getName();
|
||||
if (ref.getObjectId() != null) {
|
||||
b.revision = ref.getObjectId().name();
|
||||
}
|
||||
b.setCanDelete(!targets.contains(ref.getName()) && refControl.canDelete());
|
||||
return b;
|
||||
return new BranchInfo(ref.getName(),
|
||||
ref.getObjectId() != null ? ref.getObjectId().name() : null,
|
||||
!targets.contains(ref.getName()) && refControl.canDelete());
|
||||
}
|
||||
|
||||
public static class BranchInfo {
|
||||
@@ -155,6 +148,12 @@ public class ListBranches implements RestReadView<ProjectResource> {
|
||||
public String revision;
|
||||
public Boolean canDelete;
|
||||
|
||||
public BranchInfo(String ref, String revision, boolean canDelete) {
|
||||
this.ref = ref;
|
||||
this.revision = revision;
|
||||
this.canDelete = canDelete;
|
||||
}
|
||||
|
||||
void setCanDelete(boolean canDelete) {
|
||||
this.canDelete = canDelete ? true : null;
|
||||
}
|
||||
|
@@ -38,10 +38,10 @@ import org.eclipse.jgit.errors.RepositoryNotFoundException;
|
||||
import java.io.IOException;
|
||||
|
||||
public class SetParent implements RestModifyView<ProjectResource, Input> {
|
||||
static class Input {
|
||||
public static class Input {
|
||||
@DefaultInput
|
||||
String parent;
|
||||
String commitMessage;
|
||||
public String parent;
|
||||
public String commitMessage;
|
||||
}
|
||||
|
||||
private final ProjectCache cache;
|
||||
|
Reference in New Issue
Block a user