@Test public void searchEndpointShouldHandleMultipleResourceTypes() throws Exception { MockResponse response = MockResponseFactory.create200() .setBody("{\"resourceLookup\": []}"); mWebMockRule.enqueue(response); Map<String, Object> params = new HashMap<>(); params.put("folderUri", "/"); Set<String> types = new HashSet<>(); types.add("reportUnit"); types.add("dashboard"); params.put("type", types); restApiUnderTest.searchResources(params); RecordedRequest request = mWebMockRule.get().takeRequest(); assertThat(request, containsHeader("Accept", "application/json; charset=UTF-8")); assertThat(request, hasQuery("folderUri", "/")); assertThat(request, hasQuery("type", "reportUnit")); assertThat(request, hasQuery("type", "dashboard")); assertThat(request, wasMethod("GET")); }
@NotNull public ResourceSearchResult searchResources(@NotNull Map<String, Object> searchParams) throws IOException, HttpException { HttpUrl url = mNetworkClient.getBaseUrl() .newBuilder() .addPathSegment("rest_v2") .addPathSegment("resources") .build(); url = QueryMapper.INSTANCE.mapParams(searchParams, url); Request request = new Request.Builder() .addHeader("Accept", "application/json; charset=UTF-8") .get() .url(url) .build(); com.squareup.okhttp.Response rawResponse = mNetworkClient.makeCall(request); int status = rawResponse.code(); ResourceSearchResult entity; if (status == 204) { entity = ResourceSearchResult.empty(); } else { entity = mNetworkClient.deserializeJson(rawResponse, ResourceSearchResult.class); com.squareup.okhttp.Headers headers = rawResponse.headers(); int resultCount = Utils.headerToInt(headers, "Result-Count"); int totalCount = Utils.headerToInt(headers, "Total-Count"); int startIndex = Utils.headerToInt(headers, "Start-Index"); int nextOffset = Utils.headerToInt(headers, "Next-Offset"); entity.setResultCount(resultCount); entity.setTotalCount(totalCount); entity.setStartIndex(startIndex); entity.setNextOffset(nextOffset); } return entity; }
RepositoryRestApi { @NotNull public ResourceSearchResult searchResources(@NotNull Map<String, Object> searchParams) throws IOException, HttpException { HttpUrl url = mNetworkClient.getBaseUrl() .newBuilder() .addPathSegment("rest_v2") .addPathSegment("resources") .build(); url = QueryMapper.INSTANCE.mapParams(searchParams, url); Request request = new Request.Builder() .addHeader("Accept", "application/json; charset=UTF-8") .get() .url(url) .build(); com.squareup.okhttp.Response rawResponse = mNetworkClient.makeCall(request); int status = rawResponse.code(); ResourceSearchResult entity; if (status == 204) { entity = ResourceSearchResult.empty(); } else { entity = mNetworkClient.deserializeJson(rawResponse, ResourceSearchResult.class); com.squareup.okhttp.Headers headers = rawResponse.headers(); int resultCount = Utils.headerToInt(headers, "Result-Count"); int totalCount = Utils.headerToInt(headers, "Total-Count"); int startIndex = Utils.headerToInt(headers, "Start-Index"); int nextOffset = Utils.headerToInt(headers, "Next-Offset"); entity.setResultCount(resultCount); entity.setTotalCount(totalCount); entity.setStartIndex(startIndex); entity.setNextOffset(nextOffset); } return entity; } }
RepositoryRestApi { @NotNull public ResourceSearchResult searchResources(@NotNull Map<String, Object> searchParams) throws IOException, HttpException { HttpUrl url = mNetworkClient.getBaseUrl() .newBuilder() .addPathSegment("rest_v2") .addPathSegment("resources") .build(); url = QueryMapper.INSTANCE.mapParams(searchParams, url); Request request = new Request.Builder() .addHeader("Accept", "application/json; charset=UTF-8") .get() .url(url) .build(); com.squareup.okhttp.Response rawResponse = mNetworkClient.makeCall(request); int status = rawResponse.code(); ResourceSearchResult entity; if (status == 204) { entity = ResourceSearchResult.empty(); } else { entity = mNetworkClient.deserializeJson(rawResponse, ResourceSearchResult.class); com.squareup.okhttp.Headers headers = rawResponse.headers(); int resultCount = Utils.headerToInt(headers, "Result-Count"); int totalCount = Utils.headerToInt(headers, "Total-Count"); int startIndex = Utils.headerToInt(headers, "Start-Index"); int nextOffset = Utils.headerToInt(headers, "Next-Offset"); entity.setResultCount(resultCount); entity.setTotalCount(totalCount); entity.setStartIndex(startIndex); entity.setNextOffset(nextOffset); } return entity; } RepositoryRestApi(NetworkClient networkClient); }
RepositoryRestApi { @NotNull public ResourceSearchResult searchResources(@NotNull Map<String, Object> searchParams) throws IOException, HttpException { HttpUrl url = mNetworkClient.getBaseUrl() .newBuilder() .addPathSegment("rest_v2") .addPathSegment("resources") .build(); url = QueryMapper.INSTANCE.mapParams(searchParams, url); Request request = new Request.Builder() .addHeader("Accept", "application/json; charset=UTF-8") .get() .url(url) .build(); com.squareup.okhttp.Response rawResponse = mNetworkClient.makeCall(request); int status = rawResponse.code(); ResourceSearchResult entity; if (status == 204) { entity = ResourceSearchResult.empty(); } else { entity = mNetworkClient.deserializeJson(rawResponse, ResourceSearchResult.class); com.squareup.okhttp.Headers headers = rawResponse.headers(); int resultCount = Utils.headerToInt(headers, "Result-Count"); int totalCount = Utils.headerToInt(headers, "Total-Count"); int startIndex = Utils.headerToInt(headers, "Start-Index"); int nextOffset = Utils.headerToInt(headers, "Next-Offset"); entity.setResultCount(resultCount); entity.setTotalCount(totalCount); entity.setStartIndex(startIndex); entity.setNextOffset(nextOffset); } return entity; } RepositoryRestApi(NetworkClient networkClient); @NotNull ResourceSearchResult searchResources(@NotNull Map<String, Object> searchParams); @NotNull ResourceLookup requestResource(@NotNull String resourceUri, @NotNull String type); @NotNull DashboardComponentCollection requestDashboardComponents(@NotNull String dashboardUri); @NotNull OutputResource requestResourceOutput(@NotNull String resourceUri); }
RepositoryRestApi { @NotNull public ResourceSearchResult searchResources(@NotNull Map<String, Object> searchParams) throws IOException, HttpException { HttpUrl url = mNetworkClient.getBaseUrl() .newBuilder() .addPathSegment("rest_v2") .addPathSegment("resources") .build(); url = QueryMapper.INSTANCE.mapParams(searchParams, url); Request request = new Request.Builder() .addHeader("Accept", "application/json; charset=UTF-8") .get() .url(url) .build(); com.squareup.okhttp.Response rawResponse = mNetworkClient.makeCall(request); int status = rawResponse.code(); ResourceSearchResult entity; if (status == 204) { entity = ResourceSearchResult.empty(); } else { entity = mNetworkClient.deserializeJson(rawResponse, ResourceSearchResult.class); com.squareup.okhttp.Headers headers = rawResponse.headers(); int resultCount = Utils.headerToInt(headers, "Result-Count"); int totalCount = Utils.headerToInt(headers, "Total-Count"); int startIndex = Utils.headerToInt(headers, "Start-Index"); int nextOffset = Utils.headerToInt(headers, "Next-Offset"); entity.setResultCount(resultCount); entity.setTotalCount(totalCount); entity.setStartIndex(startIndex); entity.setNextOffset(nextOffset); } return entity; } RepositoryRestApi(NetworkClient networkClient); @NotNull ResourceSearchResult searchResources(@NotNull Map<String, Object> searchParams); @NotNull ResourceLookup requestResource(@NotNull String resourceUri, @NotNull String type); @NotNull DashboardComponentCollection requestDashboardComponents(@NotNull String dashboardUri); @NotNull OutputResource requestResourceOutput(@NotNull String resourceUri);  }