policy/engine jdk11 upgrades
[policy/engine.git] / ONAP-PDP / src / test / java / org / onap / policy / xacml / pdp / OnapPdpEngineFactoryTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP-PDP
4  * ================================================================================
5  * Copyright (C) 2017-2018, 2020 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.xacml.pdp;
22
23 import static org.junit.Assert.assertTrue;
24 import static org.junit.Assert.fail;
25
26 import com.att.research.xacml.util.FactoryException;
27 import com.att.research.xacml.util.FactoryFinder;
28 import com.att.research.xacmlatt.pdp.eval.EvaluationContextFactory;
29
30 import java.util.Properties;
31
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34 import org.mockito.Mockito;
35 import org.powermock.api.mockito.PowerMockito;
36 import org.powermock.core.classloader.annotations.PowerMockIgnore;
37 import org.powermock.core.classloader.annotations.PrepareForTest;
38 import org.powermock.modules.junit4.PowerMockRunner;
39
40 @RunWith(PowerMockRunner.class)
41 @PowerMockIgnore({"com.sun.org.apache.xerces.*", "jdk.internal.reflect.*", "javax.xml.*", "org.xml.*"})
42 @PrepareForTest(OnapPdpEngineFactory.class)
43 public class OnapPdpEngineFactoryTest {
44     @Test
45     public final void testNewEngine() {
46         final OnapPdpEngineFactory pdpEngine = new OnapPdpEngineFactory();
47         try {
48             assertTrue(pdpEngine.newEngine() != null);
49         } catch (final Exception e) {
50             fail("operation failed, e=" + e);
51         }
52     }
53
54     @Test
55     public final void testNewEngineProperties() {
56         final OnapPdpEngineFactory pdpEngine = new OnapPdpEngineFactory();
57         final Properties properties = new Properties();
58         try {
59             assertTrue(pdpEngine.newEngine(properties) != null);
60         } catch (final Exception e) {
61             fail("operation failed, e=" + e);
62         }
63     }
64
65     @PrepareForTest({ EvaluationContextFactory.class, FactoryFinder.class })
66     @Test(expected = FactoryException.class)
67     public void testNegTestEngine() throws FactoryException {
68         // Setup test data
69         PowerMockito.mockStatic(FactoryFinder.class);
70         PowerMockito.when(FactoryFinder.find(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(null);
71
72         // Negative test factory
73         final OnapPdpEngineFactory factory = new OnapPdpEngineFactory();
74         factory.newEngine();
75         fail("Expecting an exception.");
76     }
77
78     @PrepareForTest({ EvaluationContextFactory.class, FactoryFinder.class })
79     @Test(expected = FactoryException.class)
80     public void testNegTestEngine2() throws FactoryException {
81         // Setup test data
82         PowerMockito.mockStatic(FactoryFinder.class);
83         PowerMockito.when(FactoryFinder.find(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(null);
84
85         // Negative test factory
86         final OnapPdpEngineFactory factory = new OnapPdpEngineFactory();
87         final Properties properties = new Properties();
88         factory.newEngine(properties);
89         fail("Expecting an exception.");
90     }
91 }