Add and modify jUnits for code coverage (components)
[policy/engine.git] / POLICY-SDK-APP / src / test / java / org / onap / policy / components / HumanPolicyComponentTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Engine
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.policy.components;
22
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;
29
30 import com.att.research.xacml.util.XACMLPolicyScanner.CallbackResult;
31 import java.io.File;
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;
52
53 public class HumanPolicyComponentTest {
54
55     private AttributeIdentifiers attrIds;
56     private HtmlProcessor processor;
57     private static File temp;
58     private static File tempAction;
59     private static File tempConfig;
60
61     @BeforeClass
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");
66         temp.deleteOnExit();
67         tempAction.deleteOnExit();
68         tempConfig.deleteOnExit();
69     }
70
71     @Test
72     public void testAttributeIdentifiers() {
73         String testCategory = "testCategory";
74         String testID = "testId";
75         String testType = "testType";
76         String newTestType = "testNewType";
77
78         attrIds = new AttributeIdentifiers(testCategory, testType, testID);
79         assertEquals(testCategory, attrIds.category);
80         assertEquals(testID, attrIds.id);
81         assertEquals(testType, attrIds.getType());
82
83         attrIds.setType(newTestType);
84         assertEquals(newTestType, attrIds.getType());
85     }
86
87     @SuppressWarnings("unchecked")
88     @Test
89     public void testHumanPolicyComponentException() {
90         JAXBElement<PolicySetType> mockRoot = Mockito.mock(JAXBElement.class);
91         when(mockRoot.getValue()).thenReturn(null);
92         assertNull(HumanPolicyComponent.DescribePolicy(temp));
93     }
94
95     @Test(expected = IllegalArgumentException.class)
96     public void testHtmlProcessorNull() throws IOException {
97         processor = new HtmlProcessor(null, null);
98     }
99
100     @Test(expected = IllegalArgumentException.class)
101     public void testHtmlProcessor() throws IOException {
102         File tempFile = File.createTempFile("testFile", ".tmp");
103         tempFile.delete();
104         processor = new HtmlProcessor(tempFile, null);
105     }
106
107     @Test(expected = IllegalArgumentException.class)
108     public void testHtmlProcessorInvalidObject() throws IOException {
109         processor = new HtmlProcessor(temp, null);
110     }
111
112     @Test
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();
118     }
119
120     @Test
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();
126     }
127
128     @Test
129     public void testHtmlProcessorConfigPolicyType() {
130         PolicyType mockPolicyType = Mockito.mock(PolicyType.class);
131         processor = new HtmlProcessor(tempConfig, mockPolicyType);
132         verify(mockPolicyType).getVersion();
133     }
134
135     @Test
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();
141     }
142
143     @Test
144     public void testHtmlProcessorOnPreVisitPolicySet() {
145         PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
146         PolicySetType mockPolicyParent = Mockito.mock(PolicySetType.class);
147
148         processor = new HtmlProcessor(temp, mockPolicySetType);
149
150         when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(Collections.emptyList());
151         when(mockPolicySetType.getDescription()).thenReturn(null);
152
153         CallbackResult preResult = processor.onPreVisitPolicySet(mockPolicyParent, mockPolicySetType);
154         assertEquals("CONTINUE", preResult.name());
155         verify(mockPolicySetType, atLeast(1)).getPolicySetOrPolicyOrPolicySetIdReference();
156         verify(mockPolicySetType, atLeast(1)).getDescription();
157     }
158     @Test
159     public void testHtmlProcessorOnPreVisitPolicySetNullParent() {
160         PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
161         PolicySetType mockPolicyParent = null;
162         JAXBElement<?> mockElement = Mockito.mock(JAXBElement.class);
163
164         List<JAXBElement<?>> testList = new ArrayList<JAXBElement<?>>();
165         testList.add(mockElement);
166
167         processor = new HtmlProcessor(temp, mockPolicySetType);
168
169         when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(testList);
170         when(mockPolicySetType.getDescription()).thenReturn("");
171
172         CallbackResult preResult = processor.onPreVisitPolicySet(mockPolicyParent, mockPolicySetType);
173         assertEquals("CONTINUE", preResult.name());
174         verify(mockPolicySetType, atLeast(1)).getPolicySetOrPolicyOrPolicySetIdReference();
175         verify(mockPolicySetType, atLeast(1)).getDescription();
176     }
177
178     @Test
179     public void testHtmlProcessorOnPostVisitPolicySet() {
180         PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
181         PolicySetType mockPolicyParent = Mockito.mock(PolicySetType.class);
182
183         processor = new HtmlProcessor(temp, mockPolicySetType);
184
185         when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(Collections.emptyList());
186         when(mockPolicySetType.getDescription()).thenReturn(null);
187
188         CallbackResult postResult = processor.onPostVisitPolicySet(mockPolicyParent, mockPolicySetType);
189         assertEquals("CONTINUE", postResult.name());
190         verify(mockPolicySetType, atLeast(1)).getPolicySetOrPolicyOrPolicySetIdReference();
191         verify(mockPolicySetType, atLeast(1)).getDescription();
192     }
193
194     @Test
195     public void testHtmlProcessorOnPostVisitPolicySetNullParent() {
196         PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
197         PolicySetType mockPolicyParent = null;
198         JAXBElement<?> mockElement = Mockito.mock(JAXBElement.class);
199
200         List<JAXBElement<?>> testList = new ArrayList<JAXBElement<?>>();
201         testList.add(mockElement);
202
203         processor = new HtmlProcessor(temp, mockPolicySetType);
204
205         when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(testList);
206         when(mockPolicySetType.getDescription()).thenReturn("");
207
208         CallbackResult postResult = processor.onPostVisitPolicySet(mockPolicyParent, mockPolicySetType);
209         assertEquals("CONTINUE", postResult.name());
210         verify(mockPolicySetType, atLeast(1)).getPolicySetOrPolicyOrPolicySetIdReference();
211         verify(mockPolicySetType, atLeast(1)).getDescription();
212     }
213
214     @Test
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);
220
221         when(mockPolicyType.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()).thenReturn(testList);
222         when(mockPolicySetType.getDescription()).thenReturn(null);
223
224         CallbackResult preResult = processor.onPreVisitPolicy(mockPolicySetType, mockPolicyType);
225         assertEquals("CONTINUE", preResult.name());
226         verify(mockPolicyType, atLeast(1)).getCombinerParametersOrRuleCombinerParametersOrVariableDefinition();
227         verify(mockPolicyType, atLeast(1)).getDescription();
228     }
229
230     @Test
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);
237
238         when(mockPolicyType.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()).thenReturn(testList);
239         when(mockPolicyType.getDescription()).thenReturn("");
240
241         CallbackResult preResult = processor.onPreVisitPolicy(mockPolicyParent, mockPolicyType);
242         assertEquals("CONTINUE", preResult.name());
243         verify(mockPolicyType, atLeast(1)).getCombinerParametersOrRuleCombinerParametersOrVariableDefinition();
244         verify(mockPolicyType, atLeast(1)).getDescription();
245
246     }
247
248     @Test
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);
254
255         when(mockPolicyType.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()).thenReturn(testList);
256
257         CallbackResult postResult = processor.onPostVisitPolicy(mockPolicySetType, mockPolicyType);
258         assertEquals("CONTINUE", postResult.name());
259         verify(mockPolicyType, atLeast(1)).getCombinerParametersOrRuleCombinerParametersOrVariableDefinition();
260     }
261
262     @Test
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);
269
270         when(mockPolicyType.getCombinerParametersOrRuleCombinerParametersOrVariableDefinition()).thenReturn(testList);
271
272         CallbackResult postResult = processor.onPostVisitPolicy(mockPolicyParent, mockPolicyType);
273         assertEquals("CONTINUE", postResult.name());
274         verify(mockPolicyType, atLeast(1)).getCombinerParametersOrRuleCombinerParametersOrVariableDefinition();
275     }
276
277     @Test
278     public void testHtmlProcessorPolicy() {
279         PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
280         PolicyType mockPolicyType = Mockito.mock(PolicyType.class);
281         processor = new HtmlProcessor(temp, mockPolicySetType);
282
283         when(mockPolicyType.getRuleCombiningAlgId()).thenReturn(null);
284         when(mockPolicyType.getPolicyId()).thenReturn(null);
285         when(mockPolicyType.getVersion()).thenReturn(null);
286         when(mockPolicyType.getTarget()).thenReturn(null);
287
288         processor.policy(mockPolicyType);
289         verify(mockPolicyType).getRuleCombiningAlgId();
290         verify(mockPolicyType).getPolicyId();
291         verify(mockPolicyType).getVersion();
292         verify(mockPolicyType).getTarget();
293     }
294
295     @Test
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);
302
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);
308
309         processor.policy(mockPolicyType);
310
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();
316     }
317
318     @Test
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);
326
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);
332
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();
339     }
340
341     @Test
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);
347
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);
354
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();
362     }
363
364     @Test
365     public void testHtmlProcessorPolicySet() {
366         PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
367         processor = new HtmlProcessor(temp, mockPolicySetType);
368
369         when(mockPolicySetType.getPolicyCombiningAlgId()).thenReturn("");
370         when(mockPolicySetType.getPolicySetId()).thenReturn("");
371         when(mockPolicySetType.getVersion()).thenReturn("");
372
373         processor.policySet(mockPolicySetType, "");
374         verify(mockPolicySetType, atLeast(1)).getPolicyCombiningAlgId();
375         verify(mockPolicySetType, atLeast(1)).getPolicySetId();
376         verify(mockPolicySetType, atLeast(1)).getVersion();
377     }
378
379     @Test
380     public void testHtmlProcessorPolicySetNull() {
381         PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
382         TargetType mockTargetType = Mockito.mock(TargetType.class);
383         processor = new HtmlProcessor(temp, mockPolicySetType);
384
385         when(mockPolicySetType.getTarget()).thenReturn(mockTargetType);
386         when(mockTargetType.getAnyOf()).thenReturn(null);
387         when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(null);
388
389         processor.policySet(mockPolicySetType, "");
390         verify(mockPolicySetType, atLeast(1)).getTarget();
391         verify(mockTargetType, atLeast(1)).getAnyOf();
392         verify(mockPolicySetType, atLeast(1)).getPolicySetOrPolicyOrPolicySetIdReference();
393     }
394
395     @Test
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);
401
402         when(mockPolicySetType.getTarget()).thenReturn(mockTargetType);
403         when(mockTargetType.getAnyOf()).thenReturn(anyOfList);
404         when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(null);
405
406         processor.policySet(mockPolicySetType, "");
407         verify(mockPolicySetType, atLeast(1)).getTarget();
408         verify(mockTargetType, atLeast(1)).getAnyOf();
409         verify(mockPolicySetType, atLeast(1)).getPolicySetOrPolicyOrPolicySetIdReference();
410     }
411
412     @Test
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());
418
419         when(mockPolicySetType.getTarget()).thenReturn(mockTargetType);
420         when(mockTargetType.getAnyOf()).thenReturn(anyOfList);
421         when(mockPolicySetType.getPolicySetOrPolicyOrPolicySetIdReference()).thenReturn(null);
422
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();
428     }
429
430     @Test
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);
439
440         List<ObligationExpressionType> oblList = new ArrayList<ObligationExpressionType>();
441         oblList.add(mockOEType);
442
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);
450
451         processor.rule(mockRuleType);
452
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();
459     }
460
461     @Test
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);
470
471         List<AnyOfType> anyOfList = new ArrayList<AnyOfType>();
472         List<AdviceExpressionType> adviceExList = new ArrayList<AdviceExpressionType>();
473         adviceExList.add(mockAdviceEx);
474
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);
484
485         processor.rule(mockRuleType);
486
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();
497
498         when(mockTargetType.getAnyOf()).thenReturn(anyOfList);
499         processor.rule(mockRuleType);
500         verify(mockTargetType, atLeast(1)).getAnyOf();
501     }
502
503     @Test
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);
514
515         List<AnyOfType> anyOfList = new ArrayList<AnyOfType>();
516         anyOfList.add(new AnyOfType());
517
518         List<AdviceExpressionType> adviceList = new ArrayList<AdviceExpressionType>();
519         adviceList.add(adviceExpTypeMock);
520
521         List<AttributeAssignmentExpressionType> attrList = new ArrayList<AttributeAssignmentExpressionType>();
522
523         List<ObligationExpressionType> obExList = new ArrayList<ObligationExpressionType>();
524         obExList.add(mockObExType);
525
526         List<Object> contentList = new ArrayList<>();
527         contentList.add(new Object());
528
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);
542
543         processor.rule(mockRuleType);
544
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();
558     }
559
560     @Test
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);
568
569         List<AnyOfType> anyOfList = new ArrayList<AnyOfType>();
570         anyOfList.add(new AnyOfType());
571
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);
577
578         CallbackResult callbackResult = processor.onPreVisitRule(mockPolicyType, mockRuleType);
579         assertNotNull(callbackResult);
580
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();
587
588         mockPolicyType = Mockito.mock(PolicyType.class);
589         when(mockRuleType.getDescription()).thenReturn("");
590
591         callbackResult = processor.onPreVisitRule(mockPolicyType, mockRuleType);
592         assertNotNull(callbackResult);
593     }
594
595     @Test
596     public void testHtmlProcessorOnPostVisitRule() {
597         PolicySetType mockPolicySetType = Mockito.mock(PolicySetType.class);
598         PolicyType mockPolicyType = null;
599         RuleType mockRuleType = Mockito.mock(RuleType.class);
600
601         processor = new HtmlProcessor(temp, mockPolicySetType);
602         CallbackResult callbackResult = processor.onPostVisitRule(mockPolicyType, mockRuleType);
603         assertNotNull(callbackResult);
604
605         mockPolicyType = Mockito.mock(PolicyType.class);
606         callbackResult = processor.onPostVisitRule(mockPolicyType, mockRuleType);
607         assertNotNull(callbackResult);
608     }
609 }