Search in sources :

Example 1 with Builder

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);
    }
}
Also used : RawReportDownloadResponse(com.google.api.ads.adwords.lib.utils.RawReportDownloadResponse) ReportDownloadResponse(com.google.api.ads.adwords.lib.utils.ReportDownloadResponse) ReportRequest(com.google.api.ads.adwords.lib.utils.ReportRequest) Builder(com.google.api.ads.adwords.lib.utils.v201809.DetailedReportDownloadResponseException.Builder) ReportDefinition(com.google.api.ads.adwords.lib.jaxb.v201809.ReportDefinition) Selector(com.google.api.ads.adwords.lib.jaxb.v201809.Selector)

Aggregations

ReportDefinition (com.google.api.ads.adwords.lib.jaxb.v201809.ReportDefinition)1 Selector (com.google.api.ads.adwords.lib.jaxb.v201809.Selector)1 RawReportDownloadResponse (com.google.api.ads.adwords.lib.utils.RawReportDownloadResponse)1 ReportDownloadResponse (com.google.api.ads.adwords.lib.utils.ReportDownloadResponse)1 ReportRequest (com.google.api.ads.adwords.lib.utils.ReportRequest)1 Builder (com.google.api.ads.adwords.lib.utils.v201809.DetailedReportDownloadResponseException.Builder)1