2 * ============LICENSE_START=======================================================
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
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.xacml.pdp;
23 import static org.junit.Assert.assertTrue;
24 import static org.junit.Assert.fail;
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;
30 import java.util.Properties;
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;
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 {
45 public final void testNewEngine() {
46 final OnapPdpEngineFactory pdpEngine = new OnapPdpEngineFactory();
48 assertTrue(pdpEngine.newEngine() != null);
49 } catch (final Exception e) {
50 fail("operation failed, e=" + e);
55 public final void testNewEngineProperties() {
56 final OnapPdpEngineFactory pdpEngine = new OnapPdpEngineFactory();
57 final Properties properties = new Properties();
59 assertTrue(pdpEngine.newEngine(properties) != null);
60 } catch (final Exception e) {
61 fail("operation failed, e=" + e);
65 @PrepareForTest({ EvaluationContextFactory.class, FactoryFinder.class })
66 @Test(expected = FactoryException.class)
67 public void testNegTestEngine() throws FactoryException {
69 PowerMockito.mockStatic(FactoryFinder.class);
70 PowerMockito.when(FactoryFinder.find(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(null);
72 // Negative test factory
73 final OnapPdpEngineFactory factory = new OnapPdpEngineFactory();
75 fail("Expecting an exception.");
78 @PrepareForTest({ EvaluationContextFactory.class, FactoryFinder.class })
79 @Test(expected = FactoryException.class)
80 public void testNegTestEngine2() throws FactoryException {
82 PowerMockito.mockStatic(FactoryFinder.class);
83 PowerMockito.when(FactoryFinder.find(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(null);
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.");