2 * ============LICENSE_START=======================================================
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
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.PrepareForTest;
37 import org.powermock.modules.junit4.PowerMockRunner;
39 @RunWith(PowerMockRunner.class)
40 public class OnapPdpEngineFactoryTest {
42 public final void testNewEngine() {
43 final OnapPdpEngineFactory pdpEngine = new OnapPdpEngineFactory();
45 assertTrue(pdpEngine.newEngine() != null);
46 } catch (final Exception e) {
47 fail("operation failed, e=" + e);
52 public final void testNewEngineProperties() {
53 final OnapPdpEngineFactory pdpEngine = new OnapPdpEngineFactory();
54 final Properties properties = new Properties();
56 assertTrue(pdpEngine.newEngine(properties) != null);
57 } catch (final Exception e) {
58 fail("operation failed, e=" + e);
62 @PrepareForTest({ EvaluationContextFactory.class, FactoryFinder.class })
63 @Test(expected = FactoryException.class)
64 public void negTestEngine() throws FactoryException {
66 PowerMockito.mockStatic(FactoryFinder.class);
67 PowerMockito.when(FactoryFinder.find(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(null);
69 // Negative test factory
70 final OnapPdpEngineFactory factory = new OnapPdpEngineFactory();
72 fail("Expecting an exception.");
75 @PrepareForTest({ EvaluationContextFactory.class, FactoryFinder.class })
76 @Test(expected = FactoryException.class)
77 public void negTestEngine2() throws FactoryException {
79 PowerMockito.mockStatic(FactoryFinder.class);
80 PowerMockito.when(FactoryFinder.find(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(null);
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.");