-
Notifications
You must be signed in to change notification settings - Fork 741
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(retrofit2): fix retrofit2 issues (#1875)
* test(retrofit2): add test to demonstrate the following error when QueryMap is used without generics: `java.lang.IllegalArgumentException: Map must include generic types (e.g., Map<String, String>)` * fix(retrofit2): fix non-generics QueryMap which causes the following error: `java.lang.IllegalArgumentException: Map must include generic types (e.g., Map<String, String>)` * fix(retrofit2): fix `A @path parameter must not come after a @Query` error
- Loading branch information
1 parent
381f554
commit bdf8922
Showing
5 changed files
with
95 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...re/src/test/java/com/netflix/spinnaker/gate/services/internal/ClouddriverServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Copyright 2025 OpsMx, Inc. | ||
* | ||
* 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.netflix.spinnaker.gate.services.internal; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.get; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; | ||
import static com.github.tomakehurst.wiremock.client.WireMock.verify; | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer; | ||
import com.github.tomakehurst.wiremock.client.WireMock; | ||
import com.github.tomakehurst.wiremock.core.WireMockConfiguration; | ||
import com.netflix.spinnaker.kork.retrofit.ErrorHandlingExecutorCallAdapterFactory; | ||
import com.netflix.spinnaker.kork.retrofit.Retrofit2SyncCall; | ||
import java.util.Map; | ||
import okhttp3.OkHttpClient; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import retrofit2.Retrofit; | ||
import retrofit2.converter.jackson.JacksonConverterFactory; | ||
|
||
public class ClouddriverServiceTest { | ||
WireMockServer wireMockServer; | ||
int port; | ||
ClouddriverService clouddriverService; | ||
String baseUrl = "http://localhost:PORT"; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
wireMockServer = new WireMockServer(WireMockConfiguration.options().dynamicPort()); | ||
wireMockServer.start(); | ||
port = wireMockServer.port(); | ||
WireMock.configureFor("localhost", port); | ||
|
||
baseUrl = baseUrl.replaceFirst("PORT", String.valueOf(port)); | ||
|
||
clouddriverService = | ||
new Retrofit.Builder() | ||
.baseUrl(baseUrl) | ||
.client(new OkHttpClient()) | ||
.addCallAdapterFactory(ErrorHandlingExecutorCallAdapterFactory.getInstance()) | ||
.addConverterFactory(JacksonConverterFactory.create()) | ||
.build() | ||
.create(ClouddriverService.class); | ||
} | ||
|
||
@AfterEach | ||
void tearDown() { | ||
wireMockServer.stop(); | ||
} | ||
|
||
@Test | ||
void testClouddriverService_withQueryMap() { | ||
stubFor( | ||
get(urlEqualTo("/search?q=app1&type=securityGroups&platform=aws&pageSize=500&page=1")) | ||
.willReturn( | ||
aResponse() | ||
.withStatus(200) | ||
.withBody( | ||
"[{\"pageNumber\":1,\"pageSize\":500,\"platform\":\"aws\",\"query\":\"app1\",\"results\":[],\"totalMatches\":0}]"))); | ||
|
||
Retrofit2SyncCall.execute( | ||
clouddriverService.search("app1", "securityGroups", "aws", 500, 1, Map.of())); | ||
|
||
verify( | ||
1, | ||
getRequestedFor( | ||
urlEqualTo("/search?q=app1&type=securityGroups&platform=aws&pageSize=500&page=1"))); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters