use of com.google.api.ads.adwords.lib.utils.v201809.DetailedReportDownloadResponseException.Builder in project googleads-java-lib by googleads.
the class ReportDownloaderTest method downloadReport.
/**
* Invokes {@link ReportDownloader#downloadReport(ReportDefinition)} or
* {@link ReportDownloader#downloadReport(String, DownloadFormat)}, depending on whether this
* instance is configured to use AWQL.
*
* @param downloadFormat the DownloadFormat for the request
* @param rawResponse the response to return from the mocked ad hoc helper
*/
private ReportDownloadResponse downloadReport(DownloadFormat downloadFormat, RawReportDownloadResponse rawResponse, String expectedErrorText) throws ReportException, ReportDownloadResponseException {
if (rawResponse.getHttpStatus() == 200) {
// Response indicates success, so return a ReportDownloadResponse.
when(adHocDownloadHelper.downloadReport(ArgumentMatchers.any(ReportRequest.class), ArgumentMatchers.any(Builder.class))).thenReturn(new ReportDownloadResponse(rawResponse));
} else {
// Response indicates failure, so throw an exception.
when(adHocDownloadHelper.downloadReport(ArgumentMatchers.any(ReportRequest.class), ArgumentMatchers.any(Builder.class))).thenThrow(new Builder().build(rawResponse.getHttpStatus(), expectedErrorText));
}
if (isUseAwql) {
return reportDownloader.downloadReport(AWQL_REQUEST, downloadFormat);
} else {
ReportDefinition reportDefinition = new ReportDefinition();
reportDefinition.setSelector(new Selector());
reportDefinition.getSelector().getFields().addAll(Arrays.asList("CampaignId", "CampaignName", "Impressions"));
reportDefinition.setDateRangeType(ReportDefinitionDateRangeType.LAST_7_DAYS);
reportDefinition.setReportName("Custom report");
reportDefinition.setReportType(ReportDefinitionReportType.CAMPAIGN_PERFORMANCE_REPORT);
return reportDownloader.downloadReport(reportDefinition);
}
}
Aggregations