@Test public void testHtmlProcessorRuleNonNullObjects() { PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class); RuleType mockRuleType = Mockito.mock(RuleType.class); TargetType mockTargetType = Mockito.mock(TargetType.class); AdviceExpressionsType mockAdvice = Mockito.mock(AdviceExpressionsType.class); ObligationExpressionsType mockObEx = Mockito.mock(ObligationExpressionsType.class); AdviceExpressionType adviceExpTypeMock = Mockito.mock(AdviceExpressionType.class); ObligationExpressionType mockObExType = Mockito.mock(ObligationExpressionType.class); EffectType effectTypePermit = EffectType.PERMIT; processor = new HtmlProcessor(temp, mockPolicySetType); List<AnyOfType> anyOfList = new ArrayList<AnyOfType>(); anyOfList.add(new AnyOfType()); List<AdviceExpressionType> adviceList = new ArrayList<AdviceExpressionType>(); adviceList.add(adviceExpTypeMock); List<AttributeAssignmentExpressionType> attrList = new ArrayList<AttributeAssignmentExpressionType>(); List<ObligationExpressionType> obExList = new ArrayList<ObligationExpressionType>(); obExList.add(mockObExType); List<Object> contentList = new ArrayList<>(); contentList.add(new Object()); when(mockRuleType.getRuleId()).thenReturn(""); when(mockRuleType.getTarget()).thenReturn(mockTargetType); when(mockRuleType.getEffect()).thenReturn(effectTypePermit); when(mockTargetType.getAnyOf()).thenReturn(anyOfList); when(mockRuleType.getAdviceExpressions()).thenReturn(mockAdvice); when(mockAdvice.getAdviceExpression()).thenReturn(adviceList); when(mockRuleType.getObligationExpressions()).thenReturn(mockObEx); when(mockObEx.getObligationExpression()).thenReturn(obExList); when(mockObExType.getAttributeAssignmentExpression()).thenReturn(null); when(mockObExType.getFulfillOn()).thenReturn(effectTypePermit); when(adviceExpTypeMock.getAdviceId()).thenReturn(""); when(adviceExpTypeMock.getAppliesTo()).thenReturn(effectTypePermit); when(adviceExpTypeMock.getAttributeAssignmentExpression()).thenReturn(attrList); processor.rule(mockRuleType); verify(mockRuleType, atLeast(1)).getRuleId(); verify(mockRuleType, atLeast(1)).getTarget(); verify(mockRuleType, atLeast(1)).getEffect(); verify(mockRuleType, atLeast(1)).getAdviceExpressions(); verify(mockRuleType, atLeast(1)).getObligationExpressions(); verify(mockTargetType, atLeast(1)).getAnyOf(); verify(mockObEx, atLeast(1)).getObligationExpression(); verify(mockObExType, atLeast(1)).getAttributeAssignmentExpression(); verify(mockObExType, atLeast(1)).getFulfillOn(); verify(mockAdvice, atLeast(1)).getAdviceExpression(); verify(adviceExpTypeMock, atLeast(1)).getAdviceId(); verify(adviceExpTypeMock, atLeast(1)).getAppliesTo(); verify(adviceExpTypeMock, atLeast(1)).getAttributeAssignmentExpression(); }
public void rule(RuleType rule) { String id = "-"; if (rule.getRuleId() != null) { id = extractLastIdentifier(rule.getRuleId(), ":"); } htmlOut.println("<li><b>Rule ID</b>: <i>" + id + "</i></li>"); htmlOut.println("<dl>"); htmlOut.print("<p>"); htmlOut.print(rule.getEffect().value()); if (rule.getTarget() == null || rule.getTarget().getAnyOf() == null || rule.getTarget().getAnyOf().isEmpty()) { htmlOut.print(" for all requests"); } else { htmlOut.print(" for requests with attributes "); target(rule.getTarget().getAnyOf()); } if (rule.getCondition() != null) { htmlOut.print(" when "); htmlOut.println(this.stringifyCondition(rule.getCondition()) + " "); } else { htmlOut.print(" with no conditions "); } if (rule.getAdviceExpressions() != null) { advice(rule.getAdviceExpressions()); if (rule.getObligationExpressions() != null) { htmlOut.println(" and "); } } if (rule.getObligationExpressions() != null) { obligation(rule.getObligationExpressions()); } htmlOut.println("</p>"); }
HtmlProcessor extends SimpleCallback { public void rule(RuleType rule) { String id = "-"; if (rule.getRuleId() != null) { id = extractLastIdentifier(rule.getRuleId(), ":"); } htmlOut.println("<li><b>Rule ID</b>: <i>" + id + "</i></li>"); htmlOut.println("<dl>"); htmlOut.print("<p>"); htmlOut.print(rule.getEffect().value()); if (rule.getTarget() == null || rule.getTarget().getAnyOf() == null || rule.getTarget().getAnyOf().isEmpty()) { htmlOut.print(" for all requests"); } else { htmlOut.print(" for requests with attributes "); target(rule.getTarget().getAnyOf()); } if (rule.getCondition() != null) { htmlOut.print(" when "); htmlOut.println(this.stringifyCondition(rule.getCondition()) + " "); } else { htmlOut.print(" with no conditions "); } if (rule.getAdviceExpressions() != null) { advice(rule.getAdviceExpressions()); if (rule.getObligationExpressions() != null) { htmlOut.println(" and "); } } if (rule.getObligationExpressions() != null) { obligation(rule.getObligationExpressions()); } htmlOut.println("</p>"); } }
HtmlProcessor extends SimpleCallback { public void rule(RuleType rule) { String id = "-"; if (rule.getRuleId() != null) { id = extractLastIdentifier(rule.getRuleId(), ":"); } htmlOut.println("<li><b>Rule ID</b>: <i>" + id + "</i></li>"); htmlOut.println("<dl>"); htmlOut.print("<p>"); htmlOut.print(rule.getEffect().value()); if (rule.getTarget() == null || rule.getTarget().getAnyOf() == null || rule.getTarget().getAnyOf().isEmpty()) { htmlOut.print(" for all requests"); } else { htmlOut.print(" for requests with attributes "); target(rule.getTarget().getAnyOf()); } if (rule.getCondition() != null) { htmlOut.print(" when "); htmlOut.println(this.stringifyCondition(rule.getCondition()) + " "); } else { htmlOut.print(" with no conditions "); } if (rule.getAdviceExpressions() != null) { advice(rule.getAdviceExpressions()); if (rule.getObligationExpressions() != null) { htmlOut.println(" and "); } } if (rule.getObligationExpressions() != null) { obligation(rule.getObligationExpressions()); } htmlOut.println("</p>"); } HtmlProcessor(File policyFile, Object policyObject); }
HtmlProcessor extends SimpleCallback { public void rule(RuleType rule) { String id = "-"; if (rule.getRuleId() != null) { id = extractLastIdentifier(rule.getRuleId(), ":"); } htmlOut.println("<li><b>Rule ID</b>: <i>" + id + "</i></li>"); htmlOut.println("<dl>"); htmlOut.print("<p>"); htmlOut.print(rule.getEffect().value()); if (rule.getTarget() == null || rule.getTarget().getAnyOf() == null || rule.getTarget().getAnyOf().isEmpty()) { htmlOut.print(" for all requests"); } else { htmlOut.print(" for requests with attributes "); target(rule.getTarget().getAnyOf()); } if (rule.getCondition() != null) { htmlOut.print(" when "); htmlOut.println(this.stringifyCondition(rule.getCondition()) + " "); } else { htmlOut.print(" with no conditions "); } if (rule.getAdviceExpressions() != null) { advice(rule.getAdviceExpressions()); if (rule.getObligationExpressions() != null) { htmlOut.println(" and "); } } if (rule.getObligationExpressions() != null) { obligation(rule.getObligationExpressions()); } htmlOut.println("</p>"); } HtmlProcessor(File policyFile, Object policyObject); Map<String, AttributeIdentifiers> getAttributeIdentifiersMap(); @Override void onFinishScan(Object root); @Override CallbackResult onPreVisitPolicySet(PolicySetType parent, PolicySetType policySet); @Override CallbackResult onPostVisitPolicySet(PolicySetType parent, PolicySetType policySet); void policySet(PolicySetType policySet, String htmlListElement); @Override CallbackResult onPreVisitPolicy(PolicySetType parent, PolicyType policy); @Override CallbackResult onPostVisitPolicy(PolicySetType parent, PolicyType policy); void policy(PolicyType policy); @Override CallbackResult onPreVisitRule(PolicyType parent, RuleType rule); @Override CallbackResult onPostVisitRule(PolicyType parent, RuleType rule); void rule(RuleType rule); void target(List<AnyOfType> anyOfList); String html(); }
HtmlProcessor extends SimpleCallback { public void rule(RuleType rule) { String id = "-"; if (rule.getRuleId() != null) { id = extractLastIdentifier(rule.getRuleId(), ":"); } htmlOut.println("<li><b>Rule ID</b>: <i>" + id + "</i></li>"); htmlOut.println("<dl>"); htmlOut.print("<p>"); htmlOut.print(rule.getEffect().value()); if (rule.getTarget() == null || rule.getTarget().getAnyOf() == null || rule.getTarget().getAnyOf().isEmpty()) { htmlOut.print(" for all requests"); } else { htmlOut.print(" for requests with attributes "); target(rule.getTarget().getAnyOf()); } if (rule.getCondition() != null) { htmlOut.print(" when "); htmlOut.println(this.stringifyCondition(rule.getCondition()) + " "); } else { htmlOut.print(" with no conditions "); } if (rule.getAdviceExpressions() != null) { advice(rule.getAdviceExpressions()); if (rule.getObligationExpressions() != null) { htmlOut.println(" and "); } } if (rule.getObligationExpressions() != null) { obligation(rule.getObligationExpressions()); } htmlOut.println("</p>"); } HtmlProcessor(File policyFile, Object policyObject); Map<String, AttributeIdentifiers> getAttributeIdentifiersMap(); @Override void onFinishScan(Object root); @Override CallbackResult onPreVisitPolicySet(PolicySetType parent, PolicySetType policySet); @Override CallbackResult onPostVisitPolicySet(PolicySetType parent, PolicySetType policySet); void policySet(PolicySetType policySet, String htmlListElement); @Override CallbackResult onPreVisitPolicy(PolicySetType parent, PolicyType policy); @Override CallbackResult onPostVisitPolicy(PolicySetType parent, PolicyType policy); void policy(PolicyType policy); @Override CallbackResult onPreVisitRule(PolicyType parent, RuleType rule); @Override CallbackResult onPostVisitRule(PolicyType parent, RuleType rule); void rule(RuleType rule); void target(List<AnyOfType> anyOfList); String html();  }