HtmlProcessor extends SimpleCallback { public void policySet(PolicySetType policySet, String htmlListElement) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("PolicySet: " + policySet.getPolicySetId()); } String combiningAlgorithm = "-"; String id = "-"; String version = "-"; if (policySet.getPolicyCombiningAlgId() != null) { combiningAlgorithm = extractLastIdentifier(policySet.getPolicyCombiningAlgId(), ":"); } if (policySet.getPolicySetId() != null) { id = extractLastIdentifier(policySet.getPolicySetId(), ":"); } if (policySet.getVersion() != null) { version = policySet.getVersion(); } htmlOut.println("<" + htmlListElement + "><b>Policy Set ID</b>: <i>" + id + "</i> (v" + version + ") " + "</" + htmlListElement + ">"); if (policySet.getTarget() == null || policySet.getTarget().getAnyOf() == null || policySet.getTarget().getAnyOf().isEmpty()) { htmlOut.println("<p>This policy set applies to all requests.</p>"); } else { htmlOut.print("<p>"); htmlOut.print("This policy set applies to requests with attributes "); target(policySet.getTarget().getAnyOf()); htmlOut.println(".</p>"); } if (policySet.getPolicySetOrPolicyOrPolicySetIdReference() != null && !policySet.getPolicySetOrPolicyOrPolicySetIdReference().isEmpty()) { String algoDesc = combiningAlgo2human.get(combiningAlgorithm); if (algoDesc != null) { algoDesc = algoDesc.replace("$placeholder$", "policy") + " (" + "<i>" + combiningAlgorithm + "</i>)"; } else { algoDesc = combiningAlgorithm; } htmlOut.println("<p>The result is " + algoDesc + ": </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();  }
@Test public void testHtmlProcessorPolicySet() { PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class); processor = new HtmlProcessor(temp, mockPolicySetType); when(mockPolicySetType.getPolicyCombiningAlgId()).thenReturn(""); when(mockPolicySetType.getPolicySetId()).thenReturn(""); when(mockPolicySetType.getVersion()).thenReturn(""); processor.policySet(mockPolicySetType, ""); verify(mockPolicySetType, atLeast(1)).getPolicyCombiningAlgId(); verify(mockPolicySetType, atLeast(1)).getPolicySetId(); verify(mockPolicySetType, atLeast(1)).getVersion(); }
@Test public void testHtmlProcessorPolicySetNull() { PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class); TargetType mockTargetType = Mockito.mock(TargetType.class); processor = new HtmlProcessor(temp, mockPolicySetType); when(mockPolicySetType.getTarget()).thenReturn(mockTargetType); when(mockTargetType.getAnyOf()).thenReturn(null); when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(null); processor.policySet(mockPolicySetType, ""); verify(mockPolicySetType, atLeast(1)).getTarget(); verify(mockTargetType, atLeast(1)).getAnyOf(); verify(mockPolicySetType, atLeast(1)).getPolicySetOrPolicyOrPolicySetIdReference(); }
@Test public void testHtmlProcessorPolicySetEmpty() { PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class); TargetType mockTargetType = Mockito.mock(TargetType.class); List<AnyOfType> anyOfList = new ArrayList<AnyOfType>(); processor = new HtmlProcessor(temp, mockPolicySetType); when(mockPolicySetType.getTarget()).thenReturn(mockTargetType); when(mockTargetType.getAnyOf()).thenReturn(anyOfList); when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(null); processor.policySet(mockPolicySetType, ""); verify(mockPolicySetType, atLeast(1)).getTarget(); verify(mockTargetType, atLeast(1)).getAnyOf(); verify(mockPolicySetType, atLeast(1)).getPolicySetOrPolicyOrPolicySetIdReference(); }
@Test public void testHtmlProcessorPolicySetNotEmpty() { PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class); TargetType mockTargetType = Mockito.mock(TargetType.class); List<AnyOfType> anyOfList = new ArrayList<AnyOfType>(); anyOfList.add(new AnyOfType()); when(mockPolicySetType.getTarget()).thenReturn(mockTargetType); when(mockTargetType.getAnyOf()).thenReturn(anyOfList); when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(null); processor = new HtmlProcessor(temp, mockPolicySetType); processor.policySet(mockPolicySetType, ""); verify(mockPolicySetType, atLeast(1)).getTarget(); verify(mockTargetType, atLeast(1)).getAnyOf(); verify(mockPolicySetType, atLeast(1)).getPolicySetOrPolicyOrPolicySetIdReference(); }