@Test public void testHtmlProcessorProcessAttributeAssignments() { PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class); processor = new HtmlProcessor(temp, mockPolicySetType); RuleType mockRuleType = Mockito.mock(RuleType.class); EffectType effectTypePermit = EffectType.PERMIT; ObligationExpressionsType mockOblExsType = Mockito.mock(ObligationExpressionsType.class); ObligationExpressionType mockOblExTypeListObj = Mockito.mock(ObligationExpressionType.class); List<ObligationExpressionType> oblExTypeList = new ArrayList<ObligationExpressionType>(); oblExTypeList.add(mockOblExTypeListObj); AttributeAssignmentExpressionType mockattrAssignListObj = Mockito.mock(AttributeAssignmentExpressionType.class); List<AttributeAssignmentExpressionType> attrAssignList = new ArrayList<AttributeAssignmentExpressionType>(); attrAssignList.add(mockattrAssignListObj); JAXBElement<?> jaxbElementMock = Mockito.mock(JAXBElement.class); AttributeValueType attrValTypeMock = Mockito.mock(AttributeValueType.class); AttributeDesignatorType attrDesignTypeMock = Mockito.mock(AttributeDesignatorType.class); AttributeSelectorType attrSelTypeMock = Mockito.mock(AttributeSelectorType.class); ApplyType applyTypeMock = Mockito.mock(ApplyType.class); Object genericObjectMock = Mockito.mock(Object.class); Object mockContentListObject = Mockito.mock(Object.class); List<Object> contentList = new ArrayList<Object>(); contentList.add(mockContentListObject); contentList.add(mockContentListObject); when(mockRuleType.getEffect()).thenReturn(effectTypePermit); when(mockRuleType.getObligationExpressions()).thenReturn(mockOblExsType); when(mockOblExsType.getObligationExpression()).thenReturn(oblExTypeList); when(mockOblExTypeListObj.getAttributeAssignmentExpression()).thenReturn(attrAssignList); when(mockOblExTypeListObj.getFulfillOn()).thenReturn(effectTypePermit); when(mockattrAssignListObj.getCategory()).thenReturn(""); when(mockattrAssignListObj.getAttributeId()).thenReturn(""); doReturn(jaxbElementMock).when(mockattrAssignListObj).getExpression(); doReturn(attrValTypeMock).when(jaxbElementMock).getValue(); when(attrValTypeMock.getContent()).thenReturn(contentList); processor.rule(mockRuleType); verify(mockRuleType, atLeast(1)).getEffect(); verify(mockRuleType, atLeast(1)).getObligationExpressions(); verify(mockOblExsType, atLeast(1)).getObligationExpression(); verify(mockOblExTypeListObj, atLeast(1)).getAttributeAssignmentExpression(); verify(mockOblExTypeListObj, atLeast(1)).getFulfillOn(); verify(mockattrAssignListObj, atLeast(1)).getExpression(); verify(jaxbElementMock, atLeast(1)).getValue(); verify(attrValTypeMock, atLeast(1)).getContent(); doReturn(attrDesignTypeMock).when(jaxbElementMock).getValue(); processor.rule(mockRuleType); verify(jaxbElementMock, atLeast(1)).getValue(); doReturn(attrSelTypeMock).when(jaxbElementMock).getValue(); processor.rule(mockRuleType); verify(jaxbElementMock, atLeast(1)).getValue(); doReturn(applyTypeMock).when(jaxbElementMock).getValue(); processor.rule(mockRuleType); verify(jaxbElementMock, atLeast(1)).getValue(); doReturn(genericObjectMock).when(jaxbElementMock).getValue(); processor.rule(mockRuleType); verify(jaxbElementMock, 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();  }