d3ee544a584d61d94d8d730b022c09fdf09e2469
[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 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.PrepareForTest;
37 import org.powermock.modules.junit4.PowerMockRunner;
38
39 @RunWith(PowerMockRunner.class)
40 public class OnapPdpEngineFactoryTest {
41     @Test
42     public final void testNewEngine() {
43         final OnapPdpEngineFactory pdpEngine = new OnapPdpEngineFactory();
44         try {
45             assertTrue(pdpEngine.newEngine() != null);
46         } catch (final Exception e) {
47             fail("operation failed, e=" + e);
48         }
49     }
50
51     @Test
52     public final void testNewEngineProperties() {
53         final OnapPdpEngineFactory pdpEngine = new OnapPdpEngineFactory();
54         final Properties properties = new Properties();
55         try {
56             assertTrue(pdpEngine.newEngine(properties) != null);
57         } catch (final Exception e) {
58             fail("operation failed, e=" + e);
59         }
60     }
61
62     @PrepareForTest({ EvaluationContextFactory.class, FactoryFinder.class })
63     @Test(expected = FactoryException.class)
64     public void negTestEngine() throws FactoryException {
65         // Setup test data
66         PowerMockito.mockStatic(FactoryFinder.class);
67         PowerMockito.when(FactoryFinder.find(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(null);
68
69         // Negative test factory
70         final OnapPdpEngineFactory factory = new OnapPdpEngineFactory();
71         factory.newEngine();
72         fail("Expecting an exception.");
73     }
74
75     @PrepareForTest({ EvaluationContextFactory.class, FactoryFinder.class })
76     @Test(expected = FactoryException.class)
77     public void negTestEngine2() throws FactoryException {
78         // Setup test data
79         PowerMockito.mockStatic(FactoryFinder.class);
80         PowerMockito.when(FactoryFinder.find(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(null);
81
82         // Negative test factory
83         final OnapPdpEngineFactory factory = new OnapPdpEngineFactory();
84         final Properties properties = new Properties();
85         factory.newEngine(properties);
86         fail("Expecting an exception.");
87     }
88 }