@Test public void testHtmlProcessorRule() { PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class); RuleType mockRuleType = Mockito.mock(RuleType.class); ConditionType mockConditionType = Mockito.mock(ConditionType.class); ObligationExpressionsType mockOESType = Mockito.mock(ObligationExpressionsType.class); ObligationExpressionType mockOEType = Mockito.mock(ObligationExpressionType.class); EffectType effectTypePermit = EffectType.PERMIT; processor = new HtmlProcessor(temp, mockPolicySetType); List<ObligationExpressionType> oblList = new ArrayList<ObligationExpressionType>(); oblList.add(mockOEType); when(mockRuleType.getEffect()).thenReturn(effectTypePermit); when(mockRuleType.getRuleId()).thenReturn(null); when(mockRuleType.getTarget()).thenReturn(null); when(mockRuleType.getCondition()).thenReturn(mockConditionType); when(mockRuleType.getObligationExpressions()).thenReturn(mockOESType); when(mockOESType.getObligationExpression()).thenReturn(oblList); when(mockOEType.getFulfillOn()).thenReturn(effectTypePermit); processor.rule(mockRuleType); verify(mockRuleType, atLeast(1)).getRuleId(); verify(mockRuleType, atLeast(1)).getTarget(); verify(mockRuleType, atLeast(1)).getCondition(); verify(mockRuleType, atLeast(1)).getObligationExpressions(); verify(mockOESType, atLeast(1)).getObligationExpression(); verify(mockOEType, atLeast(1)).getFulfillOn(); JAXBElement<?> mockJaxBElement = Mockito.mock(JAXBElement.class); Object mockValueObject = Mockito.mock(Object.class); doReturn(mockJaxBElement).when(mockConditionType).getExpression(); doReturn(mockValueObject).when(mockJaxBElement).getValue(); try { processor.rule(mockRuleType); fail(); } catch (IllegalArgumentException e) { verify(mockConditionType, atLeast(1)).getExpression(); verify(mockJaxBElement, atLeast(1)).getValue(); } }
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();  }