@Test public void createReportOptionShouldNotAllowNullOptionLabel() throws Exception { mExpectedException.expect(NullPointerException.class); mExpectedException.expectMessage("Option label should not be null"); restApiUnderTest.createReportOption("any_id", null, REPORT_PARAMS, false); }
@NotNull public ReportOptionEntity createReportOption( @NotNull String reportUnitUri, @NotNull String optionLabel, @NotNull List<ReportParameter> parameters, boolean overwrite) throws IOException, HttpException { Utils.checkNotNull(reportUnitUri, "Report uri should not be null"); Utils.checkNotNull(optionLabel, "Option label should not be null"); Utils.checkNotNull(parameters, "Parameters values should not be null"); HttpUrl url = new PathResolver.Builder() .addPath("rest_v2") .addPath("reports") .addPaths(reportUnitUri) .addPath("options") .build() .resolve(mNetworkClient.getBaseUrl()) .newBuilder() .addQueryParameter("label", optionLabel) .addQueryParameter("overwrite", String.valueOf(overwrite)) .build(); Map<String, Set<String>> controlsValues = ReportParamsMapper.INSTANCE.toMap(parameters); RequestBody requestBody = mNetworkClient.createJsonRequestBody(controlsValues); Request request = new Request.Builder() .addHeader("Accept", "application/json; charset=UTF-8") .post(requestBody) .url(url) .build(); Response response = mNetworkClient.makeCall(request); return mNetworkClient.deserializeJson(response, ReportOptionEntity.class); }
ReportOptionRestApi { @NotNull public ReportOptionEntity createReportOption( @NotNull String reportUnitUri, @NotNull String optionLabel, @NotNull List<ReportParameter> parameters, boolean overwrite) throws IOException, HttpException { Utils.checkNotNull(reportUnitUri, "Report uri should not be null"); Utils.checkNotNull(optionLabel, "Option label should not be null"); Utils.checkNotNull(parameters, "Parameters values should not be null"); HttpUrl url = new PathResolver.Builder() .addPath("rest_v2") .addPath("reports") .addPaths(reportUnitUri) .addPath("options") .build() .resolve(mNetworkClient.getBaseUrl()) .newBuilder() .addQueryParameter("label", optionLabel) .addQueryParameter("overwrite", String.valueOf(overwrite)) .build(); Map<String, Set<String>> controlsValues = ReportParamsMapper.INSTANCE.toMap(parameters); RequestBody requestBody = mNetworkClient.createJsonRequestBody(controlsValues); Request request = new Request.Builder() .addHeader("Accept", "application/json; charset=UTF-8") .post(requestBody) .url(url) .build(); Response response = mNetworkClient.makeCall(request); return mNetworkClient.deserializeJson(response, ReportOptionEntity.class); } }
ReportOptionRestApi { @NotNull public ReportOptionEntity createReportOption( @NotNull String reportUnitUri, @NotNull String optionLabel, @NotNull List<ReportParameter> parameters, boolean overwrite) throws IOException, HttpException { Utils.checkNotNull(reportUnitUri, "Report uri should not be null"); Utils.checkNotNull(optionLabel, "Option label should not be null"); Utils.checkNotNull(parameters, "Parameters values should not be null"); HttpUrl url = new PathResolver.Builder() .addPath("rest_v2") .addPath("reports") .addPaths(reportUnitUri) .addPath("options") .build() .resolve(mNetworkClient.getBaseUrl()) .newBuilder() .addQueryParameter("label", optionLabel) .addQueryParameter("overwrite", String.valueOf(overwrite)) .build(); Map<String, Set<String>> controlsValues = ReportParamsMapper.INSTANCE.toMap(parameters); RequestBody requestBody = mNetworkClient.createJsonRequestBody(controlsValues); Request request = new Request.Builder() .addHeader("Accept", "application/json; charset=UTF-8") .post(requestBody) .url(url) .build(); Response response = mNetworkClient.makeCall(request); return mNetworkClient.deserializeJson(response, ReportOptionEntity.class); } ReportOptionRestApi(NetworkClient networkClient); }
ReportOptionRestApi { @NotNull public ReportOptionEntity createReportOption( @NotNull String reportUnitUri, @NotNull String optionLabel, @NotNull List<ReportParameter> parameters, boolean overwrite) throws IOException, HttpException { Utils.checkNotNull(reportUnitUri, "Report uri should not be null"); Utils.checkNotNull(optionLabel, "Option label should not be null"); Utils.checkNotNull(parameters, "Parameters values should not be null"); HttpUrl url = new PathResolver.Builder() .addPath("rest_v2") .addPath("reports") .addPaths(reportUnitUri) .addPath("options") .build() .resolve(mNetworkClient.getBaseUrl()) .newBuilder() .addQueryParameter("label", optionLabel) .addQueryParameter("overwrite", String.valueOf(overwrite)) .build(); Map<String, Set<String>> controlsValues = ReportParamsMapper.INSTANCE.toMap(parameters); RequestBody requestBody = mNetworkClient.createJsonRequestBody(controlsValues); Request request = new Request.Builder() .addHeader("Accept", "application/json; charset=UTF-8") .post(requestBody) .url(url) .build(); Response response = mNetworkClient.makeCall(request); return mNetworkClient.deserializeJson(response, ReportOptionEntity.class); } ReportOptionRestApi(NetworkClient networkClient); @NotNull Set<ReportOptionEntity> requestReportOptionsList(
            @NotNull String reportUnitUri); @NotNull ReportOptionEntity createReportOption(
            @NotNull String reportUnitUri,
            @NotNull String optionLabel,
            @NotNull List<ReportParameter> parameters,
            boolean overwrite); void updateReportOption(
            @NotNull String reportUnitUri,
            @NotNull String optionId,
            @NotNull List<ReportParameter> parameters); void deleteReportOption(
            @Nullable String reportUnitUri,
            @Nullable String optionId); }
