Remove `UriResourceLocator` And all URIs related to gerrit REST endpoints. Also clean-up remainding mocks in tests. Bug: Issue 336577745 Change-Id: I834298e22adde3bcadcd02378cf2ef92d3a1dda8
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/UriResourceLocator.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/UriResourceLocator.java deleted file mode 100644 index 084657f..0000000 --- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/common/client/api/UriResourceLocator.java +++ /dev/null
@@ -1,46 +0,0 @@ -package com.googlesource.gerrit.plugins.chatgpt.mode.common.client.api; - -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; - - -public class UriResourceLocator { - private static final String AUTH_PREFIX_URI = "/a"; - - public static String gerritAccountsUri() { - return AUTH_PREFIX_URI + "/accounts"; - } - - public static String gerritAccountIdUri(String userName) { - return gerritAccountsUri() + "/?q=username:" + URLEncoder.encode(userName, StandardCharsets.UTF_8); - } - - public static String gerritGroupPostfixUri(int accountId) { - return "/" + accountId + "/groups"; - } - - public static String gerritRevisionBasePostfixUri(int revisionBase) { - return revisionBase > 0 ? "/?base=" + revisionBase : ""; - } - - public static String gerritPatchSetRevisionsUri(String fullChangeId) { - return gerritSetChangesUri(fullChangeId, "/?o=ALL_REVISIONS"); - } - - public static String gerritGetAllPatchSetCommentsUri(String fullChangeId) { - return gerritSetChangesUri(fullChangeId, "/comments"); - } - - public static String gerritSetReviewUri(String fullChangeId) { - return gerritSetChangesUri(fullChangeId, "/revisions/current/review"); - } - - public static String gerritGetPatchSetDetailUri(String fullChangeId) { - return gerritSetChangesUri(fullChangeId, "/detail"); - } - - protected static String gerritSetChangesUri(String fullChangeId, String uriPostfix) { - return AUTH_PREFIX_URI + "/changes/" + fullChangeId + uriPostfix; - } - -}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/UriResourceLocatorStateful.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/UriResourceLocatorStateful.java index 87fc0f3..586fce9 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/UriResourceLocatorStateful.java +++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateful/client/api/UriResourceLocatorStateful.java
@@ -1,8 +1,6 @@ package com.googlesource.gerrit.plugins.chatgpt.mode.stateful.client.api; -import com.googlesource.gerrit.plugins.chatgpt.mode.common.client.api.UriResourceLocator; - -public class UriResourceLocatorStateful extends UriResourceLocator { +public class UriResourceLocatorStateful { public static String chatCreateFilesUri() { return "/v1/files"; }
diff --git a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateless/client/api/UriResourceLocatorStateless.java b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateless/client/api/UriResourceLocatorStateless.java index 299da78..a09cd28 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateless/client/api/UriResourceLocatorStateless.java +++ b/src/main/java/com/googlesource/gerrit/plugins/chatgpt/mode/stateless/client/api/UriResourceLocatorStateless.java
@@ -1,21 +1,8 @@ package com.googlesource.gerrit.plugins.chatgpt.mode.stateless.client.api; -import com.googlesource.gerrit.plugins.chatgpt.mode.common.client.api.UriResourceLocator; -import java.net.URLEncoder; -import java.nio.charset.StandardCharsets; - -public class UriResourceLocatorStateless extends UriResourceLocator { - public static String gerritDiffPostfixUri(String filename) { - return "/" + URLEncoder.encode(filename, StandardCharsets.UTF_8) + "/diff"; - } - - public static String gerritPatchSetFilesUri(String fullChangeId) { - return gerritSetChangesUri(fullChangeId, "/revisions/current/files"); - } - +public class UriResourceLocatorStateless { public static String chatCompletionsUri() { return "/v1/chat/completions"; } - }
diff --git a/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewTestBase.java b/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewTestBase.java index 5c557ef..0c024f8 100644 --- a/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewTestBase.java +++ b/src/test/java/com/googlesource/gerrit/plugins/chatgpt/ChatGptReviewTestBase.java
@@ -1,9 +1,7 @@ package com.googlesource.gerrit.plugins.chatgpt; -import com.github.tomakehurst.wiremock.client.WireMock; import com.github.tomakehurst.wiremock.junit.WireMockRule; import com.github.tomakehurst.wiremock.verification.LoggedRequest; -import com.google.common.net.HttpHeaders; import com.google.gerrit.entities.Account; import com.google.gerrit.entities.BranchNameKey; import com.google.gerrit.entities.Change; @@ -57,7 +55,6 @@ import com.googlesource.gerrit.plugins.chatgpt.mode.stateless.client.api.chatgpt.ChatGptClientStateless; import com.googlesource.gerrit.plugins.chatgpt.mode.stateless.client.api.gerrit.GerritClientPatchSetStateless; import lombok.NonNull; -import org.apache.http.entity.ContentType; import org.junit.Before; import org.junit.Rule; import org.mockito.ArgumentCaptor; @@ -78,9 +75,7 @@ import java.util.function.Consumer; import static com.google.gerrit.extensions.client.ChangeKind.REWORK; -import static com.googlesource.gerrit.plugins.chatgpt.mode.common.client.api.UriResourceLocator.*; import static com.googlesource.gerrit.plugins.chatgpt.utils.GsonUtils.getGson; -import static java.net.HttpURLConnection.HTTP_OK; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -180,8 +175,6 @@ } protected void setupMockRequests() throws RestApiException { - String fullChangeId = getGerritChange().getFullChangeId(); - Accounts accountsMock = mockGerritAccountsRestEndpoint(); // Mock the behavior of the gerritAccountIdUri request mockGerritAccountsQueryApiCall(accountsMock, GERRIT_GPT_USERNAME, GERRIT_GPT_ACCOUNT_ID); @@ -193,33 +186,12 @@ mockGerritAccountGroupsApiCall(accountsMock, GERRIT_USER_ACCOUNT_ID); mockGerritChangeApiRestEndpoint(); - // Mock the behavior of the gerritPatchSetRevisionsUri request - WireMock.stubFor(WireMock.get(gerritPatchSetRevisionsUri(fullChangeId)) - .willReturn(WireMock.aResponse() - .withStatus(HTTP_OK) - .withHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()) - .withBody("{\"revisions\":{\"aa5be5ebb80846475ec4dfe43e0799eb73c6415a\":{}}}"))); // Mock the behavior of the gerritGetPatchSetDetailUri request - WireMock.stubFor(WireMock.get(gerritGetPatchSetDetailUri(fullChangeId)) - .willReturn(WireMock.aResponse() - .withStatus(HTTP_OK) - .withHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()) - .withBodyFile("gerritPatchSetDetail.json"))); mockGerritChangeDetailsApiCall(); // Mock the behavior of the gerritPatchSet comments request - WireMock.stubFor(WireMock.get(gerritGetAllPatchSetCommentsUri(fullChangeId)) - .willReturn(WireMock.aResponse() - .withStatus(HTTP_OK) - .withHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString()) - .withBodyFile("gerritPatchSetComments.json"))); mockGerritChangeCommentsApiCall(); - - // Mock the behavior of the postReview request - WireMock.stubFor(WireMock.post(gerritSetReviewUri(fullChangeId)) - .willReturn(WireMock.aResponse() - .withStatus(HTTP_OK))); } private Accounts mockGerritAccountsRestEndpoint() {