AccountApi: Add methods to get and set EditPreferencesInfo
Change-Id: Ib54a4cced7b97d1df7a68cc7d0ae17768c445548
This commit is contained in:
@@ -12,25 +12,25 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package com.google.gerrit.acceptance.rest.account;
|
||||
package com.google.gerrit.acceptance.api.accounts;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.RestResponse;
|
||||
import com.google.gerrit.acceptance.NoHttpd;
|
||||
import com.google.gerrit.extensions.client.EditPreferencesInfo;
|
||||
import com.google.gerrit.extensions.client.KeyMapType;
|
||||
import com.google.gerrit.extensions.client.Theme;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@NoHttpd
|
||||
public class EditPreferencesIT extends AbstractDaemonTest {
|
||||
@Test
|
||||
public void getSetEditPreferences() throws Exception {
|
||||
String endPoint = "/accounts/" + admin.email + "/preferences.edit";
|
||||
RestResponse r = adminSession.get(endPoint);
|
||||
r.assertOK();
|
||||
EditPreferencesInfo out = getEditPrefInfo(r);
|
||||
EditPreferencesInfo out = gApi.accounts()
|
||||
.id(admin.getId().toString())
|
||||
.getEditPreferences();
|
||||
|
||||
assertThat(out.lineLength).isEqualTo(100);
|
||||
assertThat(out.tabSize).isEqualTo(8);
|
||||
@@ -59,29 +59,24 @@ public class EditPreferencesIT extends AbstractDaemonTest {
|
||||
out.theme = Theme.TWILIGHT;
|
||||
out.keyMapType = KeyMapType.EMACS;
|
||||
|
||||
r = adminSession.put(endPoint, out);
|
||||
r.assertOK();
|
||||
EditPreferencesInfo info = gApi.accounts()
|
||||
.id(admin.getId().toString())
|
||||
.setEditPreferences(out);
|
||||
|
||||
EditPreferencesInfo info = getEditPrefInfo(r);
|
||||
assertEditPreferences(info, out);
|
||||
|
||||
// Partially filled input record
|
||||
EditPreferencesInfo in = new EditPreferencesInfo();
|
||||
in.tabSize = 42;
|
||||
r = adminSession.put(endPoint, in);
|
||||
r.assertOK();
|
||||
|
||||
info = getEditPrefInfo(r);
|
||||
info = gApi.accounts()
|
||||
.id(admin.getId().toString())
|
||||
.setEditPreferences(in);
|
||||
|
||||
out.tabSize = in.tabSize;
|
||||
assertEditPreferences(info, out);
|
||||
}
|
||||
|
||||
private EditPreferencesInfo getEditPrefInfo(RestResponse r)
|
||||
throws Exception {
|
||||
return newGson().fromJson(r.getReader(),
|
||||
EditPreferencesInfo.class);
|
||||
}
|
||||
|
||||
private void assertEditPreferences(EditPreferencesInfo out,
|
||||
EditPreferencesInfo in) throws Exception {
|
||||
assertThat(out.lineLength).isEqualTo(in.lineLength);
|
@@ -14,6 +14,7 @@
|
||||
|
||||
package com.google.gerrit.extensions.api.accounts;
|
||||
|
||||
import com.google.gerrit.extensions.client.EditPreferencesInfo;
|
||||
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.common.GpgKeyInfo;
|
||||
@@ -32,6 +33,10 @@ public interface AccountApi {
|
||||
GeneralPreferencesInfo setPreferences(GeneralPreferencesInfo in)
|
||||
throws RestApiException;
|
||||
|
||||
EditPreferencesInfo getEditPreferences() throws RestApiException;
|
||||
EditPreferencesInfo setEditPreferences(EditPreferencesInfo in)
|
||||
throws RestApiException;
|
||||
|
||||
void starChange(String id) throws RestApiException;
|
||||
void unstarChange(String id) throws RestApiException;
|
||||
void addEmail(EmailInput input) throws RestApiException;
|
||||
@@ -67,6 +72,17 @@ public interface AccountApi {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditPreferencesInfo getEditPreferences() throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditPreferencesInfo setEditPreferences(EditPreferencesInfo in)
|
||||
throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void starChange(String id) throws RestApiException {
|
||||
throw new NotImplementedException();
|
||||
|
@@ -18,6 +18,7 @@ import com.google.gerrit.common.errors.EmailException;
|
||||
import com.google.gerrit.extensions.api.accounts.AccountApi;
|
||||
import com.google.gerrit.extensions.api.accounts.EmailInput;
|
||||
import com.google.gerrit.extensions.api.accounts.GpgKeyApi;
|
||||
import com.google.gerrit.extensions.client.EditPreferencesInfo;
|
||||
import com.google.gerrit.extensions.client.GeneralPreferencesInfo;
|
||||
import com.google.gerrit.extensions.common.AccountInfo;
|
||||
import com.google.gerrit.extensions.common.GpgKeyInfo;
|
||||
@@ -29,7 +30,9 @@ import com.google.gerrit.server.account.AccountLoader;
|
||||
import com.google.gerrit.server.account.AccountResource;
|
||||
import com.google.gerrit.server.account.CreateEmail;
|
||||
import com.google.gerrit.server.account.GetAvatar;
|
||||
import com.google.gerrit.server.account.GetEditPreferences;
|
||||
import com.google.gerrit.server.account.GetPreferences;
|
||||
import com.google.gerrit.server.account.SetEditPreferences;
|
||||
import com.google.gerrit.server.account.SetPreferences;
|
||||
import com.google.gerrit.server.account.StarredChanges;
|
||||
import com.google.gerrit.server.change.ChangeResource;
|
||||
@@ -56,6 +59,8 @@ public class AccountApiImpl implements AccountApi {
|
||||
private final Provider<GetAvatar> getAvatar;
|
||||
private final GetPreferences getPreferences;
|
||||
private final SetPreferences setPreferences;
|
||||
private final GetEditPreferences getEditPreferences;
|
||||
private final SetEditPreferences setEditPreferences;
|
||||
private final StarredChanges.Create starredChangesCreate;
|
||||
private final StarredChanges.Delete starredChangesDelete;
|
||||
private final CreateEmail.Factory createEmailFactory;
|
||||
@@ -67,6 +72,8 @@ public class AccountApiImpl implements AccountApi {
|
||||
Provider<GetAvatar> getAvatar,
|
||||
GetPreferences getPreferences,
|
||||
SetPreferences setPreferences,
|
||||
GetEditPreferences getEditPreferences,
|
||||
SetEditPreferences setEditPreferences,
|
||||
StarredChanges.Create starredChangesCreate,
|
||||
StarredChanges.Delete starredChangesDelete,
|
||||
CreateEmail.Factory createEmailFactory,
|
||||
@@ -78,6 +85,8 @@ public class AccountApiImpl implements AccountApi {
|
||||
this.getAvatar = getAvatar;
|
||||
this.getPreferences = getPreferences;
|
||||
this.setPreferences = setPreferences;
|
||||
this.getEditPreferences = getEditPreferences;
|
||||
this.setEditPreferences = setEditPreferences;
|
||||
this.starredChangesCreate = starredChangesCreate;
|
||||
this.starredChangesDelete = starredChangesDelete;
|
||||
this.createEmailFactory = createEmailFactory;
|
||||
@@ -119,6 +128,25 @@ public class AccountApiImpl implements AccountApi {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditPreferencesInfo getEditPreferences() throws RestApiException {
|
||||
try {
|
||||
return getEditPreferences.apply(account);
|
||||
} catch (IOException | ConfigInvalidException e) {
|
||||
throw new RestApiException("Cannot query edit preferences", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EditPreferencesInfo setEditPreferences(EditPreferencesInfo in)
|
||||
throws RestApiException {
|
||||
try {
|
||||
return setEditPreferences.apply(account, in);
|
||||
} catch (IOException | ConfigInvalidException e) {
|
||||
throw new RestApiException("Cannot set edit preferences", e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void starChange(String id) throws RestApiException {
|
||||
try {
|
||||
|
Reference in New Issue
Block a user