2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 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.brms.api;
23 import static org.junit.Assert.assertFalse;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertNull;
26 import static org.junit.Assert.fail;
28 import org.junit.After;
29 import org.junit.AfterClass;
30 import org.junit.Before;
31 import org.junit.BeforeClass;
32 import org.junit.Test;
33 import org.mockito.Mockito;
34 import org.onap.policy.api.PolicyException;
35 import org.onap.policy.brms.api.BrmsGateway.Factory;
36 import org.powermock.reflect.Whitebox;
38 public class BrmsGatewayTest {
39 private static final String FACTORY_FIELD = "factory";
41 private static Factory saveFactory;
43 private Thread thread;
46 public static void setUpBeforeClass() {
47 saveFactory = Whitebox.getInternalState(BrmsGateway.class, FACTORY_FIELD);
51 public static void tearDownAfterClass() {
52 Whitebox.setInternalState(BrmsGateway.class, FACTORY_FIELD, saveFactory);
62 Factory factory = new Factory() {
64 public BrmsHandler makeBrmsHandler(String configFile) throws PolicyException {
66 return Mockito.mock(BrmsHandler.class);
70 public Thread makeThread(Runnable runnable) {
71 thread = super.makeThread(runnable);
77 Whitebox.setInternalState(BrmsGateway.class, FACTORY_FIELD, factory);
81 * Interrupts the thread, if there is one.
84 public void tearDown() throws InterruptedException {
88 assertFalse(thread.isAlive());
93 public void testFactory() throws InterruptedException {
94 assertNotNull(saveFactory);
95 assertNotNull(saveFactory.makeThread(() -> { }));
99 public void testGet() {
100 assertNull(BrmsGateway.getPolicyEngine());
104 public void testMain() throws Exception {
106 final String[] args = new String[0];
107 BrmsGateway.main(args);
108 } catch (final Exception ex) {
109 fail("Not expected an exception: " + ex);