aboutsummaryrefslogtreecommitdiffstats
path: root/BRMSGateway/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'BRMSGateway/src/test/java')
-rw-r--r--BRMSGateway/src/test/java/org/onap/policy/brms/BrmsPushTest.java26
-rw-r--r--BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsGatewayTest.java91
-rw-r--r--BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsHandlerTest.java15
-rw-r--r--BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsPushTest.java14
4 files changed, 100 insertions, 46 deletions
diff --git a/BRMSGateway/src/test/java/org/onap/policy/brms/BrmsPushTest.java b/BRMSGateway/src/test/java/org/onap/policy/brms/BrmsPushTest.java
index de1a7d6eb..994e97368 100644
--- a/BRMSGateway/src/test/java/org/onap/policy/brms/BrmsPushTest.java
+++ b/BRMSGateway/src/test/java/org/onap/policy/brms/BrmsPushTest.java
@@ -2,7 +2,7 @@
* ============LICENSE_START=======================================================
* ONAP Policy Engine
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017, 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -81,7 +81,7 @@ public class BrmsPushTest {
}
@Test(expected = PolicyException.class)
- public void brmsHandlerFailTest2() throws PolicyException {
+ public void testBrmsHandlerFail2() throws PolicyException {
final PropertyChange prop = new PropertyChange();
prop.key = "defaultName";
prop.remove = true;
@@ -92,7 +92,7 @@ public class BrmsPushTest {
}
@Test(expected = PolicyException.class)
- public void brmsHandlerFailTest3() throws PolicyException {
+ public void testBrmsHandlerFail3() throws PolicyException {
PropertyChange prop = new PropertyChange();
prop.key = "repositoryID";
prop.remove = true;
@@ -107,7 +107,7 @@ public class BrmsPushTest {
}
@Test(expected = PolicyException.class)
- public void brmsHandlerFailTest4() throws PolicyException {
+ public void testBrmsHandlerFail4() throws PolicyException {
final PropertyChange prop = new PropertyChange();
prop.key = "repositoryURL";
prop.remove = true;
@@ -118,7 +118,7 @@ public class BrmsPushTest {
}
@Test(expected = PolicyException.class)
- public void brmsHandlerFailTest5() throws PolicyException {
+ public void testBrmsHandlerFail5() throws PolicyException {
final PropertyChange prop = new PropertyChange();
prop.key = "repositoryName";
prop.remove = true;
@@ -129,7 +129,7 @@ public class BrmsPushTest {
}
@Test(expected = PolicyException.class)
- public void brmsHandlerFailTest6() throws PolicyException {
+ public void testBrmsHandlerFail6() throws PolicyException {
PropertyChange prop = new PropertyChange();
prop.key = "repositoryURL";
prop.value = "http://nexus:8081/nexus/content/repositories/releases,"
@@ -146,7 +146,7 @@ public class BrmsPushTest {
}
@Test(expected = PolicyException.class)
- public void brmsHandlerFailTest7() throws PolicyException {
+ public void testBrmsHandlerFail7() throws PolicyException {
final PropertyChange prop = new PropertyChange();
prop.key = "repositoryPassword";
prop.remove = true;
@@ -157,7 +157,7 @@ public class BrmsPushTest {
}
@Test(expected = PolicyException.class)
- public void brmsHandlerFailTest8() throws PolicyException {
+ public void testBrmsHandlerFail8() throws PolicyException {
final PropertyChange prop = new PropertyChange();
prop.key = "policyKeyID";
prop.remove = true;
@@ -168,7 +168,7 @@ public class BrmsPushTest {
}
@Test(expected = PolicyException.class)
- public void brmsHandlerFailTest9() throws PolicyException {
+ public void testBrmsHandlerFail9() throws PolicyException {
PropertyChange prop = new PropertyChange();
prop.key = "sync";
prop.value = "true";
@@ -188,7 +188,7 @@ public class BrmsPushTest {
}
@Test(expected = PolicyException.class)
- public void brmsHandlerFailTest10() throws PolicyException {
+ public void testBrmsHandlerFail10() throws PolicyException {
final PropertyChange prop = new PropertyChange();
prop.key = "groupNames";
prop.value = "";
@@ -200,7 +200,7 @@ public class BrmsPushTest {
}
@Test(expected = PolicyException.class)
- public void brmsHandlerFailTest11() throws PolicyException {
+ public void testBrmsHandlerFail11() throws PolicyException {
final PropertyChange prop = new PropertyChange();
prop.key = "default.groupID";
prop.remove = true;
@@ -211,7 +211,7 @@ public class BrmsPushTest {
}
@Test(expected = PolicyException.class)
- public void brmsHandlerFailTest12() throws PolicyException {
+ public void testBrmsHandlerFail12() throws PolicyException {
final PropertyChange prop = new PropertyChange();
prop.key = "default.artifactID";
prop.remove = true;
@@ -222,7 +222,7 @@ public class BrmsPushTest {
}
@Test(expected = PolicyException.class)
- public void brmsHandlerFailTest13() throws PolicyException {
+ public void testBrmsHandlerFail13() throws PolicyException {
PropertyChange prop = new PropertyChange();
prop.key = "NOTIFICATION_TYPE";
prop.value = "dmaap";
diff --git a/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsGatewayTest.java b/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsGatewayTest.java
index fd8a7ed3b..f5a4fff8a 100644
--- a/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsGatewayTest.java
+++ b/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsGatewayTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP Policy Engine
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2019 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -20,37 +20,88 @@
package org.onap.policy.brms.api;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
import org.junit.Test;
-import org.junit.runner.RunWith;
import org.mockito.Mockito;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
+import org.onap.policy.api.PolicyException;
+import org.onap.policy.brms.api.BrmsGateway.Factory;
+import org.powermock.reflect.Whitebox;
-@RunWith(PowerMockRunner.class)
public class BrmsGatewayTest {
+ private static final String FACTORY_FIELD = "factory";
+
+ private static Factory saveFactory;
+
+ private Thread thread;
+
+ @BeforeClass
+ public static void setUpBeforeClass() {
+ saveFactory = Whitebox.getInternalState(BrmsGateway.class, FACTORY_FIELD);
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() {
+ Whitebox.setInternalState(BrmsGateway.class, FACTORY_FIELD, saveFactory);
+ }
+
+ /**
+ * Installs a factory.
+ */
+ @Before
+ public void setUp() {
+ thread = null;
+
+ Factory factory = new Factory() {
+ @Override
+ public BrmsHandler makeBrmsHandler(String configFile) throws PolicyException {
+ // Mock handler
+ return Mockito.mock(BrmsHandler.class);
+ }
+
+ @Override
+ public Thread makeThread(Runnable runnable) {
+ thread = super.makeThread(runnable);
+ return thread;
+ }
+
+ };
+
+ Whitebox.setInternalState(BrmsGateway.class, FACTORY_FIELD, factory);
+ }
+
+ /**
+ * Interrupts the thread, if there is one.
+ */
+ @After
+ public void tearDown() throws InterruptedException {
+ if (thread != null) {
+ thread.interrupt();
+ thread.join(5000L);
+ assertFalse(thread.isAlive());
+ }
+ }
+
+ @Test
+ public void testFactory() throws InterruptedException {
+ assertNotNull(saveFactory);
+ assertNotNull(saveFactory.makeThread(() -> { }));
+ }
+
@Test
public void testGet() {
assertNull(BrmsGateway.getPolicyEngine());
}
- @PrepareForTest({Thread.class, BrmsGateway.class})
@Test
public void testMain() throws Exception {
- // Mock Thread
- PowerMockito.spy(Thread.class);
- PowerMockito.doNothing().when(Thread.class);
- Thread.sleep(1000);
-
- // Mock handler
- final BrmsHandler handler = Mockito.mock(BrmsHandler.class);
- PowerMockito.whenNew(BrmsHandler.class).withArguments(any()).thenReturn(handler);
-
- // Run app
try {
final String[] args = new String[0];
BrmsGateway.main(args);
diff --git a/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsHandlerTest.java b/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsHandlerTest.java
index 1a6dc4719..079db2109 100644
--- a/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsHandlerTest.java
+++ b/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsHandlerTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP Policy Engine
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,13 +23,12 @@ package org.onap.policy.brms.api;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
-import javax.persistence.Query;
import javax.persistence.TypedQuery;
import org.junit.Test;
@@ -39,14 +38,16 @@ import org.onap.policy.api.NotificationType;
import org.onap.policy.std.StdPDPNotification;
import org.onap.policy.utils.BackUpMonitor;
import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
+@PowerMockIgnore({"com.sun.org.apache.xerces.*", "jdk.internal.reflect.*", "javax.xml.*", "org.xml.*", "org.w3c.*"})
+@PrepareForTest({Persistence.class, BackUpMonitor.class})
public class BrmsHandlerTest {
- @PrepareForTest({Persistence.class, BackUpMonitor.class})
@Test
- public void negativeTestNotifications() throws Exception {
+ public void testNegativeTestNotifications() throws Exception {
// Mock emf, persistence, and query
final EntityManagerFactory emf = Mockito.mock(EntityManagerFactory.class);
final EntityManager em = Mockito.mock(EntityManager.class);
diff --git a/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsPushTest.java b/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsPushTest.java
index 2c76a2eff..3adc55700 100644
--- a/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsPushTest.java
+++ b/BRMSGateway/src/test/java/org/onap/policy/brms/api/BrmsPushTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* ONAP Policy Engine
* ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018-2020 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
- *
+ *
* http://www.apache.org/licenses/LICENSE-2.0
- *
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -23,7 +23,7 @@ package org.onap.policy.brms.api;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
import java.util.HashMap;
import java.util.List;
@@ -46,15 +46,17 @@ import org.onap.policy.utils.BackUpHandler;
import org.onap.policy.utils.BackUpMonitor;
import org.onap.policy.utils.BackUpMonitorException;
import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
+@PowerMockIgnore({"com.sun.org.apache.xerces.*", "jdk.internal.reflect.*", "javax.xml.*", "org.xml.*", "org.w3c.*"})
+@PrepareForTest({Persistence.class, BackUpMonitor.class})
public class BrmsPushTest {
@Rule
public ExpectedException thrown = ExpectedException.none();
- @PrepareForTest({Persistence.class, BackUpMonitor.class})
@Test
public void testPush() throws BackUpMonitorException, PolicyException {
// Mock emf, persistence, and query
@@ -108,7 +110,7 @@ public class BrmsPushTest {
// Test misc methods
final String controllerName = "testController";
final List<Dependency> deps = push.defaultDependencies(controllerName);
- assertEquals(deps.size(), 7);
+ assertEquals(deps.size(), 6);
assertNotNull(BrmsPush.getBackUpMonitor());
assertEquals(push.urlListSize(), 1);