2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.components;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
26 import static org.mockito.Mockito.atLeast;
27 import static org.mockito.Mockito.verify;
28 import static org.mockito.Mockito.when;
30 import com.att.research.xacml.util.XACMLPolicyScanner.CallbackResult;
32 import java.io.IOException;
33 import java.util.ArrayList;
34 import java.util.Collections;
35 import java.util.List;
36 import javax.xml.bind.JAXBElement;
37 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType;
38 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType;
39 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
40 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType;
41 import oasis.names.tc.xacml._3_0.core.schema.wd_17.ConditionType;
42 import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType;
43 import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionType;
44 import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionsType;
45 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicySetType;
46 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
47 import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
48 import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
49 import org.junit.BeforeClass;
50 import org.junit.Test;
51 import org.mockito.Mockito;
53 public class HumanPolicyComponentTest {
55 private AttributeIdentifiers attrIds;
56 private HtmlProcessor processor;
57 private static File temp;
58 private static File tempAction;
59 private static File tempConfig;
62 public static void setup() throws IOException {
63 temp = File.createTempFile("tmpFile", ".tmp");
64 tempAction = File.createTempFile("Action_test", ".tmp");
65 tempConfig = File.createTempFile("Config_test", ".tmp");
67 tempAction.deleteOnExit();
68 tempConfig.deleteOnExit();
72 public void testAttributeIdentifiers() {
73 String testCategory = "testCategory";
74 String testID = "testId";
75 String testType = "testType";
76 String newTestType = "testNewType";
78 attrIds = new AttributeIdentifiers(testCategory, testType, testID);
79 assertEquals(testCategory, attrIds.category);
80 assertEquals(testID, attrIds.id);
81 assertEquals(testType, attrIds.getType());
83 attrIds.setType(newTestType);
84 assertEquals(newTestType, attrIds.getType());
87 @SuppressWarnings("unchecked")
89 public void testHumanPolicyComponentException() {
90 JAXBElement<PolicySetType> mockRoot = Mockito.mock(JAXBElement.class);
91 when(mockRoot.getValue()).thenReturn(null);
92 assertNull(HumanPolicyComponent.DescribePolicy(temp));
95 @Test(expected = IllegalArgumentException.class)
96 public void testHtmlProcessorNull() throws IOException {
97 processor = new HtmlProcessor(null, null);
100 @Test(expected = IllegalArgumentException.class)
101 public void testHtmlProcessor() throws IOException {
102 File tempFile = File.createTempFile("testFile", ".tmp");
104 processor = new HtmlProcessor(tempFile, null);
107 @Test(expected = IllegalArgumentException.class)
108 public void testHtmlProcessorInvalidObject() throws IOException {
109 processor = new HtmlProcessor(temp, null);
113 public void testHtmlProcessorConfigPolicySetType() {
114 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
115 processor = new HtmlProcessor(tempConfig, mockPolicySetType);
116 processor.onFinishScan(mockPolicySetType);
117 verify(mockPolicySetType).getVersion();
121 public void testHtmlProcessorActionPolicySetType() {
122 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
123 processor = new HtmlProcessor(tempAction, mockPolicySetType);
124 processor.onFinishScan(mockPolicySetType);
125 verify(mockPolicySetType).getVersion();
129 public void testHtmlProcessorConfigPolicyType() {
130 PolicyType mockPolicyType = Mockito.mock(PolicyType.class);
131 processor = new HtmlProcessor(tempConfig, mockPolicyType);
132 verify(mockPolicyType).getVersion();
136 public void testHtmlProcessorActionPolicyType() {
137 PolicyType mockPolicyType = Mockito.mock(PolicyType.class);
138 processor = new HtmlProcessor(tempAction, mockPolicyType);
139 assertNotNull(processor.getAttributeIdentifiersMap());
140 verify(mockPolicyType).getVersion();
144 public void testHtmlProcessorOnPreVisitPolicySet() {
145 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
146 PolicySetType mockPolicyParent = Mockito.mock(PolicySetType.class);
148 processor = new HtmlProcessor(temp, mockPolicySetType);
150 when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(Collections.emptyList());
151 when(mockPolicySetType.getDescription()).thenReturn(null);
153 CallbackResult preResult = processor.onPreVisitPolicySet(mockPolicyParent, mockPolicySetType);
154 assertEquals("CONTINUE", preResult.name());
155 verify(mockPolicySetType, atLeast(1)).getPolicySetOrPolicyOrPolicySetIdReference();
156 verify(mockPolicySetType, atLeast(1)).getDescription();
159 public void testHtmlProcessorOnPreVisitPolicySetNullParent() {
160 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
161 PolicySetType mockPolicyParent = null;
162 JAXBElement<?> mockElement = Mockito.mock(JAXBElement.class);
164 List<JAXBElement<?>> testList = new ArrayList<JAXBElement<?>>();
165 testList.add(mockElement);
167 processor = new HtmlProcessor(temp, mockPolicySetType);
169 when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(testList);
170 when(mockPolicySetType.getDescription()).thenReturn("");
172 CallbackResult preResult = processor.onPreVisitPolicySet(mockPolicyParent, mockPolicySetType);
173 assertEquals("CONTINUE", preResult.name());
174 verify(mockPolicySetType, atLeast(1)).getPolicySetOrPolicyOrPolicySetIdReference();
175 verify(mockPolicySetType, atLeast(1)).getDescription();
179 public void testHtmlProcessorOnPostVisitPolicySet() {
180 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
181 PolicySetType mockPolicyParent = Mockito.mock(PolicySetType.class);
183 processor = new HtmlProcessor(temp, mockPolicySetType);
185 when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(Collections.emptyList());
186 when(mockPolicySetType.getDescription()).thenReturn(null);
188 CallbackResult postResult = processor.onPostVisitPolicySet(mockPolicyParent, mockPolicySetType);
189 assertEquals("CONTINUE", postResult.name());
190 verify(mockPolicySetType, atLeast(1)).getPolicySetOrPolicyOrPolicySetIdReference();
191 verify(mockPolicySetType, atLeast(1)).getDescription();
195 public void testHtmlProcessorOnPostVisitPolicySetNullParent() {
196 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
197 PolicySetType mockPolicyParent = null;
198 JAXBElement<?> mockElement = Mockito.mock(JAXBElement.class);
200 List<JAXBElement<?>> testList = new ArrayList<JAXBElement<?>>();
201 testList.add(mockElement);
203 processor = new HtmlProcessor(temp, mockPolicySetType);
205 when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(testList);
206 when(mockPolicySetType.getDescription()).thenReturn("");
208 CallbackResult postResult = processor.onPostVisitPolicySet(mockPolicyParent, mockPolicySetType);
209 assertEquals("CONTINUE", postResult.name());
210 verify(mockPolicySetType, atLeast(1)).getPolicySetOrPolicyOrPolicySetIdReference();
211 verify(mockPolicySetType, atLeast(1)).getDescription();
215 public void testHtmlProcessorOnPreVisitPolicy() {
216 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
217 PolicyType mockPolicyType = Mockito.mock(PolicyType.class);
218 List<Object> testList = new ArrayList<Object>();
219 processor = new HtmlProcessor(temp, mockPolicySetType);
221 when(mockPolicyType.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()).thenReturn(testList);
222 when(mockPolicySetType.getDescription()).thenReturn(null);
224 CallbackResult preResult = processor.onPreVisitPolicy(mockPolicySetType, mockPolicyType);
225 assertEquals("CONTINUE", preResult.name());
226 verify(mockPolicyType, atLeast(1)).getCombinerParametersOrRuleCombinerParametersOrVariableDefinition();
227 verify(mockPolicyType, atLeast(1)).getDescription();
231 public void testHtmlProcessorOnPreVisitPolicyNullParent() {
232 PolicyType mockPolicyType = Mockito.mock(PolicyType.class);
233 PolicySetType mockPolicyParent = null;
234 List<Object> testList = new ArrayList<Object>();
235 testList.add(new Object());
236 processor = new HtmlProcessor(temp, mockPolicyType);
238 when(mockPolicyType.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()).thenReturn(testList);
239 when(mockPolicyType.getDescription()).thenReturn("");
241 CallbackResult preResult = processor.onPreVisitPolicy(mockPolicyParent, mockPolicyType);
242 assertEquals("CONTINUE", preResult.name());
243 verify(mockPolicyType, atLeast(1)).getCombinerParametersOrRuleCombinerParametersOrVariableDefinition();
244 verify(mockPolicyType, atLeast(1)).getDescription();
249 public void testHtmlProcessorOnPostVisitPolicy() {
250 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
251 PolicyType mockPolicyType = Mockito.mock(PolicyType.class);
252 List<Object> testList = new ArrayList<Object>();
253 processor = new HtmlProcessor(temp, mockPolicySetType);
255 when(mockPolicyType.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()).thenReturn(testList);
257 CallbackResult postResult = processor.onPostVisitPolicy(mockPolicySetType, mockPolicyType);
258 assertEquals("CONTINUE", postResult.name());
259 verify(mockPolicyType, atLeast(1)).getCombinerParametersOrRuleCombinerParametersOrVariableDefinition();
263 public void testHtmlProcessorOnPostVisitPolicyNullParent() {
264 PolicyType mockPolicyType = Mockito.mock(PolicyType.class);
265 PolicySetType mockPolicyParent = null;
266 List<Object> testList = new ArrayList<Object>();
267 testList.add(new Object());
268 processor = new HtmlProcessor(temp, mockPolicyType);
270 when(mockPolicyType.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()).thenReturn(testList);
272 CallbackResult postResult = processor.onPostVisitPolicy(mockPolicyParent, mockPolicyType);
273 assertEquals("CONTINUE", postResult.name());
274 verify(mockPolicyType, atLeast(1)).getCombinerParametersOrRuleCombinerParametersOrVariableDefinition();
278 public void testHtmlProcessorPolicy() {
279 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
280 PolicyType mockPolicyType = Mockito.mock(PolicyType.class);
281 processor = new HtmlProcessor(temp, mockPolicySetType);
283 when(mockPolicyType.getRuleCombiningAlgId()).thenReturn(null);
284 when(mockPolicyType.getPolicyId()).thenReturn(null);
285 when(mockPolicyType.getVersion()).thenReturn(null);
286 when(mockPolicyType.getTarget()).thenReturn(null);
288 processor.policy(mockPolicyType);
289 verify(mockPolicyType).getRuleCombiningAlgId();
290 verify(mockPolicyType).getPolicyId();
291 verify(mockPolicyType).getVersion();
292 verify(mockPolicyType).getTarget();
296 public void testHtmlProcessorPolicyListEmpty() {
297 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
298 PolicyType mockPolicyType = Mockito.mock(PolicyType.class);
299 TargetType mockTargetType = Mockito.mock(TargetType.class);
300 List<AnyOfType> anyOfList = new ArrayList<AnyOfType>();
301 processor = new HtmlProcessor(temp, mockPolicySetType);
303 when(mockPolicyType.getRuleCombiningAlgId()).thenReturn(null);
304 when(mockPolicyType.getPolicyId()).thenReturn(null);
305 when(mockPolicyType.getVersion()).thenReturn(null);
306 when(mockPolicyType.getTarget()).thenReturn(mockTargetType);
307 when(mockTargetType.getAnyOf()).thenReturn(anyOfList);
309 processor.policy(mockPolicyType);
311 verify(mockPolicyType, atLeast(1)).getRuleCombiningAlgId();
312 verify(mockPolicyType, atLeast(1)).getPolicyId();
313 verify(mockPolicyType, atLeast(1)).getVersion();
314 verify(mockPolicyType, atLeast(1)).getTarget();
315 verify(mockTargetType, atLeast(1)).getAnyOf();
319 public void testHtmlProcessorPolicyListNotEmpty() {
320 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
321 PolicyType mockPolicyType = Mockito.mock(PolicyType.class);
322 TargetType mockTargetType = Mockito.mock(TargetType.class);
323 List<AnyOfType> anyOfList = new ArrayList<AnyOfType>();
324 anyOfList.add(new AnyOfType());
325 processor = new HtmlProcessor(temp, mockPolicySetType);
327 when(mockPolicyType.getRuleCombiningAlgId()).thenReturn(null);
328 when(mockPolicyType.getPolicyId()).thenReturn(null);
329 when(mockPolicyType.getVersion()).thenReturn(null);
330 when(mockPolicyType.getTarget()).thenReturn(mockTargetType);
331 when(mockTargetType.getAnyOf()).thenReturn(anyOfList);
333 processor.policy(mockPolicyType);
334 verify(mockPolicyType, atLeast(1)).getRuleCombiningAlgId();
335 verify(mockPolicyType, atLeast(1)).getPolicyId();
336 verify(mockPolicyType, atLeast(1)).getVersion();
337 verify(mockPolicyType, atLeast(1)).getTarget();
338 verify(mockTargetType, atLeast(1)).getAnyOf();
342 public void testHtmlProcessorPolicyNull() {
343 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
344 PolicyType mockPolicyType = Mockito.mock(PolicyType.class);
345 TargetType mockTargetType = Mockito.mock(TargetType.class);
346 processor = new HtmlProcessor(temp, mockPolicySetType);
348 when(mockPolicyType.getRuleCombiningAlgId()).thenReturn(null);
349 when(mockPolicyType.getPolicyId()).thenReturn(null);
350 when(mockPolicyType.getVersion()).thenReturn(null);
351 when(mockPolicyType.getTarget()).thenReturn(mockTargetType);
352 when(mockPolicyType.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()).thenReturn(null);
353 when(mockTargetType.getAnyOf()).thenReturn(null);
355 processor.policy(mockPolicyType);
356 verify(mockPolicyType, atLeast(1)).getRuleCombiningAlgId();
357 verify(mockPolicyType, atLeast(1)).getPolicyId();
358 verify(mockPolicyType, atLeast(1)).getVersion();
359 verify(mockPolicyType, atLeast(1)).getTarget();
360 verify(mockPolicyType, atLeast(1)).getCombinerParametersOrRuleCombinerParametersOrVariableDefinition();
361 verify(mockTargetType, atLeast(1)).getAnyOf();
365 public void testHtmlProcessorPolicySet() {
366 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
367 processor = new HtmlProcessor(temp, mockPolicySetType);
369 when(mockPolicySetType.getPolicyCombiningAlgId()).thenReturn("");
370 when(mockPolicySetType.getPolicySetId()).thenReturn("");
371 when(mockPolicySetType.getVersion()).thenReturn("");
373 processor.policySet(mockPolicySetType, "");
374 verify(mockPolicySetType, atLeast(1)).getPolicyCombiningAlgId();
375 verify(mockPolicySetType, atLeast(1)).getPolicySetId();
376 verify(mockPolicySetType, atLeast(1)).getVersion();
380 public void testHtmlProcessorPolicySetNull() {
381 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
382 TargetType mockTargetType = Mockito.mock(TargetType.class);
383 processor = new HtmlProcessor(temp, mockPolicySetType);
385 when(mockPolicySetType.getTarget()).thenReturn(mockTargetType);
386 when(mockTargetType.getAnyOf()).thenReturn(null);
387 when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(null);
389 processor.policySet(mockPolicySetType, "");
390 verify(mockPolicySetType, atLeast(1)).getTarget();
391 verify(mockTargetType, atLeast(1)).getAnyOf();
392 verify(mockPolicySetType, atLeast(1)).getPolicySetOrPolicyOrPolicySetIdReference();
396 public void testHtmlProcessorPolicySetEmpty() {
397 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
398 TargetType mockTargetType = Mockito.mock(TargetType.class);
399 List<AnyOfType> anyOfList = new ArrayList<AnyOfType>();
400 processor = new HtmlProcessor(temp, mockPolicySetType);
402 when(mockPolicySetType.getTarget()).thenReturn(mockTargetType);
403 when(mockTargetType.getAnyOf()).thenReturn(anyOfList);
404 when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(null);
406 processor.policySet(mockPolicySetType, "");
407 verify(mockPolicySetType, atLeast(1)).getTarget();
408 verify(mockTargetType, atLeast(1)).getAnyOf();
409 verify(mockPolicySetType, atLeast(1)).getPolicySetOrPolicyOrPolicySetIdReference();
413 public void testHtmlProcessorPolicySetNotEmpty() {
414 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
415 TargetType mockTargetType = Mockito.mock(TargetType.class);
416 List<AnyOfType> anyOfList = new ArrayList<AnyOfType>();
417 anyOfList.add(new AnyOfType());
419 when(mockPolicySetType.getTarget()).thenReturn(mockTargetType);
420 when(mockTargetType.getAnyOf()).thenReturn(anyOfList);
421 when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(null);
423 processor = new HtmlProcessor(temp, mockPolicySetType);
424 processor.policySet(mockPolicySetType, "");
425 verify(mockPolicySetType, atLeast(1)).getTarget();
426 verify(mockTargetType, atLeast(1)).getAnyOf();
427 verify(mockPolicySetType, atLeast(1)).getPolicySetOrPolicyOrPolicySetIdReference();
431 public void testHtmlProcessorRule() {
432 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
433 RuleType mockRuleType = Mockito.mock(RuleType.class);
434 ConditionType mockConditionType = Mockito.mock(ConditionType.class);
435 ObligationExpressionsType mockOESType = Mockito.mock(ObligationExpressionsType.class);
436 ObligationExpressionType mockOEType = Mockito.mock(ObligationExpressionType.class);
437 EffectType effectTypePermit = EffectType.PERMIT;
438 processor = new HtmlProcessor(temp, mockPolicySetType);
440 List<ObligationExpressionType> oblList = new ArrayList<ObligationExpressionType>();
441 oblList.add(mockOEType);
443 when(mockRuleType.getEffect()).thenReturn(effectTypePermit);
444 when(mockRuleType.getRuleId()).thenReturn(null);
445 when(mockRuleType.getTarget()).thenReturn(null);
446 when(mockRuleType.getCondition()).thenReturn(mockConditionType);
447 when(mockRuleType.getObligationExpressions()).thenReturn(mockOESType);
448 when(mockOESType.getObligationExpression()).thenReturn(oblList);
449 when(mockOEType.getFulfillOn()).thenReturn(effectTypePermit);
451 processor.rule(mockRuleType);
453 verify(mockRuleType, atLeast(1)).getRuleId();
454 verify(mockRuleType, atLeast(1)).getTarget();
455 verify(mockRuleType, atLeast(1)).getCondition();
456 verify(mockRuleType, atLeast(1)).getObligationExpressions();
457 verify(mockOESType, atLeast(1)).getObligationExpression();
458 verify(mockOEType, atLeast(1)).getFulfillOn();
462 public void testHtmlProcessorRuleNullEmptyList() {
463 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
464 RuleType mockRuleType = Mockito.mock(RuleType.class);
465 TargetType mockTargetType = Mockito.mock(TargetType.class);
466 EffectType effectTypePermit = EffectType.PERMIT;
467 AdviceExpressionsType mockAdviceExsType = Mockito.mock(AdviceExpressionsType.class);
468 AdviceExpressionType mockAdviceEx = Mockito.mock(AdviceExpressionType.class);
469 processor = new HtmlProcessor(temp, mockPolicySetType);
471 List<AnyOfType> anyOfList = new ArrayList<AnyOfType>();
472 List<AdviceExpressionType> adviceExList = new ArrayList<AdviceExpressionType>();
473 adviceExList.add(mockAdviceEx);
475 when(mockRuleType.getEffect()).thenReturn(effectTypePermit);
476 when(mockRuleType.getRuleId()).thenReturn(null);
477 when(mockRuleType.getTarget()).thenReturn(mockTargetType);
478 when(mockRuleType.getObligationExpressions()).thenReturn(null);
479 when(mockRuleType.getAdviceExpressions()).thenReturn(mockAdviceExsType);
480 when(mockTargetType.getAnyOf()).thenReturn(null);
481 when(mockAdviceExsType.getAdviceExpression()).thenReturn(adviceExList);
482 when(mockAdviceEx.getAttributeAssignmentExpression()).thenReturn(null);
483 when(mockAdviceEx.getAppliesTo()).thenReturn(effectTypePermit);
485 processor.rule(mockRuleType);
487 verify(mockRuleType, atLeast(1)).getEffect();
488 verify(mockRuleType, atLeast(1)).getRuleId();
489 verify(mockRuleType, atLeast(1)).getTarget();
490 verify(mockRuleType, atLeast(1)).getCondition();
491 verify(mockRuleType, atLeast(1)).getObligationExpressions();
492 verify(mockRuleType, atLeast(1)).getAdviceExpressions();
493 verify(mockTargetType, atLeast(1)).getAnyOf();
494 verify(mockAdviceExsType, atLeast(1)).getAdviceExpression();
495 verify(mockAdviceEx, atLeast(1)).getAttributeAssignmentExpression();
496 verify(mockAdviceEx, atLeast(1)).getAppliesTo();
498 when(mockTargetType.getAnyOf()).thenReturn(anyOfList);
499 processor.rule(mockRuleType);
500 verify(mockTargetType, atLeast(1)).getAnyOf();
504 public void testHtmlProcessorRuleNonNullObjects() {
505 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
506 RuleType mockRuleType = Mockito.mock(RuleType.class);
507 TargetType mockTargetType = Mockito.mock(TargetType.class);
508 AdviceExpressionsType mockAdvice = Mockito.mock(AdviceExpressionsType.class);
509 ObligationExpressionsType mockObEx = Mockito.mock(ObligationExpressionsType.class);
510 AdviceExpressionType adviceExpTypeMock = Mockito.mock(AdviceExpressionType.class);
511 ObligationExpressionType mockObExType = Mockito.mock(ObligationExpressionType.class);
512 EffectType effectTypePermit = EffectType.PERMIT;
513 processor = new HtmlProcessor(temp, mockPolicySetType);
515 List<AnyOfType> anyOfList = new ArrayList<AnyOfType>();
516 anyOfList.add(new AnyOfType());
518 List<AdviceExpressionType> adviceList = new ArrayList<AdviceExpressionType>();
519 adviceList.add(adviceExpTypeMock);
521 List<AttributeAssignmentExpressionType> attrList = new ArrayList<AttributeAssignmentExpressionType>();
523 List<ObligationExpressionType> obExList = new ArrayList<ObligationExpressionType>();
524 obExList.add(mockObExType);
526 List<Object> contentList = new ArrayList<>();
527 contentList.add(new Object());
529 when(mockRuleType.getRuleId()).thenReturn("");
530 when(mockRuleType.getTarget()).thenReturn(mockTargetType);
531 when(mockRuleType.getEffect()).thenReturn(effectTypePermit);
532 when(mockTargetType.getAnyOf()).thenReturn(anyOfList);
533 when(mockRuleType.getAdviceExpressions()).thenReturn(mockAdvice);
534 when(mockAdvice.getAdviceExpression()).thenReturn(adviceList);
535 when(mockRuleType.getObligationExpressions()).thenReturn(mockObEx);
536 when(mockObEx.getObligationExpression()).thenReturn(obExList);
537 when(mockObExType.getAttributeAssignmentExpression()).thenReturn(null);
538 when(mockObExType.getFulfillOn()).thenReturn(effectTypePermit);
539 when(adviceExpTypeMock.getAdviceId()).thenReturn("");
540 when(adviceExpTypeMock.getAppliesTo()).thenReturn(effectTypePermit);
541 when(adviceExpTypeMock.getAttributeAssignmentExpression()).thenReturn(attrList);
543 processor.rule(mockRuleType);
545 verify(mockRuleType, atLeast(1)).getRuleId();
546 verify(mockRuleType, atLeast(1)).getTarget();
547 verify(mockRuleType, atLeast(1)).getEffect();
548 verify(mockRuleType, atLeast(1)).getAdviceExpressions();
549 verify(mockRuleType, atLeast(1)).getObligationExpressions();
550 verify(mockTargetType, atLeast(1)).getAnyOf();
551 verify(mockObEx, atLeast(1)).getObligationExpression();
552 verify(mockObExType, atLeast(1)).getAttributeAssignmentExpression();
553 verify(mockObExType, atLeast(1)).getFulfillOn();
554 verify(mockAdvice, atLeast(1)).getAdviceExpression();
555 verify(adviceExpTypeMock, atLeast(1)).getAdviceId();
556 verify(adviceExpTypeMock, atLeast(1)).getAppliesTo();
557 verify(adviceExpTypeMock, atLeast(1)).getAttributeAssignmentExpression();
561 public void testHtmlProcessorOnPreVisitRule() {
562 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
563 PolicyType mockPolicyType = null;
564 RuleType mockRuleType = Mockito.mock(RuleType.class);
565 EffectType effectTypePermit = EffectType.PERMIT;
566 TargetType mockTargetType = Mockito.mock(TargetType.class);
567 processor = new HtmlProcessor(temp, mockPolicySetType);
569 List<AnyOfType> anyOfList = new ArrayList<AnyOfType>();
570 anyOfList.add(new AnyOfType());
572 when(mockRuleType.getCondition()).thenReturn(null);
573 when(mockRuleType.getDescription()).thenReturn(null);
574 when(mockRuleType.getEffect()).thenReturn(effectTypePermit);
575 when(mockRuleType.getTarget()).thenReturn(mockTargetType);
576 when(mockTargetType.getAnyOf()).thenReturn(anyOfList);
578 CallbackResult callbackResult = processor.onPreVisitRule(mockPolicyType, mockRuleType);
579 assertNotNull(callbackResult);
581 verify(mockRuleType, atLeast(1)).getCondition();
582 verify(mockRuleType, atLeast(1)).getDescription();
583 verify(mockRuleType, atLeast(1)).getEffect();
584 verify(mockRuleType, atLeast(1)).getTarget();
585 verify(mockRuleType, atLeast(1)).getAdviceExpressions();
586 verify(mockTargetType, atLeast(1)).getAnyOf();
588 mockPolicyType = Mockito.mock(PolicyType.class);
589 when(mockRuleType.getDescription()).thenReturn("");
591 callbackResult = processor.onPreVisitRule(mockPolicyType, mockRuleType);
592 assertNotNull(callbackResult);
596 public void testHtmlProcessorOnPostVisitRule() {
597 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
598 PolicyType mockPolicyType = null;
599 RuleType mockRuleType = Mockito.mock(RuleType.class);
601 processor = new HtmlProcessor(temp, mockPolicySetType);
602 CallbackResult callbackResult = processor.onPostVisitRule(mockPolicyType, mockRuleType);
603 assertNotNull(callbackResult);
605 mockPolicyType = Mockito.mock(PolicyType.class);
606 callbackResult = processor.onPostVisitRule(mockPolicyType, mockRuleType);
607 assertNotNull(callbackResult);