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=========================================================
20 package org.onap.policy.xacml.pdp;
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;
35 @RunWith(PowerMockRunner.class)
36 public class ONAPPDPEngineFactoryTest {
38 public final void testNewEngine() {
39 ONAPPDPEngineFactory pdpEngine = new ONAPPDPEngineFactory();
41 assertTrue(pdpEngine.newEngine() != null);
42 } catch (Exception e) {
43 fail("operation failed, e=" + e);
48 public final void testNewEngineProperties() {
49 ONAPPDPEngineFactory pdpEngine = new ONAPPDPEngineFactory();
50 Properties properties = new Properties();
52 assertTrue(pdpEngine.newEngine(properties) != null);
53 } catch (Exception e) {
54 fail("operation failed, e=" + e);
58 @PrepareForTest({EvaluationContextFactory.class, FactoryFinder.class})
59 @Test(expected = FactoryException.class)
60 public void negTestEngine() throws FactoryException {
62 PowerMockito.mockStatic(FactoryFinder.class);
63 PowerMockito.when(FactoryFinder.find(Mockito.any(), Mockito.any(), Mockito.any()))
66 // Negative test factory
67 ONAPPDPEngineFactory factory = new ONAPPDPEngineFactory();
69 fail("Expecting an exception.");
72 @PrepareForTest({EvaluationContextFactory.class, FactoryFinder.class})
73 @Test(expected = FactoryException.class)
74 public void negTestEngine2() throws FactoryException {
76 PowerMockito.mockStatic(FactoryFinder.class);
77 PowerMockito.when(FactoryFinder.find(Mockito.any(), Mockito.any(), Mockito.any()))
80 // Negative test factory
81 ONAPPDPEngineFactory factory = new ONAPPDPEngineFactory();
82 Properties properties = new Properties();
83 factory.newEngine(properties);
84 fail("Expecting an exception.");