Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public static List<Option<String>> getProjectIdOptions(

List<Option<String>> options = new ArrayList<>();

String nextPageToken = "";
String nextPageToken = null;

do {
Map<String, Object> response = context
.http(http -> http.get("https://bigquery.googleapis.com/bigquery/v2/projects"))
.configuration(responseType(Http.ResponseType.JSON))
.queryParameter(NEXT_PAGE_TOKEN, nextPageToken)
.queryParameters("pageToken", nextPageToken, "maxResults", 50)
.execute()
.getBody(new TypeReference<>() {});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static com.bytechef.component.definition.ComponentDsl.option;
import static com.bytechef.component.google.bigquery.constant.GoogleBigQueryConstants.ID;
import static com.bytechef.component.google.bigquery.constant.GoogleBigQueryConstants.NEXT_PAGE_TOKEN;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentCaptor.forClass;
Expand Down Expand Up @@ -56,6 +57,7 @@ class GoogleBigQueryUtilsTest {
private final Http mockedHttp = mock(Http.class);
private final Parameters mockedParameters = MockParametersFactory.create(Map.of());
private final Response mockedResponse = mock(Response.class);
private final ArgumentCaptor<Object[]> objectsArgumentCaptor = forClass(Object[].class);
private final ArgumentCaptor<String> stringArgumentCaptor = forClass(String.class);

@Test
Expand All @@ -70,7 +72,7 @@ void testGetProjectIdOptions() {
.thenReturn(mockedExecutor);
when(mockedExecutor.configuration(configurationBuilderArgumentCaptor.capture()))
.thenReturn(mockedExecutor);
when(mockedExecutor.queryParameter(stringArgumentCaptor.capture(), stringArgumentCaptor.capture()))
when(mockedExecutor.queryParameters(objectsArgumentCaptor.capture()))
.thenReturn(mockedExecutor);
when(mockedExecutor.execute())
.thenReturn(mockedResponse);
Expand Down Expand Up @@ -98,14 +100,33 @@ void testGetProjectIdOptions() {
assertNotNull(capturedFunction);

Configuration.ConfigurationBuilder configurationBuilder = configurationBuilderArgumentCaptor.getValue();

Configuration configuration = configurationBuilder.build();

Http.ResponseType responseType = configuration.getResponseType();

assertEquals(Http.ResponseType.Type.JSON, responseType.getType());

assertEquals(
List.of("https://bigquery.googleapis.com/bigquery/v2/projects", NEXT_PAGE_TOKEN, "",
"https://bigquery.googleapis.com/bigquery/v2/projects", NEXT_PAGE_TOKEN, "token"),
List.of(
"https://bigquery.googleapis.com/bigquery/v2/projects",
"https://bigquery.googleapis.com/bigquery/v2/projects"),
stringArgumentCaptor.getAllValues());

List<Object[]> allQueryParams = objectsArgumentCaptor.getAllValues();

assertEquals(2, allQueryParams.size());

Object[] queryParameters1 = {
"pageToken", null,
"maxResults", 50
};
Object[] queryParameters2 = {
"pageToken", "token",
"maxResults", 50
};

assertArrayEquals(queryParameters1, allQueryParams.get(0));
assertArrayEquals(queryParameters2, allQueryParams.get(1));
}
}