JUnit additions for PAP-REST,REST
[policy/engine.git] / ONAP-PAP-REST / src / test / java / org / onap / policy / pap / xacml / rest / util / JPAUtilsTest.java
index 2c852fd..9b45c3b 100644 (file)
 package org.onap.policy.pap.xacml.rest.util;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import javax.persistence.EntityManager;
 import javax.persistence.EntityManagerFactory;
-import org.junit.Rule;
+import javax.persistence.Query;
 import org.junit.Test;
-import org.junit.rules.ExpectedException;
 import org.mockito.Mockito;
 
 public class JPAUtilsTest {
-       @Rule
-       public ExpectedException thrown = ExpectedException.none();
-       
-       @Test
-       public void testJPAUtils() throws IllegalAccessException {
-               EntityManagerFactory emf = Mockito.mock(EntityManagerFactory.class);
-               JPAUtils utils = JPAUtils.getJPAUtilsInstance(emf);
-               
-               assertEquals(utils.dbLockdownIgnoreErrors(), false);
-               
-               thrown.expect(NullPointerException.class);
-               utils.dbLockdown();
-       }
+  @Test(expected = IllegalAccessException.class)
+  public void testJPAUtils() throws IllegalAccessException {
+    // Setup test data
+    EntityManagerFactory emf = Mockito.mock(EntityManagerFactory.class);
+    EntityManager em = Mockito.mock(EntityManager.class);
+    Query query = Mockito.mock(Query.class);
+    Mockito.when(emf.createEntityManager()).thenReturn(em);
+    Mockito.when(em.createNamedQuery(Mockito.any())).thenReturn(query);
+
+    // Test lockdown
+    JPAUtils utils = JPAUtils.getJPAUtilsInstance(emf);
+    assertEquals(utils.dbLockdownIgnoreErrors(), false);
+    utils.dbLockdown();
+    fail("Expecting an exception");
+  }
 }