@Test public void testHtmlProcessorStringifyExpression() { PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class); processor = new HtmlProcessor(temp, mockPolicySetType); RuleType mockRuleType = Mockito.mock(RuleType.class); ConditionType mockConditionType = Mockito.mock(ConditionType.class); JAXBElement<?> mockJAXBElement = Mockito.mock(JAXBElement.class); EffectType effectTypePermit = EffectType.PERMIT; Object mockExpressObject = Mockito.mock(Object.class); AttributeDesignatorType mockAttrDesType = Mockito.mock(AttributeDesignatorType.class); AttributeSelectorType mockAttrSelType = Mockito.mock(AttributeSelectorType.class); AttributeValueType mockAttrValType = Mockito.mock(AttributeValueType.class); VariableReferenceType mockVarRefType = Mockito.mock(VariableReferenceType.class); Object mockContentObject = Mockito.mock(Object.class); List<Object> contentList = new ArrayList<Object>(); contentList.add(mockContentObject); when(mockRuleType.getEffect()).thenReturn(effectTypePermit); when(mockRuleType.getCondition()).thenReturn(mockConditionType); doReturn(mockJAXBElement).when(mockConditionType).getExpression(); doReturn(mockExpressObject).when(mockJAXBElement).getValue(); try { processor.rule(mockRuleType); fail(); } catch (IllegalArgumentException e) { verify(mockRuleType, atLeast(1)).getEffect(); verify(mockRuleType, atLeast(1)).getCondition(); verify(mockConditionType, atLeast(1)).getExpression(); verify(mockJAXBElement, atLeast(1)).getValue(); } doReturn(mockAttrDesType).when(mockJAXBElement).getValue(); when(mockAttrDesType.getCategory()).thenReturn(""); when(mockAttrDesType.getAttributeId()).thenReturn(""); when(mockAttrDesType.getDataType()).thenReturn(""); processor.rule(mockRuleType); verify(mockJAXBElement, atLeast(1)).getValue(); verify(mockAttrDesType, atLeast(1)).getCategory(); verify(mockAttrDesType, atLeast(1)).getAttributeId(); verify(mockAttrDesType, atLeast(1)).getDataType(); doReturn(mockAttrSelType).when(mockJAXBElement).getValue(); when(mockAttrSelType.getPath()).thenReturn("SamplePath/text()"); processor.rule(mockRuleType); verify(mockJAXBElement, atLeast(1)).getValue(); verify(mockAttrSelType, atLeast(1)).getPath(); when(mockAttrSelType.getPath()).thenReturn(""); processor.rule(mockRuleType); verify(mockJAXBElement, atLeast(1)).getValue(); verify(mockAttrSelType, atLeast(1)).getPath(); doReturn(mockAttrValType).when(mockJAXBElement).getValue(); when(mockAttrValType.getContent()).thenReturn(contentList); processor.rule(mockRuleType); verify(mockJAXBElement, atLeast(1)).getValue(); verify(mockAttrValType, atLeast(1)).getContent(); doReturn(mockVarRefType).when(mockJAXBElement).getValue(); processor.rule(mockRuleType); 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();  }