Fix error message when --query and --query2 are both used on GET /groups/

--query and --query2 on GET /groups/ are mutually exclusive. Using
both of these options at the same time already failed because the
QueryGroups REST endpoint was always returned when --query2 was
specified and QueryGroups was rejecting --query with:

  "--query" is not a valid option

Change-Id: I89aa4ea8c7f5ed8e354e0cf42635b96aba7ed93e
Signed-off-by: Edwin Kempin <ekempin@google.com>
This commit is contained in:
Edwin Kempin
2017-01-16 14:14:53 +01:00
parent f7773c4bc0
commit 67810cf171
3 changed files with 41 additions and 2 deletions

View File

@@ -0,0 +1,32 @@
// Copyright (C) 2017 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 static com.google.common.truth.Truth.assertThat;
import com.google.gerrit.acceptance.AbstractDaemonTest;
import com.google.gerrit.acceptance.RestResponse;
import org.junit.Test;
public class GroupsIT extends AbstractDaemonTest {
@Test
public void invalidQueryOptions() throws Exception {
RestResponse r = adminRestSession.put("/groups/?query=foo&query2=bar");
r.assertBadRequest();
assertThat(r.getEntityContent())
.isEqualTo("\"query\" and \"query2\" options are mutually exclusive");
}
}

View File

@@ -28,5 +28,5 @@ public interface NeedsParams {
*
* @param params the request parameter
*/
void setParams(Multimap<String, String> params);
void setParams(Multimap<String, String> params) throws RestApiException;
}

View File

@@ -22,6 +22,7 @@ import com.google.gerrit.common.errors.NoSuchGroupException;
import com.google.gerrit.extensions.registration.DynamicMap;
import com.google.gerrit.extensions.restapi.AcceptsCreate;
import com.google.gerrit.extensions.restapi.AuthException;
import com.google.gerrit.extensions.restapi.BadRequestException;
import com.google.gerrit.extensions.restapi.IdString;
import com.google.gerrit.extensions.restapi.NeedsParams;
import com.google.gerrit.extensions.restapi.ResourceNotFoundException;
@@ -69,7 +70,13 @@ public class GroupsCollection implements
}
@Override
public void setParams(Multimap<String, String> params) {
public void setParams(Multimap<String, String> params)
throws BadRequestException {
if (params.containsKey("query") && params.containsKey("query2")) {
throw new BadRequestException(
"\"query\" and \"query2\" options are mutually exclusive");
}
// The --query2 option is defined in QueryGroups
this.hasQuery2 = params.containsKey("query2");
}