Random generator = new Random();
int numCamp = generator.nextInt(4) + 1;
for (int i = 0; i < numCamp; i++) {
Campaign campaign = new Campaign();
campaign.setBudget(new Budget(BudgetBudgetPeriod.DAILY, new Money("USD", 1000000L),
BudgetBudgetDeliveryMethod.STANDARD));
campaign.setStatus(CampaignStatus.PAUSED);
campaign.setBiddingStrategy(new ManualCPC());
CampaignReturnValue crv =
campaignService.mutate(new CampaignOperation[] {new CampaignOperation(Operator.ADD, null,
null, campaign)});
campaign = crv.getValue()[0];
campaignTargetService.mutate(new CampaignTargetOperation[] {new CampaignTargetOperation(
Operator.SET, null, new NetworkTargetList(campaign.getId(), null,
new NetworkTarget[] {new NetworkTarget(null, NetworkCoverageType.GOOGLE_SEARCH)}))});
NegativeCampaignCriterion negativeCampaignCriterion = new NegativeCampaignCriterion();
negativeCampaignCriterion.setCampaignId(campaign.getId());
negativeCampaignCriterion.setCriterion(new Placement(null, null, "http://example.com/"));
CampaignCriterionOperation operation = new CampaignCriterionOperation();
operation.setOperator(Operator.ADD);
operation.setOperand(negativeCampaignCriterion);
campaignCriterionService.mutate(new CampaignCriterionOperation[] {operation});
int numAdGrp = generator.nextInt(6) + 1;
for (int j = 0; j < numAdGrp; j++) {
AdGroupPage adGroupPage =
adGroupService.get(new AdGroupSelector(campaign.getId(), null, null, null));
AdGroup[] adGroups = adGroupPage.getEntries();
AdGroup adGroup = null;
if (adGroups != null && j < adGroups.length) {
adGroup = adGroups[j];
} else {
adGroup = new AdGroup();
adGroup.setName("AdGroup " + (j + 1));
adGroup.setBids(new ManualCPCAdGroupBids(null, new Bid(new Money("USD",
generator.nextInt(10) * 50000L + 50000L)), null, null));
adGroup.setCampaignId(campaign.getId());
AdGroupReturnValue adGroupReturnValue =
adGroupService.mutate(new AdGroupOperation[] {new AdGroupOperation(Operator.ADD,