use of com.google.api.ads.adwords.axis.v201809.cm.Ad in project googleads-java-lib by googleads.
the class ProductPartitionTreeTest method testCreateMultiNodeTreeFromScratch.
/**
* Tests creating an empty tree and then adding several levels of nodes.
*/
@Test
public void testCreateMultiNodeTreeFromScratch() {
ProductPartitionTree tree = ProductPartitionTree.createAdGroupTree(-1L, biddingStrategyConfig, Collections.<AdGroupCriterion>emptyList());
ProductPartitionNode rootNode = tree.getRoot().asSubdivision();
ProductPartitionNode brand1 = rootNode.addChild(ProductDimensions.createBrand("google")).asSubdivision();
ProductPartitionNode brand1Offer1 = brand1.addChild(ProductDimensions.createOfferId("A")).asBiddableUnit().setBid(1000000L).putCustomParameter("param1", "value1").putCustomParameter("param2", "value2");
ProductPartitionNode brand1Offer2 = brand1.addChild(ProductDimensions.createOfferId(null)).asExcludedUnit();
ProductPartitionNode brand2 = rootNode.addChild(ProductDimensions.createBrand(null)).asExcludedUnit();
int expectedOpCount = 5;
List<AdGroupCriterionOperation> mutateOperations = tree.getMutateOperations();
assertEquals("Number of operations is incorrect", expectedOpCount, mutateOperations.size());
List<CriterionDescriptor> nodeDescriptors = Stream.of(rootNode, brand1, brand1Offer1, brand1Offer2, brand2).map(CriterionDescriptor::new).collect(Collectors.toList());
int opNum = 0;
List<CriterionDescriptor> opDescriptors = Lists.newArrayList();
Map<Long, CriterionDescriptor> opDescriptorsById = Maps.newHashMap();
for (AdGroupCriterionOperation op : mutateOperations) {
CriterionDescriptor opDescriptor = new CriterionDescriptor(op.getOperand(), opNum++);
opDescriptors.add(opDescriptor);
opDescriptorsById.put(opDescriptor.partitionId, opDescriptor);
}
Map<Long, Map<Long, CriterionDescriptor>> opDescriptorMap = buildDescriptorMap(opDescriptors);
for (CriterionDescriptor nodeDescriptor : nodeDescriptors) {
CriterionDescriptor opDescriptor = opDescriptorMap.get(nodeDescriptor.parentPartitionId).get(nodeDescriptor.partitionId);
nodeDescriptor.assertDescriptorEquals(opDescriptor);
AdGroupCriterionOperation op = mutateOperations.get(opDescriptor.operationNumber);
assertEquals("operator is incorrect", Operator.ADD, op.getOperator());
if (nodeDescriptor.parentPartitionId != null) {
CriterionDescriptor parentOpDescriptor = opDescriptorsById.get(nodeDescriptor.parentPartitionId);
assertNotNull("no operation found for parent", parentOpDescriptor);
assertThat("operation # for parent is > operation # for child", opDescriptor.operationNumber, Matchers.greaterThan(parentOpDescriptor.operationNumber));
}
}
assertThat("Tree toString does not contain the root's detailed toString", tree.toString(), Matchers.containsString(tree.getRoot().toDetailedString()));
assertThat("Tree toString does not contain the ad group ID", tree.toString(), Matchers.containsString(tree.getAdGroupId().toString()));
}
Aggregations