/** Tests building a report query with {@link Iterable} fields. */ @Test public void testBuildWithIterableFields() { String expectedAwql = "SELECT CampaignId, CampaignName FROM AUDIENCE_PERFORMANCE_REPORT"; ReportQueryInterface reportQuery = new ReportQuery.Builder() .fields(Arrays.asList("CampaignId", "CampaignName")) .from(ReportDefinitionReportType.AUDIENCE_PERFORMANCE_REPORT) .build(); assertEquals(expectedAwql, reportQuery.toString()); checkUtilitiesState(); }
/** Tests building a report query. */ @Test public void testBuild() { String expectedAwql = "SELECT CampaignId, CampaignName FROM CAMPAIGN_PERFORMANCE_REPORT WHERE " + "CampaignStatus = \"ENABLED\" DURING 20170101,20170131"; ReportQueryInterface reportQuery = new ReportQuery.Builder() .fields("CampaignId", "CampaignName") .from(ReportDefinitionReportType.CAMPAIGN_PERFORMANCE_REPORT) .where("CampaignStatus").equalTo("ENABLED") .during(new LocalDate(2017, 1, 1), new LocalDate(2017, 1, 31)) .build(); assertEquals(expectedAwql, reportQuery.toString()); checkUtilitiesState(); }
/** Tests building a report query duplicate fields. The order of the fields should be kept. */ @Test public void testBuild_duplicateFieldsStay() { String expectedAwql = "SELECT Id, Impressions, Id FROM AUDIENCE_PERFORMANCE_REPORT"; // fields() accepting varags. ReportQueryInterface reportQuery = new ReportQuery.Builder() .fields("Id", "Impressions", "Id") .from(ReportDefinitionReportType.AUDIENCE_PERFORMANCE_REPORT) .build(); assertEquals(expectedAwql, reportQuery.toString()); checkUtilitiesState(); expectedAwql = "SELECT Id, Impressions, Id FROM AUDIENCE_PERFORMANCE_REPORT"; // fields() accepting Iterable. reportQuery = new ReportQuery.Builder() .fields(Arrays.asList("Id", "Impressions", "Id")) .from(ReportDefinitionReportType.AUDIENCE_PERFORMANCE_REPORT) .build(); assertEquals(expectedAwql, reportQuery.toString()); }
.from(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT) .where("Clicks").greaterThan(200) .build(); .from(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT) .where("Clicks").greaterThan(200L) .build(); .from(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT) .where("Conversions").greaterThan(200.550000) .build();
.from(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT) .where("Clicks").equalTo(200) .build(); .from(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT) .where("Clicks").equalTo(200L) .build(); .from(ReportDefinitionReportType.CAMPAIGN_PERFORMANCE_REPORT) .where("IsBudgetExplicitlyShared").equalTo(true) .build();
.from(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT) .where("Clicks").notEqualTo(200) .build(); .from(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT) .where("Clicks").notEqualTo(200L) .build(); .from(ReportDefinitionReportType.CAMPAIGN_PERFORMANCE_REPORT) .where("IsBudgetExplicitlyShared").notEqualTo(true) .build();
/** Tests the LESS_THAN_OR_EQUAL_TO WHERE clause. */ @Test public void testLessThanOrEqualToWhereClause() { String expectedAwql = "SELECT Id, CampaignName FROM CRITERIA_PERFORMANCE_REPORT WHERE Clicks <= 200"; ReportQueryInterface reportQuery = new ReportQuery.Builder() .fields("Id", "CampaignName") .from(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT) .where("Clicks").lessThanOrEqualTo(200) .build(); assertEquals(expectedAwql, reportQuery.toString()); checkUtilitiesState(); reportQuery = new ReportQuery.Builder() .fields("Id", "CampaignName") .from(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT) .where("Clicks").lessThanOrEqualTo(200L) .build(); assertEquals(expectedAwql, reportQuery.toString()); expectedAwql = "SELECT Id, CampaignName FROM CRITERIA_PERFORMANCE_REPORT WHERE Conversions <= 200.550000"; reportQuery = new ReportQuery.Builder() .fields("Id", "CampaignName") .from(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT) .where("Conversions").lessThanOrEqualTo(200.550000) .build(); assertEquals(expectedAwql, reportQuery.toString()); }
.from(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT) .where("Clicks").lessThan(200) .build(); .from(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT) .where("Clicks").lessThan(200L) .build(); .from(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT) .where("Conversions").lessThan(200.550000) .build();
.from(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT) .where("Clicks").greaterThanOrEqualTo(200) .build(); .from(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT) .where("Clicks").greaterThanOrEqualTo(200L) .build(); .from(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT) .where("Conversions").greaterThanOrEqualTo(200.550000) .build();
/** Tests building a report query with multiple "select"s. The last call should stick. */ @Test public void testBuild_multipleSelects() { String expectedAwql = "SELECT Id FROM CRITERIA_PERFORMANCE_REPORT"; // fields() accepting varags. ReportQueryInterface reportQuery = new ReportQuery.Builder() .fields("Id", "Impressions", "Id") .fields("Id") .from(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT) .build(); assertEquals(expectedAwql, reportQuery.toString()); checkUtilitiesState(); expectedAwql = "SELECT Id FROM CRITERIA_PERFORMANCE_REPORT"; // fields() accepting Iterable. reportQuery = new ReportQuery.Builder() .fields(Arrays.asList("Id", "Impressions", "Id")) .fields("Id") .from(ReportDefinitionReportType.CRITERIA_PERFORMANCE_REPORT) .build(); assertEquals(expectedAwql, reportQuery.toString()); }
/** Tests building a report query with multiple string values of the WHERE clause. */ @Test public void testBuildMultipleStringwhereValues() { String expectedAwql = "SELECT CampaignId, CampaignName FROM AD_PERFORMANCE_REPORT WHERE " + "CampaignName CONTAINS_ALL [\"white\", \"black\"]"; ReportQueryInterface reportQuery = new ReportQuery.Builder() .fields("CampaignId", "CampaignName") .from(ReportDefinitionReportType.AD_PERFORMANCE_REPORT) .where("CampaignName").containsAll("white", "black") .build(); assertEquals(expectedAwql, reportQuery.toString()); checkUtilitiesState(); }
/** Tests building a report query with a numeric WHERE value. */ @Test public void testBuildLongwhereValue() { String expectedAwql = "SELECT CampaignId, CampaignName FROM ADGROUP_PERFORMANCE_REPORT WHERE " + "AverageCpm >= 5"; ReportQueryInterface reportQuery = new ReportQuery.Builder() .fields("CampaignId", "CampaignName") .from(ReportDefinitionReportType.ADGROUP_PERFORMANCE_REPORT) .where("AverageCpm").greaterThanOrEqualTo(5) .build(); assertEquals(expectedAwql, reportQuery.toString()); checkUtilitiesState(); }
/** Tests building a report query with a string WHERE value. */ @Test public void testBuildStringwhereValue() { String expectedAwql = "SELECT CampaignId, CampaignName FROM ADGROUP_PERFORMANCE_REPORT WHERE " + "CampaignName CONTAINS_IGNORE_CASE \"google\""; ReportQueryInterface reportQuery = new ReportQuery.Builder() .fields("CampaignId", "CampaignName") .from(ReportDefinitionReportType.ADGROUP_PERFORMANCE_REPORT) .where("CampaignName").containsIgnoreCase("google") .build(); assertEquals(expectedAwql, reportQuery.toString()); checkUtilitiesState(); }
/** Tests building a report query with enum date range. */ @Test public void testBuildWithEnumDateRange() { String expectedAwql = "SELECT CampaignId, CampaignName FROM CLICK_PERFORMANCE_REPORT " + "DURING THIS_WEEK_MON_TODAY"; ReportQueryInterface reportQuery = new ReportQuery.Builder() .fields("CampaignId", "CampaignName") .from(ReportDefinitionReportType.CLICK_PERFORMANCE_REPORT) .during(ReportDefinitionDateRangeType.THIS_WEEK_MON_TODAY) .build(); assertEquals(expectedAwql, reportQuery.toString()); checkUtilitiesState(); }
/** Tests building a report query with multiple long values of the WHERE clause. */ @Test public void testBuildMultipleLongwhereValues() { String expectedAwql = "SELECT CampaignId, CampaignName FROM AD_PERFORMANCE_REPORT WHERE " + "CampaignId IN [1234, 5678]"; ReportQueryInterface reportQuery = new ReportQuery.Builder() .fields("CampaignId", "CampaignName") .from(ReportDefinitionReportType.AD_PERFORMANCE_REPORT) .where("CampaignId").in(1234L, 5678L) .build(); assertEquals(expectedAwql, reportQuery.toString()); checkUtilitiesState(); }
/** Tests building a report query using a copy constructor. */ @Test public void testBuildWithCopyConstructor() { ReportQueryInterface.BuilderInterface oldBuilder = new ReportQuery.Builder() .fields("CampaignId", "CampaignName") .from(ReportDefinitionReportType.CAMPAIGN_PERFORMANCE_REPORT) .where("CampaignStatus").notEqualTo("ENABLED") .during(new LocalDate(2017, 1, 1), new LocalDate(2017, 1, 31)); ReportQueryInterface expectedReportQuery = oldBuilder.build(); ReportQueryInterface newReportQuery = new ReportQuery.Builder(oldBuilder).build(); assertEquals(expectedReportQuery, newReportQuery); checkUtilitiesState(); }
/** Tests failing to build a report query due to {@code fields()} not called. */ @Test public void testBuild_fails_fieldsNotCalled() { thrown.expect(IllegalStateException.class); thrown.expectMessage("use fields()"); new ReportQuery.Builder().from(ReportDefinitionReportType.CAMPAIGN_PERFORMANCE_REPORT).build(); }
/** Tests failing to build a report query due to {@code from()} not called. */ @Test public void testBuild_fails_fromNotCalled() { thrown.expect(IllegalStateException.class); thrown.expectMessage("use from()"); new ReportQuery.Builder().fields("Id").build(); }
/** Tests building a report query with string report type. */ @Test public void testBuildWithStringReportType() { String expectedAwql = "SELECT CampaignId, CampaignName FROM CAMPAIGN_PERFORMANCE_REPORT"; ReportQueryInterface reportQuery = new ReportQuery.Builder() .fields("CampaignId", "CampaignName") .from("CAMPAIGN_PERFORMANCE_REPORT") .build(); assertEquals(expectedAwql, reportQuery.toString()); checkUtilitiesState(); }
/** Tests failing to build a report query using a copy constructor. */ @Test public void testBuildWithCopyConstructor_nullArg_fails() { thrown.expect(NullPointerException.class); thrown.expectMessage("query builder"); new ReportQuery.Builder(null).build(); }