geoTargetList.setCampaignId(campaignId);
geoTargetList.setTargets(new GeoTarget[] {new CountryTarget(null, false, "US"),
new CountryTarget(null, false, "JP")});
// Create network targets.
NetworkTargetList networkTargetList = new NetworkTargetList();
networkTargetList.setCampaignId(campaignId);
networkTargetList.setTargets(new NetworkTarget[] {
// Specifying GOOGLE_SEARCH is necessary if you want to target
// SEARCH_NETWORK.
new NetworkTarget(null, NetworkCoverageType.GOOGLE_SEARCH),
new NetworkTarget(null, NetworkCoverageType.SEARCH_NETWORK)});
CampaignTargetOperation languageTargetOperation = new CampaignTargetOperation();
languageTargetOperation.setOperand(languageTargetList);
languageTargetOperation.setOperator(Operator.SET);
CampaignTargetOperation geoTargetOperation = new CampaignTargetOperation();
geoTargetOperation.setOperand(geoTargetList);
geoTargetOperation.setOperator(Operator.SET);
CampaignTargetOperation networkTargetOperation = new CampaignTargetOperation();
networkTargetOperation.setOperand(networkTargetList);
networkTargetOperation.setOperator(Operator.SET);
CampaignTargetOperation[] operations = new CampaignTargetOperation[] {languageTargetOperation,
geoTargetOperation, networkTargetOperation};
// Set campaign targets.
CampaignTargetReturnValue result = service.mutate(operations);
// Exclude generated fields and test objects.
if (result != null && result.getValue() != null) {
for (TargetList testList : result.getValue()) {
if (testList.getTargetListType().equals("LanguageTargetList")) {
languageTargetList.setTargetListType(testList.getTargetListType());
for (LanguageTarget languageTarget : languageTargetList.getTargets()) {
languageTarget.setTargetType(((LanguageTarget) ((LanguageTargetList) testList)
.getTargets()[0]).getTargetType());
}
TestUtils.assertDeepReflectionEquals(languageTargetList, testList);
} else if (testList.getTargetListType().equals("GeoTargetList")) {
geoTargetList.setTargetListType(testList.getTargetListType());
for (GeoTarget geoTarget : geoTargetList.getTargets()){
geoTarget.setTargetType(((GeoTarget)((GeoTargetList) testList)
.getTargets()[0]).getTargetType());
}
TestUtils.assertDeepReflectionEquals(geoTargetList, testList);
} else if (testList.getTargetListType().equals("NetworkTargetList")) {
networkTargetList.setTargetListType(testList.getTargetListType());
for (NetworkTarget networkTarget : networkTargetList.getTargets()){
networkTarget.setTargetType(((NetworkTarget)((NetworkTargetList) testList)
.getTargets()[0]).getTargetType());
}
TestUtils.assertDeepReflectionEquals(networkTargetList, testList);
}