HtmlProcessor extends SimpleCallback { public void policy(PolicyType policy) { if (LOGGER.isTraceEnabled()) { LOGGER.trace("Policy: " + policy.getPolicyId()); } String combiningAlgorithm = "-"; String id = "-"; String version = "-"; if (policy.getRuleCombiningAlgId() != null) { combiningAlgorithm = extractLastIdentifier(policy.getRuleCombiningAlgId(), ":"); } if (policy.getPolicyId() != null) { id = extractLastIdentifier(policy.getPolicyId(), ":"); } if (policy.getVersion() != null) { version = policy.getVersion(); } htmlOut.println("<li><b>Policy ID</b>: <i>" + id + "</i> (v" + version + ") " + "</li>"); if (policy.getTarget() == null || policy.getTarget().getAnyOf() == null || policy.getTarget().getAnyOf().isEmpty()) { htmlOut.println("<p>This policy applies to all requests.</p>"); } else { htmlOut.print("<p>"); htmlOut.print("This policy applies to requests with attributes "); target(policy.getTarget().getAnyOf()); htmlOut.println(".</p>"); } if (policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition() != null && !policy.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition().isEmpty()) { String algoDesc = combiningAlgo2human.get(combiningAlgorithm); if (algoDesc != null) { algoDesc = algoDesc.replace("$placeholder$", "rule") + " (<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 testHtmlProcessorPolicy() { PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class); PolicyType mockPolicyType = Mockito.mock(PolicyType.class); processor = new HtmlProcessor(temp, mockPolicySetType); when(mockPolicyType.getRuleCombiningAlgId()).thenReturn(null); when(mockPolicyType.getPolicyId()).thenReturn(null); when(mockPolicyType.getVersion()).thenReturn(null); when(mockPolicyType.getTarget()).thenReturn(null); processor.policy(mockPolicyType); verify(mockPolicyType).getRuleCombiningAlgId(); verify(mockPolicyType).getPolicyId(); verify(mockPolicyType).getVersion(); verify(mockPolicyType).getTarget(); }
@Test public void testHtmlProcessorPolicyListEmpty() { PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class); PolicyType mockPolicyType = Mockito.mock(PolicyType.class); TargetType mockTargetType = Mockito.mock(TargetType.class); List<AnyOfType> anyOfList = new ArrayList<AnyOfType>(); processor = new HtmlProcessor(temp, mockPolicySetType); when(mockPolicyType.getRuleCombiningAlgId()).thenReturn(null); when(mockPolicyType.getPolicyId()).thenReturn(null); when(mockPolicyType.getVersion()).thenReturn(null); when(mockPolicyType.getTarget()).thenReturn(mockTargetType); when(mockTargetType.getAnyOf()).thenReturn(anyOfList); processor.policy(mockPolicyType); verify(mockPolicyType, atLeast(1)).getRuleCombiningAlgId(); verify(mockPolicyType, atLeast(1)).getPolicyId(); verify(mockPolicyType, atLeast(1)).getVersion(); verify(mockPolicyType, atLeast(1)).getTarget(); verify(mockTargetType, atLeast(1)).getAnyOf(); }
@Test public void testHtmlProcessorPolicyListNotEmpty() { PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class); PolicyType mockPolicyType = Mockito.mock(PolicyType.class); TargetType mockTargetType = Mockito.mock(TargetType.class); List<AnyOfType> anyOfList = new ArrayList<AnyOfType>(); anyOfList.add(new AnyOfType()); processor = new HtmlProcessor(temp, mockPolicySetType); when(mockPolicyType.getRuleCombiningAlgId()).thenReturn(null); when(mockPolicyType.getPolicyId()).thenReturn(null); when(mockPolicyType.getVersion()).thenReturn(null); when(mockPolicyType.getTarget()).thenReturn(mockTargetType); when(mockTargetType.getAnyOf()).thenReturn(anyOfList); processor.policy(mockPolicyType); verify(mockPolicyType, atLeast(1)).getRuleCombiningAlgId(); verify(mockPolicyType, atLeast(1)).getPolicyId(); verify(mockPolicyType, atLeast(1)).getVersion(); verify(mockPolicyType, atLeast(1)).getTarget(); verify(mockTargetType, atLeast(1)).getAnyOf(); }
@Test public void testHtmlProcessorPolicyNull() { PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class); PolicyType mockPolicyType = Mockito.mock(PolicyType.class); TargetType mockTargetType = Mockito.mock(TargetType.class); processor = new HtmlProcessor(temp, mockPolicySetType); when(mockPolicyType.getRuleCombiningAlgId()).thenReturn(null); when(mockPolicyType.getPolicyId()).thenReturn(null); when(mockPolicyType.getVersion()).thenReturn(null); when(mockPolicyType.getTarget()).thenReturn(mockTargetType); when(mockPolicyType.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()).thenReturn(null); when(mockTargetType.getAnyOf()).thenReturn(null); processor.policy(mockPolicyType); verify(mockPolicyType, atLeast(1)).getRuleCombiningAlgId(); verify(mockPolicyType, atLeast(1)).getPolicyId(); verify(mockPolicyType, atLeast(1)).getVersion(); verify(mockPolicyType, atLeast(1)).getTarget(); verify(mockPolicyType, atLeast(1)).getCombinerParametersOrRuleCombinerParametersOrVariableDefinition(); verify(mockTargetType, atLeast(1)).getAnyOf(); }