@Test
public void testWithTargetTypeWithAnyOf() throws IOException {

    //
    // Create TargetType with empty AnyOf
    //
    AttributeValueType value = new AttributeValueType();
    value.setDataType(XACML3.ID_DATATYPE_STRING.stringValue());
    value.getContent().add(new String("value"));
    AttributeDesignatorType designator = new AttributeDesignatorType();
    designator.setAttributeId("foo:bar");
    designator.setDataType(XACML3.ID_DATATYPE_STRING.stringValue());
    designator.setCategory(XACML3.ID_ATTRIBUTE_CATEGORY_ACTION.stringValue());
    MatchType match = new MatchType();
    match.setMatchId(XACML3.ID_FUNCTION_STRING_EQUAL.stringValue());
    match.setAttributeValue(value);
    match.setAttributeDesignator(designator);
    AllOfType allOf = new AllOfType();
    allOf.getMatch().add(match);
    AnyOfType anyOf = new AnyOfType();
    anyOf.getAllOf().add(allOf);
    TargetType target = new TargetType();
    target.getAnyOf().add(anyOf);
    //
    // Create a simple Rule with NO obligations but a Condition
    //
    RuleType rule = new RuleType();
    rule.setRuleId("id:rule");
    rule.setEffect(EffectType.PERMIT);
    AttributeValueType expressionValue = new AttributeValueType();
    expressionValue.setDataType(XACML3.ID_DATATYPE_STRING.stringValue());
    expressionValue.getContent().add(new String("a string value"));
    designator = new AttributeDesignatorType();
    designator.setAttributeId("foo:bar");
    designator.setDataType(XACML3.ID_DATATYPE_STRING.stringValue());
    designator.setCategory(XACML3.ID_ATTRIBUTE_CATEGORY_ACTION.stringValue());
    ApplyType applyOneAndOnly = new ApplyType();
    applyOneAndOnly.setDescription("apply this");
    applyOneAndOnly.setFunctionId(XACML3.ID_FUNCTION_STRING_ONE_AND_ONLY.stringValue());
    applyOneAndOnly.getExpression().add(new ObjectFactory().createAttributeDesignator(designator));
    ApplyType applyOneAndOnly2 = new ApplyType();
    applyOneAndOnly2.setDescription("apply this");
    applyOneAndOnly2.setFunctionId(XACML3.ID_FUNCTION_STRING_ONE_AND_ONLY.stringValue());
    applyOneAndOnly2.getExpression().add(new ObjectFactory().createAttributeValue(expressionValue));
    ApplyType apply = new ApplyType();
    apply.setDescription("apply this");
    apply.setFunctionId(XACML3.ID_FUNCTION_STRING_EQUAL.stringValue());
    apply.getExpression().add(new ObjectFactory().createApply(applyOneAndOnly));
    apply.getExpression().add(new ObjectFactory().createApply(applyOneAndOnly2));
    ConditionType condition = new ConditionType();
    condition.setExpression(new ObjectFactory().createApply(apply));
    rule.setCondition(condition);
    //
    // Create a simple Rule WITH obligations
    //
    AttributeValueType val = new AttributeValueType();
    val.setDataType(XACML3.ID_DATATYPE_STRING.stringValue());
    val.getContent().add(new String("obligation data"));
    AttributeAssignmentExpressionType assignment = new AttributeAssignmentExpressionType();
    assignment.setAttributeId("ob:id:1");
    assignment.setCategory(XACML3.ID_SUBJECT_CATEGORY_ACCESS_SUBJECT.stringValue());
    assignment.setExpression(new ObjectFactory().createAttributeValue(val));
    AttributeValueType val2 = new AttributeValueType();
    val2.setDataType(XACML3.ID_DATATYPE_STRING.stringValue());
    val2.getContent().add(new String("iamperformer"));
    AttributeAssignmentExpressionType assignment2 = new AttributeAssignmentExpressionType();
    assignment2.setAttributeId("performer");
    assignment2.setCategory(XACML3.ID_SUBJECT_CATEGORY_ACCESS_SUBJECT.stringValue());
    assignment2.setExpression(new ObjectFactory().createAttributeValue(val2));
    ObligationExpressionType ob = new ObligationExpressionType();
    ob.setFulfillOn(EffectType.PERMIT);
    ob.setObligationId("id:obligation");
    ob.getAttributeAssignmentExpression().add(assignment);
    ob.getAttributeAssignmentExpression().add(assignment2);
    ObligationExpressionsType obs = new ObligationExpressionsType();
    obs.getObligationExpression().add(ob);
    RuleType obligationRule = new RuleType();
    obligationRule.setRuleId("id:rule:obligations");
    obligationRule.setEffect(EffectType.DENY);
    obligationRule.setObligationExpressions(obs);
    //
    // Create a PolicyType
    //
    PolicyType policy = new PolicyType();
    policy.setDescription("i am a description. @CreatedBy: policy designer");
    policy.setTarget(target);
    policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(rule);
    policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(obligationRule);
    //
    // Add something the ActionPolicyController will skip over
    // to catch that branch
    //
    policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().add(new VariableDefinitionType());
    //
    // Now do the test - description and
    // TargetType but its empty
    //
    PolicyRestAdapter adapter = new PolicyRestAdapter();
    adapter.setPolicyData(policy);
    adapter.setPolicyName("name");
    ActionPolicyController controller = new ActionPolicyController();
    assertThatCode(() -> controller.prePopulateActionPolicyData(adapter)).doesNotThrowAnyException();
}