ReportOptionRestApi { @NotNull public ReportOptionEntity createReportOption( @NotNull String reportUnitUri, @NotNull String optionLabel, @NotNull List<ReportParameter> parameters, boolean overwrite) throws IOException, HttpException { Utils.checkNotNull(reportUnitUri, "Report uri should not be null"); Utils.checkNotNull(optionLabel, "Option label should not be null"); Utils.checkNotNull(parameters, "Parameters values should not be null"); HttpUrl url = new PathResolver.Builder() .addPath("rest_v2") .addPath("reports") .addPaths(reportUnitUri) .addPath("options") .build() .resolve(mNetworkClient.getBaseUrl()) .newBuilder() .addQueryParameter("label", optionLabel) .addQueryParameter("overwrite", String.valueOf(overwrite)) .build(); Map<String, Set<String>> controlsValues = ReportParamsMapper.INSTANCE.toMap(parameters); RequestBody requestBody = mNetworkClient.createJsonRequestBody(controlsValues); Request request = new Request.Builder() .addHeader("Accept", "application/json; charset=UTF-8") .post(requestBody) .url(url) .build(); Response response = mNetworkClient.makeCall(request); return mNetworkClient.deserializeJson(response, ReportOptionEntity.class); } ReportOptionRestApi(NetworkClient networkClient); @NotNull Set<ReportOptionEntity> requestReportOptionsList(
            @NotNull String reportUnitUri); @NotNull ReportOptionEntity createReportOption(
            @NotNull String reportUnitUri,
            @NotNull String optionLabel,
            @NotNull List<ReportParameter> parameters,
            boolean overwrite); void updateReportOption(
            @NotNull String reportUnitUri,
            @NotNull String optionId,
            @NotNull List<ReportParameter> parameters); void deleteReportOption(
            @Nullable String reportUnitUri,
            @Nullable String optionId);  }