@Test public void requestForResourceByTypeShouldNotAcceptNullType() throws Exception { mExpectedException.expect(NullPointerException.class); mExpectedException.expectMessage("Report type should not be null"); restApiUnderTest.requestResource("/", null); }
@NotNull public ResourceLookup requestResource(@NotNull String resourceUri, @NotNull String type) throws IOException, HttpException { Utils.checkNotNull(resourceUri, "Report uri should not be null"); Utils.checkNotNull(type, "Report type should not be null"); HttpUrl url = new PathResolver.Builder() .addPath("rest_v2") .addPath("resources") .addPaths(resourceUri) .build() .resolve(mNetworkClient.getBaseUrl()); Request request = new Request.Builder() .addHeader("Accept", String.format("application/repository.%s+json", type)) .get() .url(url) .build(); com.squareup.okhttp.Response rawResponse = mNetworkClient.makeCall(request); if ("file".equals(type)) { return mNetworkClient.deserializeJson(rawResponse, FileLookup.class); } if ("folder".equals(type)) { return mNetworkClient.deserializeJson(rawResponse, FolderLookup.class); } if ("reportUnit".equals(type)) { return mNetworkClient.deserializeJson(rawResponse, ReportLookup.class); } return mNetworkClient.deserializeJson(rawResponse, ResourceLookup.class); }
RepositoryRestApi { @NotNull public ResourceLookup requestResource(@NotNull String resourceUri, @NotNull String type) throws IOException, HttpException { Utils.checkNotNull(resourceUri, "Report uri should not be null"); Utils.checkNotNull(type, "Report type should not be null"); HttpUrl url = new PathResolver.Builder() .addPath("rest_v2") .addPath("resources") .addPaths(resourceUri) .build() .resolve(mNetworkClient.getBaseUrl()); Request request = new Request.Builder() .addHeader("Accept", String.format("application/repository.%s+json", type)) .get() .url(url) .build(); com.squareup.okhttp.Response rawResponse = mNetworkClient.makeCall(request); if ("file".equals(type)) { return mNetworkClient.deserializeJson(rawResponse, FileLookup.class); } if ("folder".equals(type)) { return mNetworkClient.deserializeJson(rawResponse, FolderLookup.class); } if ("reportUnit".equals(type)) { return mNetworkClient.deserializeJson(rawResponse, ReportLookup.class); } return mNetworkClient.deserializeJson(rawResponse, ResourceLookup.class); } }
RepositoryRestApi { @NotNull public ResourceLookup requestResource(@NotNull String resourceUri, @NotNull String type) throws IOException, HttpException { Utils.checkNotNull(resourceUri, "Report uri should not be null"); Utils.checkNotNull(type, "Report type should not be null"); HttpUrl url = new PathResolver.Builder() .addPath("rest_v2") .addPath("resources") .addPaths(resourceUri) .build() .resolve(mNetworkClient.getBaseUrl()); Request request = new Request.Builder() .addHeader("Accept", String.format("application/repository.%s+json", type)) .get() .url(url) .build(); com.squareup.okhttp.Response rawResponse = mNetworkClient.makeCall(request); if ("file".equals(type)) { return mNetworkClient.deserializeJson(rawResponse, FileLookup.class); } if ("folder".equals(type)) { return mNetworkClient.deserializeJson(rawResponse, FolderLookup.class); } if ("reportUnit".equals(type)) { return mNetworkClient.deserializeJson(rawResponse, ReportLookup.class); } return mNetworkClient.deserializeJson(rawResponse, ResourceLookup.class); } RepositoryRestApi(NetworkClient networkClient); }
RepositoryRestApi { @NotNull public ResourceLookup requestResource(@NotNull String resourceUri, @NotNull String type) throws IOException, HttpException { Utils.checkNotNull(resourceUri, "Report uri should not be null"); Utils.checkNotNull(type, "Report type should not be null"); HttpUrl url = new PathResolver.Builder() .addPath("rest_v2") .addPath("resources") .addPaths(resourceUri) .build() .resolve(mNetworkClient.getBaseUrl()); Request request = new Request.Builder() .addHeader("Accept", String.format("application/repository.%s+json", type)) .get() .url(url) .build(); com.squareup.okhttp.Response rawResponse = mNetworkClient.makeCall(request); if ("file".equals(type)) { return mNetworkClient.deserializeJson(rawResponse, FileLookup.class); } if ("folder".equals(type)) { return mNetworkClient.deserializeJson(rawResponse, FolderLookup.class); } if ("reportUnit".equals(type)) { return mNetworkClient.deserializeJson(rawResponse, ReportLookup.class); } return mNetworkClient.deserializeJson(rawResponse, ResourceLookup.class); } 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 ResourceLookup requestResource(@NotNull String resourceUri, @NotNull String type) throws IOException, HttpException { Utils.checkNotNull(resourceUri, "Report uri should not be null"); Utils.checkNotNull(type, "Report type should not be null"); HttpUrl url = new PathResolver.Builder() .addPath("rest_v2") .addPath("resources") .addPaths(resourceUri) .build() .resolve(mNetworkClient.getBaseUrl()); Request request = new Request.Builder() .addHeader("Accept", String.format("application/repository.%s+json", type)) .get() .url(url) .build(); com.squareup.okhttp.Response rawResponse = mNetworkClient.makeCall(request); if ("file".equals(type)) { return mNetworkClient.deserializeJson(rawResponse, FileLookup.class); } if ("folder".equals(type)) { return mNetworkClient.deserializeJson(rawResponse, FolderLookup.class); } if ("reportUnit".equals(type)) { return mNetworkClient.deserializeJson(rawResponse, ReportLookup.class); } return mNetworkClient.deserializeJson(rawResponse, ResourceLookup.class); } 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);  }