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.junit.Assert.fail;
27 import static org.mockito.Mockito.atLeast;
28 import static org.mockito.Mockito.doReturn;
29 import static org.mockito.Mockito.verify;
30 import static org.mockito.Mockito.when;
32 import com.att.research.xacml.api.XACML1;
33 import com.att.research.xacml.util.XACMLPolicyScanner.CallbackResult;
35 import java.io.IOException;
36 import java.util.ArrayList;
37 import java.util.Collections;
38 import java.util.List;
39 import javax.xml.bind.JAXBElement;
40 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionType;
41 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AdviceExpressionsType;
42 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AllOfType;
43 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AnyOfType;
44 import oasis.names.tc.xacml._3_0.core.schema.wd_17.ApplyType;
45 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeAssignmentExpressionType;
46 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeDesignatorType;
47 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeSelectorType;
48 import oasis.names.tc.xacml._3_0.core.schema.wd_17.AttributeValueType;
49 import oasis.names.tc.xacml._3_0.core.schema.wd_17.ConditionType;
50 import oasis.names.tc.xacml._3_0.core.schema.wd_17.EffectType;
51 import oasis.names.tc.xacml._3_0.core.schema.wd_17.MatchType;
52 import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionType;
53 import oasis.names.tc.xacml._3_0.core.schema.wd_17.ObligationExpressionsType;
54 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicySetType;
55 import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
56 import oasis.names.tc.xacml._3_0.core.schema.wd_17.RuleType;
57 import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
58 import oasis.names.tc.xacml._3_0.core.schema.wd_17.VariableReferenceType;
59 import org.junit.BeforeClass;
60 import org.junit.Test;
61 import org.mockito.Mockito;
63 public class HumanPolicyComponentTest {
65 private AttributeIdentifiers attrIds;
66 private HtmlProcessor processor;
67 private static File temp;
68 private static File tempAction;
69 private static File tempConfig;
72 public static void setup() throws IOException {
73 temp = File.createTempFile("tmpFile", ".tmp");
74 tempAction = File.createTempFile("Action_test", ".tmp");
75 tempConfig = File.createTempFile("Config_test", ".tmp");
77 tempAction.deleteOnExit();
78 tempConfig.deleteOnExit();
82 public void testAttributeIdentifiers() {
83 String testCategory = "testCategory";
84 String testID = "testId";
85 String testType = "testType";
86 String newTestType = "testNewType";
88 attrIds = new AttributeIdentifiers(testCategory, testType, testID);
89 assertEquals(testCategory, attrIds.category);
90 assertEquals(testID, attrIds.id);
91 assertEquals(testType, attrIds.getType());
93 attrIds.setType(newTestType);
94 assertEquals(newTestType, attrIds.getType());
97 @SuppressWarnings("unchecked")
99 public void testHumanPolicyComponentException() {
100 JAXBElement<PolicySetType> mockRoot = Mockito.mock(JAXBElement.class);
101 when(mockRoot.getValue()).thenReturn(null);
102 assertNull(HumanPolicyComponent.DescribePolicy(temp));
105 @Test(expected = IllegalArgumentException.class)
106 public void testHtmlProcessorNull() throws IOException {
107 processor = new HtmlProcessor(null, null);
110 @Test(expected = IllegalArgumentException.class)
111 public void testHtmlProcessor() throws IOException {
112 File tempFile = File.createTempFile("testFile", ".tmp");
114 processor = new HtmlProcessor(tempFile, null);
117 @Test(expected = IllegalArgumentException.class)
118 public void testHtmlProcessorInvalidObject() throws IOException {
119 processor = new HtmlProcessor(temp, null);
123 public void testHtmlProcessorConfigPolicySetType() {
124 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
125 processor = new HtmlProcessor(tempConfig, mockPolicySetType);
126 processor.onFinishScan(mockPolicySetType);
127 verify(mockPolicySetType).getVersion();
131 public void testHtmlProcessorActionPolicySetType() {
132 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
133 processor = new HtmlProcessor(tempAction, mockPolicySetType);
134 processor.onFinishScan(mockPolicySetType);
135 verify(mockPolicySetType).getVersion();
139 public void testHtmlProcessorConfigPolicyType() {
140 PolicyType mockPolicyType = Mockito.mock(PolicyType.class);
141 processor = new HtmlProcessor(tempConfig, mockPolicyType);
142 verify(mockPolicyType).getVersion();
146 public void testHtmlProcessorActionPolicyType() {
147 PolicyType mockPolicyType = Mockito.mock(PolicyType.class);
148 processor = new HtmlProcessor(tempAction, mockPolicyType);
149 assertNotNull(processor.getAttributeIdentifiersMap());
150 verify(mockPolicyType).getVersion();
154 public void testHtmlProcessorOnPreVisitPolicySet() {
155 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
156 PolicySetType mockPolicyParent = Mockito.mock(PolicySetType.class);
158 processor = new HtmlProcessor(temp, mockPolicySetType);
160 when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(Collections.emptyList());
161 when(mockPolicySetType.getDescription()).thenReturn(null);
163 CallbackResult preResult = processor.onPreVisitPolicySet(mockPolicyParent, mockPolicySetType);
164 assertEquals("CONTINUE", preResult.name());
165 verify(mockPolicySetType, atLeast(1)).getPolicySetOrPolicyOrPolicySetIdReference();
166 verify(mockPolicySetType, atLeast(1)).getDescription();
170 public void testHtmlProcessorOnPreVisitPolicySetNullParent() {
171 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
172 PolicySetType mockPolicyParent = null;
173 JAXBElement<?> mockElement = Mockito.mock(JAXBElement.class);
175 List<JAXBElement<?>> testList = new ArrayList<JAXBElement<?>>();
176 testList.add(mockElement);
178 processor = new HtmlProcessor(temp, mockPolicySetType);
180 when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(testList);
181 when(mockPolicySetType.getDescription()).thenReturn("");
183 CallbackResult preResult = processor.onPreVisitPolicySet(mockPolicyParent, mockPolicySetType);
184 assertEquals("CONTINUE", preResult.name());
185 verify(mockPolicySetType, atLeast(1)).getPolicySetOrPolicyOrPolicySetIdReference();
186 verify(mockPolicySetType, atLeast(1)).getDescription();
190 public void testHtmlProcessorOnPostVisitPolicySet() {
191 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
192 PolicySetType mockPolicyParent = Mockito.mock(PolicySetType.class);
194 processor = new HtmlProcessor(temp, mockPolicySetType);
196 when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(Collections.emptyList());
197 when(mockPolicySetType.getDescription()).thenReturn(null);
199 CallbackResult postResult = processor.onPostVisitPolicySet(mockPolicyParent, mockPolicySetType);
200 assertEquals("CONTINUE", postResult.name());
201 verify(mockPolicySetType, atLeast(1)).getPolicySetOrPolicyOrPolicySetIdReference();
202 verify(mockPolicySetType, atLeast(1)).getDescription();
206 public void testHtmlProcessorOnPostVisitPolicySetNullParent() {
207 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
208 PolicySetType mockPolicyParent = null;
209 JAXBElement<?> mockElement = Mockito.mock(JAXBElement.class);
211 List<JAXBElement<?>> testList = new ArrayList<JAXBElement<?>>();
212 testList.add(mockElement);
214 processor = new HtmlProcessor(temp, mockPolicySetType);
216 when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(testList);
217 when(mockPolicySetType.getDescription()).thenReturn("");
219 CallbackResult postResult = processor.onPostVisitPolicySet(mockPolicyParent, mockPolicySetType);
220 assertEquals("CONTINUE", postResult.name());
221 verify(mockPolicySetType, atLeast(1)).getPolicySetOrPolicyOrPolicySetIdReference();
222 verify(mockPolicySetType, atLeast(1)).getDescription();
226 public void testHtmlProcessorOnPreVisitPolicy() {
227 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
228 PolicyType mockPolicyType = Mockito.mock(PolicyType.class);
229 List<Object> testList = new ArrayList<Object>();
230 processor = new HtmlProcessor(temp, mockPolicySetType);
232 when(mockPolicyType.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()).thenReturn(testList);
233 when(mockPolicySetType.getDescription()).thenReturn(null);
235 CallbackResult preResult = processor.onPreVisitPolicy(mockPolicySetType, mockPolicyType);
236 assertEquals("CONTINUE", preResult.name());
237 verify(mockPolicyType, atLeast(1)).getCombinerParametersOrRuleCombinerParametersOrVariableDefinition();
238 verify(mockPolicyType, atLeast(1)).getDescription();
242 public void testHtmlProcessorOnPreVisitPolicyNullParent() {
243 PolicyType mockPolicyType = Mockito.mock(PolicyType.class);
244 PolicySetType mockPolicyParent = null;
245 List<Object> testList = new ArrayList<Object>();
246 testList.add(new Object());
247 processor = new HtmlProcessor(temp, mockPolicyType);
249 when(mockPolicyType.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()).thenReturn(testList);
250 when(mockPolicyType.getDescription()).thenReturn("");
252 CallbackResult preResult = processor.onPreVisitPolicy(mockPolicyParent, mockPolicyType);
253 assertEquals("CONTINUE", preResult.name());
254 verify(mockPolicyType, atLeast(1)).getCombinerParametersOrRuleCombinerParametersOrVariableDefinition();
255 verify(mockPolicyType, atLeast(1)).getDescription();
260 public void testHtmlProcessorOnPostVisitPolicy() {
261 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
262 PolicyType mockPolicyType = Mockito.mock(PolicyType.class);
263 List<Object> testList = new ArrayList<Object>();
264 processor = new HtmlProcessor(temp, mockPolicySetType);
266 when(mockPolicyType.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()).thenReturn(testList);
268 CallbackResult postResult = processor.onPostVisitPolicy(mockPolicySetType, mockPolicyType);
269 assertEquals("CONTINUE", postResult.name());
270 verify(mockPolicyType, atLeast(1)).getCombinerParametersOrRuleCombinerParametersOrVariableDefinition();
274 public void testHtmlProcessorOnPostVisitPolicyNullParent() {
275 PolicyType mockPolicyType = Mockito.mock(PolicyType.class);
276 PolicySetType mockPolicyParent = null;
277 List<Object> testList = new ArrayList<Object>();
278 testList.add(new Object());
279 processor = new HtmlProcessor(temp, mockPolicyType);
281 when(mockPolicyType.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()).thenReturn(testList);
283 CallbackResult postResult = processor.onPostVisitPolicy(mockPolicyParent, mockPolicyType);
284 assertEquals("CONTINUE", postResult.name());
285 verify(mockPolicyType, atLeast(1)).getCombinerParametersOrRuleCombinerParametersOrVariableDefinition();
289 public void testHtmlProcessorPolicy() {
290 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
291 PolicyType mockPolicyType = Mockito.mock(PolicyType.class);
292 processor = new HtmlProcessor(temp, mockPolicySetType);
294 when(mockPolicyType.getRuleCombiningAlgId()).thenReturn(null);
295 when(mockPolicyType.getPolicyId()).thenReturn(null);
296 when(mockPolicyType.getVersion()).thenReturn(null);
297 when(mockPolicyType.getTarget()).thenReturn(null);
299 processor.policy(mockPolicyType);
300 verify(mockPolicyType).getRuleCombiningAlgId();
301 verify(mockPolicyType).getPolicyId();
302 verify(mockPolicyType).getVersion();
303 verify(mockPolicyType).getTarget();
307 public void testHtmlProcessorPolicyListEmpty() {
308 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
309 PolicyType mockPolicyType = Mockito.mock(PolicyType.class);
310 TargetType mockTargetType = Mockito.mock(TargetType.class);
311 List<AnyOfType> anyOfList = new ArrayList<AnyOfType>();
312 processor = new HtmlProcessor(temp, mockPolicySetType);
314 when(mockPolicyType.getRuleCombiningAlgId()).thenReturn(null);
315 when(mockPolicyType.getPolicyId()).thenReturn(null);
316 when(mockPolicyType.getVersion()).thenReturn(null);
317 when(mockPolicyType.getTarget()).thenReturn(mockTargetType);
318 when(mockTargetType.getAnyOf()).thenReturn(anyOfList);
320 processor.policy(mockPolicyType);
322 verify(mockPolicyType, atLeast(1)).getRuleCombiningAlgId();
323 verify(mockPolicyType, atLeast(1)).getPolicyId();
324 verify(mockPolicyType, atLeast(1)).getVersion();
325 verify(mockPolicyType, atLeast(1)).getTarget();
326 verify(mockTargetType, atLeast(1)).getAnyOf();
330 public void testHtmlProcessorPolicyListNotEmpty() {
331 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
332 PolicyType mockPolicyType = Mockito.mock(PolicyType.class);
333 TargetType mockTargetType = Mockito.mock(TargetType.class);
334 List<AnyOfType> anyOfList = new ArrayList<AnyOfType>();
335 anyOfList.add(new AnyOfType());
336 processor = new HtmlProcessor(temp, mockPolicySetType);
338 when(mockPolicyType.getRuleCombiningAlgId()).thenReturn(null);
339 when(mockPolicyType.getPolicyId()).thenReturn(null);
340 when(mockPolicyType.getVersion()).thenReturn(null);
341 when(mockPolicyType.getTarget()).thenReturn(mockTargetType);
342 when(mockTargetType.getAnyOf()).thenReturn(anyOfList);
344 processor.policy(mockPolicyType);
345 verify(mockPolicyType, atLeast(1)).getRuleCombiningAlgId();
346 verify(mockPolicyType, atLeast(1)).getPolicyId();
347 verify(mockPolicyType, atLeast(1)).getVersion();
348 verify(mockPolicyType, atLeast(1)).getTarget();
349 verify(mockTargetType, atLeast(1)).getAnyOf();
353 public void testHtmlProcessorPolicyNull() {
354 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
355 PolicyType mockPolicyType = Mockito.mock(PolicyType.class);
356 TargetType mockTargetType = Mockito.mock(TargetType.class);
357 processor = new HtmlProcessor(temp, mockPolicySetType);
359 when(mockPolicyType.getRuleCombiningAlgId()).thenReturn(null);
360 when(mockPolicyType.getPolicyId()).thenReturn(null);
361 when(mockPolicyType.getVersion()).thenReturn(null);
362 when(mockPolicyType.getTarget()).thenReturn(mockTargetType);
363 when(mockPolicyType.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()).thenReturn(null);
364 when(mockTargetType.getAnyOf()).thenReturn(null);
366 processor.policy(mockPolicyType);
367 verify(mockPolicyType, atLeast(1)).getRuleCombiningAlgId();
368 verify(mockPolicyType, atLeast(1)).getPolicyId();
369 verify(mockPolicyType, atLeast(1)).getVersion();
370 verify(mockPolicyType, atLeast(1)).getTarget();
371 verify(mockPolicyType, atLeast(1)).getCombinerParametersOrRuleCombinerParametersOrVariableDefinition();
372 verify(mockTargetType, atLeast(1)).getAnyOf();
376 public void testHtmlProcessorPolicySet() {
377 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
378 processor = new HtmlProcessor(temp, mockPolicySetType);
380 when(mockPolicySetType.getPolicyCombiningAlgId()).thenReturn("");
381 when(mockPolicySetType.getPolicySetId()).thenReturn("");
382 when(mockPolicySetType.getVersion()).thenReturn("");
384 processor.policySet(mockPolicySetType, "");
385 verify(mockPolicySetType, atLeast(1)).getPolicyCombiningAlgId();
386 verify(mockPolicySetType, atLeast(1)).getPolicySetId();
387 verify(mockPolicySetType, atLeast(1)).getVersion();
391 public void testHtmlProcessorPolicySetNull() {
392 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
393 TargetType mockTargetType = Mockito.mock(TargetType.class);
394 processor = new HtmlProcessor(temp, mockPolicySetType);
396 when(mockPolicySetType.getTarget()).thenReturn(mockTargetType);
397 when(mockTargetType.getAnyOf()).thenReturn(null);
398 when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(null);
400 processor.policySet(mockPolicySetType, "");
401 verify(mockPolicySetType, atLeast(1)).getTarget();
402 verify(mockTargetType, atLeast(1)).getAnyOf();
403 verify(mockPolicySetType, atLeast(1)).getPolicySetOrPolicyOrPolicySetIdReference();
407 public void testHtmlProcessorPolicySetEmpty() {
408 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
409 TargetType mockTargetType = Mockito.mock(TargetType.class);
410 List<AnyOfType> anyOfList = new ArrayList<AnyOfType>();
411 processor = new HtmlProcessor(temp, mockPolicySetType);
413 when(mockPolicySetType.getTarget()).thenReturn(mockTargetType);
414 when(mockTargetType.getAnyOf()).thenReturn(anyOfList);
415 when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(null);
417 processor.policySet(mockPolicySetType, "");
418 verify(mockPolicySetType, atLeast(1)).getTarget();
419 verify(mockTargetType, atLeast(1)).getAnyOf();
420 verify(mockPolicySetType, atLeast(1)).getPolicySetOrPolicyOrPolicySetIdReference();
424 public void testHtmlProcessorPolicySetNotEmpty() {
425 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
426 TargetType mockTargetType = Mockito.mock(TargetType.class);
427 List<AnyOfType> anyOfList = new ArrayList<AnyOfType>();
428 anyOfList.add(new AnyOfType());
430 when(mockPolicySetType.getTarget()).thenReturn(mockTargetType);
431 when(mockTargetType.getAnyOf()).thenReturn(anyOfList);
432 when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(null);
434 processor = new HtmlProcessor(temp, mockPolicySetType);
435 processor.policySet(mockPolicySetType, "");
436 verify(mockPolicySetType, atLeast(1)).getTarget();
437 verify(mockTargetType, atLeast(1)).getAnyOf();
438 verify(mockPolicySetType, atLeast(1)).getPolicySetOrPolicyOrPolicySetIdReference();
442 public void testHtmlProcessorRule() {
443 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
444 RuleType mockRuleType = Mockito.mock(RuleType.class);
445 ConditionType mockConditionType = Mockito.mock(ConditionType.class);
446 ObligationExpressionsType mockOESType = Mockito.mock(ObligationExpressionsType.class);
447 ObligationExpressionType mockOEType = Mockito.mock(ObligationExpressionType.class);
448 EffectType effectTypePermit = EffectType.PERMIT;
449 processor = new HtmlProcessor(temp, mockPolicySetType);
451 List<ObligationExpressionType> oblList = new ArrayList<ObligationExpressionType>();
452 oblList.add(mockOEType);
454 when(mockRuleType.getEffect()).thenReturn(effectTypePermit);
455 when(mockRuleType.getRuleId()).thenReturn(null);
456 when(mockRuleType.getTarget()).thenReturn(null);
457 when(mockRuleType.getCondition()).thenReturn(mockConditionType);
458 when(mockRuleType.getObligationExpressions()).thenReturn(mockOESType);
459 when(mockOESType.getObligationExpression()).thenReturn(oblList);
460 when(mockOEType.getFulfillOn()).thenReturn(effectTypePermit);
462 processor.rule(mockRuleType);
464 verify(mockRuleType, atLeast(1)).getRuleId();
465 verify(mockRuleType, atLeast(1)).getTarget();
466 verify(mockRuleType, atLeast(1)).getCondition();
467 verify(mockRuleType, atLeast(1)).getObligationExpressions();
468 verify(mockOESType, atLeast(1)).getObligationExpression();
469 verify(mockOEType, atLeast(1)).getFulfillOn();
471 JAXBElement<?> mockJaxBElement = Mockito.mock(JAXBElement.class);
472 Object mockValueObject = Mockito.mock(Object.class);
474 doReturn(mockJaxBElement).when(mockConditionType).getExpression();
475 doReturn(mockValueObject).when(mockJaxBElement).getValue();
478 processor.rule(mockRuleType);
480 } catch (IllegalArgumentException e) {
481 verify(mockConditionType, atLeast(1)).getExpression();
482 verify(mockJaxBElement, atLeast(1)).getValue();
487 public void testHtmlProcessorRuleNullEmptyList() {
488 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
489 RuleType mockRuleType = Mockito.mock(RuleType.class);
490 TargetType mockTargetType = Mockito.mock(TargetType.class);
491 EffectType effectTypePermit = EffectType.PERMIT;
492 AdviceExpressionsType mockAdviceExsType = Mockito.mock(AdviceExpressionsType.class);
493 AdviceExpressionType mockAdviceEx = Mockito.mock(AdviceExpressionType.class);
494 processor = new HtmlProcessor(temp, mockPolicySetType);
496 List<AnyOfType> anyOfList = new ArrayList<AnyOfType>();
497 List<AdviceExpressionType> adviceExList = new ArrayList<AdviceExpressionType>();
498 adviceExList.add(mockAdviceEx);
500 when(mockRuleType.getEffect()).thenReturn(effectTypePermit);
501 when(mockRuleType.getRuleId()).thenReturn(null);
502 when(mockRuleType.getTarget()).thenReturn(mockTargetType);
503 when(mockRuleType.getObligationExpressions()).thenReturn(null);
504 when(mockRuleType.getAdviceExpressions()).thenReturn(mockAdviceExsType);
505 when(mockTargetType.getAnyOf()).thenReturn(null);
506 when(mockAdviceExsType.getAdviceExpression()).thenReturn(adviceExList);
507 when(mockAdviceEx.getAttributeAssignmentExpression()).thenReturn(null);
508 when(mockAdviceEx.getAppliesTo()).thenReturn(effectTypePermit);
510 processor.rule(mockRuleType);
512 verify(mockRuleType, atLeast(1)).getEffect();
513 verify(mockRuleType, atLeast(1)).getRuleId();
514 verify(mockRuleType, atLeast(1)).getTarget();
515 verify(mockRuleType, atLeast(1)).getCondition();
516 verify(mockRuleType, atLeast(1)).getObligationExpressions();
517 verify(mockRuleType, atLeast(1)).getAdviceExpressions();
518 verify(mockTargetType, atLeast(1)).getAnyOf();
519 verify(mockAdviceExsType, atLeast(1)).getAdviceExpression();
520 verify(mockAdviceEx, atLeast(1)).getAttributeAssignmentExpression();
521 verify(mockAdviceEx, atLeast(1)).getAppliesTo();
523 when(mockTargetType.getAnyOf()).thenReturn(anyOfList);
524 processor.rule(mockRuleType);
525 verify(mockTargetType, atLeast(1)).getAnyOf();
529 public void testHtmlProcessorRuleNonNullObjects() {
530 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
531 RuleType mockRuleType = Mockito.mock(RuleType.class);
532 TargetType mockTargetType = Mockito.mock(TargetType.class);
533 AdviceExpressionsType mockAdvice = Mockito.mock(AdviceExpressionsType.class);
534 ObligationExpressionsType mockObEx = Mockito.mock(ObligationExpressionsType.class);
535 AdviceExpressionType adviceExpTypeMock = Mockito.mock(AdviceExpressionType.class);
536 ObligationExpressionType mockObExType = Mockito.mock(ObligationExpressionType.class);
537 EffectType effectTypePermit = EffectType.PERMIT;
538 processor = new HtmlProcessor(temp, mockPolicySetType);
540 List<AnyOfType> anyOfList = new ArrayList<AnyOfType>();
541 anyOfList.add(new AnyOfType());
543 List<AdviceExpressionType> adviceList = new ArrayList<AdviceExpressionType>();
544 adviceList.add(adviceExpTypeMock);
546 List<AttributeAssignmentExpressionType> attrList = new ArrayList<AttributeAssignmentExpressionType>();
548 List<ObligationExpressionType> obExList = new ArrayList<ObligationExpressionType>();
549 obExList.add(mockObExType);
551 List<Object> contentList = new ArrayList<>();
552 contentList.add(new Object());
554 when(mockRuleType.getRuleId()).thenReturn("");
555 when(mockRuleType.getTarget()).thenReturn(mockTargetType);
556 when(mockRuleType.getEffect()).thenReturn(effectTypePermit);
557 when(mockTargetType.getAnyOf()).thenReturn(anyOfList);
558 when(mockRuleType.getAdviceExpressions()).thenReturn(mockAdvice);
559 when(mockAdvice.getAdviceExpression()).thenReturn(adviceList);
560 when(mockRuleType.getObligationExpressions()).thenReturn(mockObEx);
561 when(mockObEx.getObligationExpression()).thenReturn(obExList);
562 when(mockObExType.getAttributeAssignmentExpression()).thenReturn(null);
563 when(mockObExType.getFulfillOn()).thenReturn(effectTypePermit);
564 when(adviceExpTypeMock.getAdviceId()).thenReturn("");
565 when(adviceExpTypeMock.getAppliesTo()).thenReturn(effectTypePermit);
566 when(adviceExpTypeMock.getAttributeAssignmentExpression()).thenReturn(attrList);
568 processor.rule(mockRuleType);
570 verify(mockRuleType, atLeast(1)).getRuleId();
571 verify(mockRuleType, atLeast(1)).getTarget();
572 verify(mockRuleType, atLeast(1)).getEffect();
573 verify(mockRuleType, atLeast(1)).getAdviceExpressions();
574 verify(mockRuleType, atLeast(1)).getObligationExpressions();
575 verify(mockTargetType, atLeast(1)).getAnyOf();
576 verify(mockObEx, atLeast(1)).getObligationExpression();
577 verify(mockObExType, atLeast(1)).getAttributeAssignmentExpression();
578 verify(mockObExType, atLeast(1)).getFulfillOn();
579 verify(mockAdvice, atLeast(1)).getAdviceExpression();
580 verify(adviceExpTypeMock, atLeast(1)).getAdviceId();
581 verify(adviceExpTypeMock, atLeast(1)).getAppliesTo();
582 verify(adviceExpTypeMock, atLeast(1)).getAttributeAssignmentExpression();
586 public void testHtmlProcessorOnPreVisitRule() {
587 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
588 PolicyType mockPolicyType = null;
589 RuleType mockRuleType = Mockito.mock(RuleType.class);
590 EffectType effectTypePermit = EffectType.PERMIT;
591 TargetType mockTargetType = Mockito.mock(TargetType.class);
592 processor = new HtmlProcessor(temp, mockPolicySetType);
594 List<AnyOfType> anyOfList = new ArrayList<AnyOfType>();
595 anyOfList.add(new AnyOfType());
597 when(mockRuleType.getCondition()).thenReturn(null);
598 when(mockRuleType.getDescription()).thenReturn(null);
599 when(mockRuleType.getEffect()).thenReturn(effectTypePermit);
600 when(mockRuleType.getTarget()).thenReturn(mockTargetType);
601 when(mockTargetType.getAnyOf()).thenReturn(anyOfList);
603 CallbackResult callbackResult = processor.onPreVisitRule(mockPolicyType, mockRuleType);
604 assertNotNull(callbackResult);
606 verify(mockRuleType, atLeast(1)).getCondition();
607 verify(mockRuleType, atLeast(1)).getDescription();
608 verify(mockRuleType, atLeast(1)).getEffect();
609 verify(mockRuleType, atLeast(1)).getTarget();
610 verify(mockRuleType, atLeast(1)).getAdviceExpressions();
611 verify(mockTargetType, atLeast(1)).getAnyOf();
613 mockPolicyType = Mockito.mock(PolicyType.class);
614 when(mockRuleType.getDescription()).thenReturn("");
616 callbackResult = processor.onPreVisitRule(mockPolicyType, mockRuleType);
617 assertNotNull(callbackResult);
621 public void testHtmlProcessorOnPostVisitRule() {
622 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
623 PolicyType mockPolicyType = null;
624 RuleType mockRuleType = Mockito.mock(RuleType.class);
626 processor = new HtmlProcessor(temp, mockPolicySetType);
627 CallbackResult callbackResult = processor.onPostVisitRule(mockPolicyType, mockRuleType);
628 assertNotNull(callbackResult);
630 mockPolicyType = Mockito.mock(PolicyType.class);
631 callbackResult = processor.onPostVisitRule(mockPolicyType, mockRuleType);
632 assertNotNull(callbackResult);
636 public void testHtmlProcessorProcessAttributeAssignments() {
637 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
638 processor = new HtmlProcessor(temp, mockPolicySetType);
640 RuleType mockRuleType = Mockito.mock(RuleType.class);
641 EffectType effectTypePermit = EffectType.PERMIT;
642 ObligationExpressionsType mockOblExsType = Mockito.mock(ObligationExpressionsType.class);
644 ObligationExpressionType mockOblExTypeListObj = Mockito.mock(ObligationExpressionType.class);
645 List<ObligationExpressionType> oblExTypeList = new ArrayList<ObligationExpressionType>();
646 oblExTypeList.add(mockOblExTypeListObj);
648 AttributeAssignmentExpressionType mockattrAssignListObj = Mockito.mock(AttributeAssignmentExpressionType.class);
649 List<AttributeAssignmentExpressionType> attrAssignList = new ArrayList<AttributeAssignmentExpressionType>();
650 attrAssignList.add(mockattrAssignListObj);
652 JAXBElement<?> jaxbElementMock = Mockito.mock(JAXBElement.class);
653 AttributeValueType attrValTypeMock = Mockito.mock(AttributeValueType.class);
654 AttributeDesignatorType attrDesignTypeMock = Mockito.mock(AttributeDesignatorType.class);
655 AttributeSelectorType attrSelTypeMock = Mockito.mock(AttributeSelectorType.class);
656 ApplyType applyTypeMock = Mockito.mock(ApplyType.class);
657 Object genericObjectMock = Mockito.mock(Object.class);
659 Object mockContentListObject = Mockito.mock(Object.class);
660 List<Object> contentList = new ArrayList<Object>();
661 contentList.add(mockContentListObject);
662 contentList.add(mockContentListObject);
664 when(mockRuleType.getEffect()).thenReturn(effectTypePermit);
665 when(mockRuleType.getObligationExpressions()).thenReturn(mockOblExsType);
666 when(mockOblExsType.getObligationExpression()).thenReturn(oblExTypeList);
667 when(mockOblExTypeListObj.getAttributeAssignmentExpression()).thenReturn(attrAssignList);
668 when(mockOblExTypeListObj.getFulfillOn()).thenReturn(effectTypePermit);
669 when(mockattrAssignListObj.getCategory()).thenReturn("");
670 when(mockattrAssignListObj.getAttributeId()).thenReturn("");
671 doReturn(jaxbElementMock).when(mockattrAssignListObj).getExpression();
672 doReturn(attrValTypeMock).when(jaxbElementMock).getValue();
673 when(attrValTypeMock.getContent()).thenReturn(contentList);
675 processor.rule(mockRuleType);
677 verify(mockRuleType, atLeast(1)).getEffect();
678 verify(mockRuleType, atLeast(1)).getObligationExpressions();
679 verify(mockOblExsType, atLeast(1)).getObligationExpression();
680 verify(mockOblExTypeListObj, atLeast(1)).getAttributeAssignmentExpression();
681 verify(mockOblExTypeListObj, atLeast(1)).getFulfillOn();
682 verify(mockattrAssignListObj, atLeast(1)).getExpression();
683 verify(jaxbElementMock, atLeast(1)).getValue();
684 verify(attrValTypeMock, atLeast(1)).getContent();
686 doReturn(attrDesignTypeMock).when(jaxbElementMock).getValue();
687 processor.rule(mockRuleType);
688 verify(jaxbElementMock, atLeast(1)).getValue();
690 doReturn(attrSelTypeMock).when(jaxbElementMock).getValue();
691 processor.rule(mockRuleType);
692 verify(jaxbElementMock, atLeast(1)).getValue();
694 doReturn(applyTypeMock).when(jaxbElementMock).getValue();
695 processor.rule(mockRuleType);
696 verify(jaxbElementMock, atLeast(1)).getValue();
698 doReturn(genericObjectMock).when(jaxbElementMock).getValue();
699 processor.rule(mockRuleType);
700 verify(jaxbElementMock, atLeast(1)).getValue();
704 public void testHtmlProcessorTarget() {
705 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
706 processor = new HtmlProcessor(temp, mockPolicySetType);
708 processor.target(null);
710 AnyOfType mockAnyOfType = Mockito.mock(AnyOfType.class);
711 List<AnyOfType> anyOfList = new ArrayList<AnyOfType>();
712 anyOfList.add(mockAnyOfType);
713 anyOfList.add(mockAnyOfType); // adding duplicate element
715 AllOfType mockAllOfType = Mockito.mock(AllOfType.class);
716 List<AllOfType> allOfTypeList = new ArrayList<AllOfType>();
717 allOfTypeList.add(mockAllOfType);
718 allOfTypeList.add(mockAllOfType); // adding duplicate element
720 MatchType mockMatchType = Mockito.mock(MatchType.class);
721 List<MatchType> matchTypeList = new ArrayList<MatchType>();
722 matchTypeList.add(mockMatchType);
723 matchTypeList.add(mockMatchType); // adding duplicate element
725 AttributeValueType mockAttrValType = Mockito.mock(AttributeValueType.class);
726 AttributeDesignatorType mockAttrDesType = Mockito.mock(AttributeDesignatorType.class);
727 AttributeSelectorType mockAttrSelType = Mockito.mock(AttributeSelectorType.class);
729 List<Object> contentList = new ArrayList<Object>();
731 when(mockAnyOfType.getAllOf()).thenReturn(allOfTypeList);
732 when(mockAllOfType.getMatch()).thenReturn(matchTypeList);
733 when(mockMatchType.getAttributeValue()).thenReturn(mockAttrValType);
734 when(mockMatchType.getMatchId()).thenReturn(XACML1.ID_FUNCTION_STRING_EQUAL.stringValue());
735 when(mockMatchType.getAttributeDesignator()).thenReturn(mockAttrDesType);
736 when(mockAttrValType.getDataType()).thenReturn("");
737 when(mockAttrValType.getContent()).thenReturn(contentList);
738 when(mockAttrDesType.getCategory()).thenReturn("");
739 when(mockAttrDesType.getAttributeId()).thenReturn("");
740 when(mockAttrDesType.getIssuer()).thenReturn("");
741 when(mockAttrDesType.getDataType()).thenReturn("");
742 processor.target(anyOfList);
743 verify(mockAnyOfType, atLeast(1)).getAllOf();
744 verify(mockAllOfType, atLeast(1)).getMatch();
745 verify(mockMatchType, atLeast(1)).getAttributeValue();
746 verify(mockMatchType, atLeast(1)).getMatchId();
747 verify(mockMatchType, atLeast(1)).getAttributeDesignator();
748 verify(mockAttrValType, atLeast(1)).getDataType();
749 verify(mockAttrValType, atLeast(1)).getContent();
750 verify(mockAttrDesType, atLeast(1)).getCategory();
751 verify(mockAttrDesType, atLeast(1)).getAttributeId();
752 verify(mockAttrDesType, atLeast(1)).getIssuer();
753 verify(mockAttrDesType, atLeast(1)).getDataType();
755 when(mockMatchType.getAttributeDesignator()).thenReturn(null);
756 when(mockMatchType.getAttributeSelector()).thenReturn(mockAttrSelType);
757 when(mockAttrSelType.getCategory()).thenReturn("");
758 when(mockAttrSelType.getContextSelectorId()).thenReturn("");
759 when(mockAttrSelType.getDataType()).thenReturn("");
760 processor.target(anyOfList);
761 verify(mockMatchType, atLeast(1)).getAttributeDesignator();
762 verify(mockMatchType, atLeast(1)).getAttributeSelector();
763 verify(mockAttrSelType, atLeast(1)).getCategory();
764 verify(mockAttrSelType, atLeast(1)).getContextSelectorId();
765 verify(mockAttrSelType, atLeast(1)).getDataType();
767 when(mockMatchType.getAttributeDesignator()).thenReturn(null);
768 when(mockMatchType.getAttributeSelector()).thenReturn(null);
769 processor.target(anyOfList);
770 verify(mockMatchType, atLeast(1)).getAttributeDesignator();
771 verify(mockMatchType, atLeast(1)).getAttributeSelector();
775 public void testHtmlProcessorStringifyExpression() {
776 PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
777 processor = new HtmlProcessor(temp, mockPolicySetType);
779 RuleType mockRuleType = Mockito.mock(RuleType.class);
780 ConditionType mockConditionType = Mockito.mock(ConditionType.class);
781 JAXBElement<?> mockJAXBElement = Mockito.mock(JAXBElement.class);
782 EffectType effectTypePermit = EffectType.PERMIT;
783 Object mockExpressObject = Mockito.mock(Object.class);
784 AttributeDesignatorType mockAttrDesType = Mockito.mock(AttributeDesignatorType.class);
785 AttributeSelectorType mockAttrSelType = Mockito.mock(AttributeSelectorType.class);
786 AttributeValueType mockAttrValType = Mockito.mock(AttributeValueType.class);
787 VariableReferenceType mockVarRefType = Mockito.mock(VariableReferenceType.class);
789 Object mockContentObject = Mockito.mock(Object.class);
790 List<Object> contentList = new ArrayList<Object>();
791 contentList.add(mockContentObject);
793 when(mockRuleType.getEffect()).thenReturn(effectTypePermit);
794 when(mockRuleType.getCondition()).thenReturn(mockConditionType);
795 doReturn(mockJAXBElement).when(mockConditionType).getExpression();
796 doReturn(mockExpressObject).when(mockJAXBElement).getValue();
799 processor.rule(mockRuleType);
801 } catch (IllegalArgumentException e) {
802 verify(mockRuleType, atLeast(1)).getEffect();
803 verify(mockRuleType, atLeast(1)).getCondition();
804 verify(mockConditionType, atLeast(1)).getExpression();
805 verify(mockJAXBElement, atLeast(1)).getValue();
808 doReturn(mockAttrDesType).when(mockJAXBElement).getValue();
809 when(mockAttrDesType.getCategory()).thenReturn("");
810 when(mockAttrDesType.getAttributeId()).thenReturn("");
811 when(mockAttrDesType.getDataType()).thenReturn("");
812 processor.rule(mockRuleType);
813 verify(mockJAXBElement, atLeast(1)).getValue();
814 verify(mockAttrDesType, atLeast(1)).getCategory();
815 verify(mockAttrDesType, atLeast(1)).getAttributeId();
816 verify(mockAttrDesType, atLeast(1)).getDataType();
818 doReturn(mockAttrSelType).when(mockJAXBElement).getValue();
819 when(mockAttrSelType.getPath()).thenReturn("SamplePath/text()");
820 processor.rule(mockRuleType);
821 verify(mockJAXBElement, atLeast(1)).getValue();
822 verify(mockAttrSelType, atLeast(1)).getPath();
824 when(mockAttrSelType.getPath()).thenReturn("");
825 processor.rule(mockRuleType);
826 verify(mockJAXBElement, atLeast(1)).getValue();
827 verify(mockAttrSelType, atLeast(1)).getPath();
829 doReturn(mockAttrValType).when(mockJAXBElement).getValue();
830 when(mockAttrValType.getContent()).thenReturn(contentList);
831 processor.rule(mockRuleType);
832 verify(mockJAXBElement, atLeast(1)).getValue();
833 verify(mockAttrValType, atLeast(1)).getContent();
835 doReturn(mockVarRefType).when(mockJAXBElement).getValue();
836 processor.rule(mockRuleType);
837 verify(mockJAXBElement, atLeast(1)).getValue();