JUnit additions and powermock pom fixes
[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 package org.onap.policy.xacml.pdp;
21
22 import static org.junit.Assert.assertTrue;
23 import static org.junit.Assert.fail;
24 import java.util.Properties;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.mockito.Mockito;
28 import org.powermock.api.mockito.PowerMockito;
29 import org.powermock.core.classloader.annotations.PrepareForTest;
30 import org.powermock.modules.junit4.PowerMockRunner;
31 import com.att.research.xacml.util.FactoryException;
32 import com.att.research.xacml.util.FactoryFinder;
33 import com.att.research.xacmlatt.pdp.eval.EvaluationContextFactory;
34
35 @RunWith(PowerMockRunner.class)
36 public class ONAPPDPEngineFactoryTest {
37   @Test
38   public final void testNewEngine() {
39     ONAPPDPEngineFactory pdpEngine = new ONAPPDPEngineFactory();
40     try {
41       assertTrue(pdpEngine.newEngine() != null);
42     } catch (Exception e) {
43       fail("operation failed, e=" + e);
44     }
45   }
46
47   @Test
48   public final void testNewEngineProperties() {
49     ONAPPDPEngineFactory pdpEngine = new ONAPPDPEngineFactory();
50     Properties properties = new Properties();
51     try {
52       assertTrue(pdpEngine.newEngine(properties) != null);
53     } catch (Exception e) {
54       fail("operation failed, e=" + e);
55     }
56   }
57
58   @PrepareForTest({EvaluationContextFactory.class, FactoryFinder.class})
59   @Test(expected = FactoryException.class)
60   public void negTestEngine() throws FactoryException {
61     // Setup test data
62     PowerMockito.mockStatic(FactoryFinder.class);
63     PowerMockito.when(FactoryFinder.find(Mockito.any(), Mockito.any(), Mockito.any()))
64         .thenReturn(null);
65
66     // Negative test factory
67     ONAPPDPEngineFactory factory = new ONAPPDPEngineFactory();
68     factory.newEngine();
69     fail("Expecting an exception.");
70   }
71
72   @PrepareForTest({EvaluationContextFactory.class, FactoryFinder.class})
73   @Test(expected = FactoryException.class)
74   public void negTestEngine2() throws FactoryException {
75     // Setup test data
76     PowerMockito.mockStatic(FactoryFinder.class);
77     PowerMockito.when(FactoryFinder.find(Mockito.any(), Mockito.any(), Mockito.any()))
78         .thenReturn(null);
79
80     // Negative test factory
81     ONAPPDPEngineFactory factory = new ONAPPDPEngineFactory();
82     Properties properties = new Properties();
83     factory.newEngine(properties);
84     fail("Expecting an exception.");
85   }
86 }