aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/ConsoleAndApiServiceTest.java188
-rw-r--r--ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/HandleIncomingNotificationsTest.java96
-rw-r--r--PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorTest.java324
3 files changed, 294 insertions, 314 deletions
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/ConsoleAndApiServiceTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/ConsoleAndApiServiceTest.java
index bad043d0f..0cd70f9b5 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/ConsoleAndApiServiceTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/ConsoleAndApiServiceTest.java
@@ -21,15 +21,15 @@
package org.onap.policy.pap.xacml.rest;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
import static org.mockito.Mockito.when;
+
import com.att.research.xacml.util.XACMLProperties;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import java.io.ByteArrayInputStream;
+import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
-import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
@@ -40,10 +40,11 @@ import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
import org.apache.commons.io.IOUtils;
import org.hibernate.SessionFactory;
-import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.mockito.Mockito;
import org.onap.policy.common.logging.ONAPLoggingContext;
import org.onap.policy.pap.xacml.rest.components.ConfigPolicy;
@@ -54,6 +55,7 @@ import org.onap.policy.pap.xacml.rest.components.PolicyDBDaoTransaction;
import org.onap.policy.pap.xacml.rest.daoimpl.CommonClassDaoImpl;
import org.onap.policy.pap.xacml.rest.policycontroller.PolicyCreation;
import org.onap.policy.rest.adapter.PolicyRestAdapter;
+import org.onap.policy.rest.dao.PolicyDBException;
import org.onap.policy.xacml.std.pap.StdEngine;
import org.onap.policy.xacml.std.pap.StdPDP;
import org.springframework.mock.web.DelegatingServletInputStream;
@@ -81,8 +83,8 @@ public class ConsoleAndApiServiceTest {
private static final String USER_ID = "userId";
private static final String APIFLAG = "apiflag";
private static final String ENVIRONMENT_HEADER = "Environment";
+ private static final ONAPLoggingContext logContext = Mockito.mock(ONAPLoggingContext.class);
private static PolicyDBDao dbd;
- private static Path repository;
private static StdEngine stdEngine = null;
private static SessionFactory sessionFactory = null;
private static List<String> headers = new ArrayList<>();
@@ -91,7 +93,8 @@ public class ConsoleAndApiServiceTest {
private static XACMLPapServlet pap;
private HttpServletRequest httpServletRequest;
private HttpServletResponse httpServletResponse;
- private static final ONAPLoggingContext logContext = Mockito.mock(ONAPLoggingContext.class);
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder();
/**
* Sets the up before class.
@@ -101,16 +104,10 @@ public class ConsoleAndApiServiceTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "src/test/resources/xacml.pap.properties");
- try {
- sessionFactory = PolicyDBDaoTest.setupH2DbDaoImpl("testConsoleApi");
- } catch (Exception e) {
- Assert.fail();
- }
-
+ sessionFactory = PolicyDBDaoTest.setupH2DbDaoImpl("testConsoleApi");
PolicyDBDao.setJunit(true);
dbd = PolicyDBDao.getPolicyDBDaoInstance();
PolicyDBDao.setJunit(true);
-
consoleAndApi = new ConsoleAndApiService();
servletConfig = Mockito.mock(MockServletConfig.class);
@@ -136,65 +133,52 @@ public class ConsoleAndApiServiceTest {
Mockito.when(httpServletRequest.getAttributeNames()).thenReturn(Collections.enumeration(headers));
CommonClassDaoImpl.setSessionfactory(sessionFactory);
PolicyCreation.setCommonClassDao(new CommonClassDaoImpl());
- repository = Paths.get("src/test/resources/pdps");
- stdEngine = new StdEngine(repository);
+ File tmpGrpDir = folder.newFolder("src", "test", "resources", "grpTest");
+ stdEngine = new StdEngine(tmpGrpDir.toPath());
dbd.setPapEngine(stdEngine);
}
@Test
- public void testGroupCreation() {
+ public void testGroupCreation() throws IOException {
Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn(DEVL);
Mockito.when(httpServletRequest.getMethod()).thenReturn(POST);
Mockito.when(httpServletRequest.getParameter(APIFLAG)).thenReturn(API2);
Mockito.when(httpServletRequest.getParameter(USER_ID)).thenReturn(API);
Mockito.when(httpServletRequest.getParameter(GROUP_DESCRIPTION)).thenReturn("test");
Mockito.when(httpServletRequest.getParameter(GROUP_NAME)).thenReturn(TESTGRP1);
- try {
- consoleAndApi.doAcPost(httpServletRequest, httpServletResponse, TESTGRP1, logContext, stdEngine);
- assertTrue(HttpServletResponse.SC_NO_CONTENT == httpServletResponse.getStatus());
- } catch (IOException e) {
- fail(e.getMessage());
- }
+ consoleAndApi.doAcPost(httpServletRequest, httpServletResponse, TESTGRP1, logContext, stdEngine);
+ assertTrue(HttpServletResponse.SC_NO_CONTENT == httpServletResponse.getStatus());
+
}
@Test
- public void testGroupNotExistInDb() {
+ public void testGroupNotExistInDb() throws IOException {
Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn(DEVL);
Mockito.when(httpServletRequest.getMethod()).thenReturn(POST);
Mockito.when(httpServletRequest.getParameter(APIFLAG)).thenReturn(API2);
Mockito.when(httpServletRequest.getParameter(USER_ID)).thenReturn(API);
Mockito.when(httpServletRequest.getParameter(GROUP_NAME)).thenReturn("testgrpNotExist");
- try {
- consoleAndApi.doAcPost(httpServletRequest, httpServletResponse, "testgrpNotExist", logContext, stdEngine);
- assertTrue(HttpServletResponse.SC_INTERNAL_SERVER_ERROR == httpServletResponse.getStatus());
- } catch (IOException e) {
- fail(e.getMessage());
- }
+ consoleAndApi.doAcPost(httpServletRequest, httpServletResponse, "testgrpNotExist", logContext, stdEngine);
+ assertTrue(HttpServletResponse.SC_INTERNAL_SERVER_ERROR == httpServletResponse.getStatus());
+
}
@Test
- public void testGroupChange() {
+ public void testGroupChange() throws IOException {
Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn(DEVL);
Mockito.when(httpServletRequest.getMethod()).thenReturn(POST);
Mockito.when(httpServletRequest.getParameter(APIFLAG)).thenReturn(API2);
Mockito.when(httpServletRequest.getParameter(USER_ID)).thenReturn(API);
Mockito.when(httpServletRequest.getParameter(GROUP_DESCRIPTION)).thenReturn("test");
Mockito.when(httpServletRequest.getParameter(GROUP_NAME)).thenReturn(TESTGRP2);
- try {
- consoleAndApi.doAcPost(httpServletRequest, httpServletResponse, TESTGRP2, logContext, stdEngine);
- assertTrue(HttpServletResponse.SC_NO_CONTENT == httpServletResponse.getStatus());
- } catch (IOException e) {
- fail(e.getMessage());
- }
+ consoleAndApi.doAcPost(httpServletRequest, httpServletResponse, TESTGRP2, logContext, stdEngine);
+ assertTrue(HttpServletResponse.SC_NO_CONTENT == httpServletResponse.getStatus());
Mockito.when(httpServletRequest.getParameter(GROUP_DESCRIPTION)).thenReturn(null);
Mockito.when(httpServletRequest.getParameter(DEFAULT)).thenReturn(DEFAULT);
- try {
- consoleAndApi.doAcPost(httpServletRequest, httpServletResponse, TESTGRP2, logContext, stdEngine);
- assertTrue(HttpServletResponse.SC_NO_CONTENT == httpServletResponse.getStatus());
- } catch (IOException e) {
- fail(e.getMessage());
- }
+ consoleAndApi.doAcPost(httpServletRequest, httpServletResponse, TESTGRP2, logContext, stdEngine);
+ assertTrue(HttpServletResponse.SC_NO_CONTENT == httpServletResponse.getStatus());
+
}
@Test
@@ -205,17 +189,13 @@ public class ConsoleAndApiServiceTest {
Mockito.when(httpServletRequest.getParameter(USER_ID)).thenReturn(API);
Mockito.when(httpServletRequest.getParameter(GROUP_DESCRIPTION)).thenReturn(null);
Mockito.when(httpServletRequest.getParameter(POLICY_ID)).thenReturn(POLICY_NAME);
- repository = Paths.get(PDPS);
- stdEngine = new StdEngine(repository);
+ stdEngine = new StdEngine(Paths.get(PDPS));
dbd.setPapEngine(stdEngine);
populatePolicyInDb();
- try {
- consoleAndApi.doAcPost(httpServletRequest, httpServletResponse, DEFAULT, logContext, stdEngine);
- assertTrue(HttpServletResponse.SC_NO_CONTENT == httpServletResponse.getStatus());
- } catch (IOException e) {
- fail(e.getMessage());
- }
+ consoleAndApi.doAcPost(httpServletRequest, httpServletResponse, DEFAULT, logContext, stdEngine);
+ assertTrue(HttpServletResponse.SC_NO_CONTENT == httpServletResponse.getStatus());
+
}
@Test
@@ -225,16 +205,12 @@ public class ConsoleAndApiServiceTest {
Mockito.when(httpServletRequest.getParameter(APIFLAG)).thenReturn(API2);
Mockito.when(httpServletRequest.getParameter(USER_ID)).thenReturn(API);
Mockito.when(httpServletRequest.getParameter("policy")).thenReturn(POLICY_NAME);
- repository = Paths.get(PDPS);
- stdEngine = new StdEngine(repository);
+ stdEngine = new StdEngine(Paths.get(PDPS));
dbd.setPapEngine(stdEngine);
- try {
- consoleAndApi.doAcPut(httpServletRequest, httpServletResponse, DEFAULT, logContext, stdEngine);
- assertTrue(HttpServletResponse.SC_NO_CONTENT == httpServletResponse.getStatus());
- } catch (IOException e) {
- fail(e.getMessage());
- }
+ consoleAndApi.doAcPut(httpServletRequest, httpServletResponse, DEFAULT, logContext, stdEngine);
+ assertTrue(HttpServletResponse.SC_NO_CONTENT == httpServletResponse.getStatus());
+
}
@Test
@@ -246,15 +222,12 @@ public class ConsoleAndApiServiceTest {
Mockito.when(httpServletRequest.getParameter(USER_ID)).thenReturn(API);
Mockito.when(httpServletRequest.getParameter(GROUP_DESCRIPTION)).thenReturn("test");
Mockito.when(httpServletRequest.getParameter(GROUP_NAME)).thenReturn(TESTGRP4);
- try {
- consoleAndApi.doAcPost(httpServletRequest, httpServletResponse, TESTGRP4, logContext, stdEngine);
- assertTrue(HttpServletResponse.SC_NO_CONTENT == httpServletResponse.getStatus());
- Mockito.when(httpServletRequest.getParameter(GROUP_NAME)).thenReturn(TESTGRP5);
- consoleAndApi.doAcPost(httpServletRequest, httpServletResponse, TESTGRP5, logContext, stdEngine);
- assertTrue(HttpServletResponse.SC_NO_CONTENT == httpServletResponse.getStatus());
- } catch (IOException e) {
- fail(e.getMessage());
- }
+ consoleAndApi.doAcPost(httpServletRequest, httpServletResponse, TESTGRP4, logContext, stdEngine);
+ assertTrue(HttpServletResponse.SC_NO_CONTENT == httpServletResponse.getStatus());
+ Mockito.when(httpServletRequest.getParameter(GROUP_NAME)).thenReturn(TESTGRP5);
+ consoleAndApi.doAcPost(httpServletRequest, httpServletResponse, TESTGRP5, logContext, stdEngine);
+ assertTrue(HttpServletResponse.SC_NO_CONTENT == httpServletResponse.getStatus());
+
Mockito.when(httpServletRequest.getParameter(GROUP_DESCRIPTION)).thenReturn(null);
Mockito.when(httpServletRequest.getParameter(PDP_ID)).thenReturn("http://localhost:4344/pdp/");
@@ -264,12 +237,9 @@ public class ConsoleAndApiServiceTest {
ObjectWriter ow = new ObjectMapper().writer();
when(httpServletRequest.getInputStream()).thenReturn(new DelegatingServletInputStream(
new ByteArrayInputStream(ow.writeValueAsString(newPdp).getBytes(StandardCharsets.UTF_8))));
- try {
- consoleAndApi.doAcPut(httpServletRequest, httpServletResponse, TESTGRP5, logContext, stdEngine);
- assertTrue(HttpServletResponse.SC_NO_CONTENT == httpServletResponse.getStatus());
- } catch (IOException e) {
- fail(e.getMessage());
- }
+ consoleAndApi.doAcPut(httpServletRequest, httpServletResponse, TESTGRP5, logContext, stdEngine);
+ assertTrue(HttpServletResponse.SC_NO_CONTENT == httpServletResponse.getStatus());
+
httpServletRequest = Mockito.mock(HttpServletRequest.class);
httpServletResponse = new MockHttpServletResponse();
@@ -279,12 +249,9 @@ public class ConsoleAndApiServiceTest {
Mockito.when(httpServletRequest.getParameter(USER_ID)).thenReturn(API);
Mockito.when(httpServletRequest.getParameter(PDP_ID)).thenReturn("http://localhost:4344/pdp/");
Mockito.when(httpServletRequest.getParameter(GROUP_NAME)).thenReturn(TESTGRP4);
- try {
- consoleAndApi.doAcPost(httpServletRequest, httpServletResponse, TESTGRP4, logContext, stdEngine);
- assertTrue(HttpServletResponse.SC_NO_CONTENT == httpServletResponse.getStatus());
- } catch (IOException e) {
- fail(e.getMessage());
- }
+ consoleAndApi.doAcPost(httpServletRequest, httpServletResponse, TESTGRP4, logContext, stdEngine);
+ assertTrue(HttpServletResponse.SC_NO_CONTENT == httpServletResponse.getStatus());
+
httpServletRequest = Mockito.mock(HttpServletRequest.class);
httpServletResponse = new MockHttpServletResponse();
@@ -294,45 +261,39 @@ public class ConsoleAndApiServiceTest {
Mockito.when(httpServletRequest.getParameter(USER_ID)).thenReturn(API);
Mockito.when(httpServletRequest.getParameter(PDP_ID)).thenReturn("http://localhost:4344/pdp/");
Mockito.when(httpServletRequest.getParameter(GROUP_NAME)).thenReturn(TESTGRP4);
- try {
- consoleAndApi.doAcDelete(httpServletRequest, httpServletResponse, TESTGRP4, logContext, stdEngine);
- assertTrue(HttpServletResponse.SC_NO_CONTENT == httpServletResponse.getStatus());
- } catch (IOException e) {
- fail(e.getMessage());
- }
+ consoleAndApi.doAcDelete(httpServletRequest, httpServletResponse, TESTGRP4, logContext, stdEngine);
+ assertTrue(HttpServletResponse.SC_NO_CONTENT == httpServletResponse.getStatus());
+
}
@Test
public void testGet() throws Exception {
+ stdEngine = new StdEngine(Paths.get("src", "test", "resources", "pdps"));
+ dbd.setPapEngine(stdEngine);
Mockito.when(httpServletRequest.getHeader(ENVIRONMENT_HEADER)).thenReturn(DEVL);
Mockito.when(httpServletRequest.getMethod()).thenReturn("GET");
Mockito.when(httpServletRequest.getParameter(APIFLAG)).thenReturn(API2);
Mockito.when(httpServletRequest.getParameter(USER_ID)).thenReturn(API);
Mockito.when(httpServletRequest.getParameter(PDP_ID)).thenReturn("http://localhost:4344/pdp/");
Mockito.when(httpServletRequest.getParameter(GROUP_NAME)).thenReturn("");
- try {
- consoleAndApi.doAcGet(httpServletRequest, httpServletResponse, "", logContext, stdEngine);
- assertTrue(HttpServletResponse.SC_OK == httpServletResponse.getStatus());
- httpServletResponse = new MockHttpServletResponse();
- Mockito.when(httpServletRequest.getParameter(DEFAULT)).thenReturn(DEFAULT);
- consoleAndApi.doAcGet(httpServletRequest, httpServletResponse, "", logContext, stdEngine);
- assertTrue(HttpServletResponse.SC_OK == httpServletResponse.getStatus());
- Mockito.when(httpServletRequest.getParameter(PDP_ID)).thenReturn(null);
- Mockito.when(httpServletRequest.getParameter(DEFAULT)).thenReturn(null);
- consoleAndApi.doAcGet(httpServletRequest, httpServletResponse, "", logContext, stdEngine);
- assertTrue(HttpServletResponse.SC_OK == httpServletResponse.getStatus());
- Mockito.when(httpServletRequest.getParameter("getPDPGroup")).thenReturn(TESTGROUP2);
- Mockito.when(httpServletRequest.getParameter(GROUP_NAME)).thenReturn(TESTGROUP2);
- consoleAndApi.doAcGet(httpServletRequest, httpServletResponse, TESTGROUP2, logContext, stdEngine);
- assertTrue(HttpServletResponse.SC_OK == httpServletResponse.getStatus());
- } catch (IOException e) {
- fail(e.getMessage());
- }
-
+ consoleAndApi.doAcGet(httpServletRequest, httpServletResponse, "", logContext, stdEngine);
+ assertTrue(HttpServletResponse.SC_OK == httpServletResponse.getStatus());
+ httpServletResponse = new MockHttpServletResponse();
+ Mockito.when(httpServletRequest.getParameter(DEFAULT)).thenReturn(DEFAULT);
+ consoleAndApi.doAcGet(httpServletRequest, httpServletResponse, "", logContext, stdEngine);
+ assertTrue(HttpServletResponse.SC_OK == httpServletResponse.getStatus());
+ Mockito.when(httpServletRequest.getParameter(PDP_ID)).thenReturn(null);
+ Mockito.when(httpServletRequest.getParameter(DEFAULT)).thenReturn(null);
+ consoleAndApi.doAcGet(httpServletRequest, httpServletResponse, "", logContext, stdEngine);
+ assertTrue(HttpServletResponse.SC_OK == httpServletResponse.getStatus());
+ Mockito.when(httpServletRequest.getParameter("getPDPGroup")).thenReturn(TESTGROUP2);
+ Mockito.when(httpServletRequest.getParameter(GROUP_NAME)).thenReturn(TESTGROUP2);
+ consoleAndApi.doAcGet(httpServletRequest, httpServletResponse, TESTGROUP2, logContext, stdEngine);
+ assertTrue(HttpServletResponse.SC_OK == httpServletResponse.getStatus());
}
- private static void populatePolicyInDb() {
+ private static void populatePolicyInDb() throws IOException, PolicyDBException {
CommonClassDaoImpl.setSessionfactory(sessionFactory);
PolicyCreation.setCommonClassDao(new CommonClassDaoImpl());
Policy policyObject = new ConfigPolicy();
@@ -348,26 +309,17 @@ public class ConsoleAndApiServiceTest {
policyObject.policyAdapter.setHighestVersion(1);
PolicyType policyTypeObject = new PolicyType();
policyObject.policyAdapter.setPolicyData(policyTypeObject);
- ClassLoader classLoader = ConsoleAndApiServiceTest.class.getClassLoader();
+
PolicyType policyConfig = new PolicyType();
policyConfig.setVersion("1");
policyConfig.setPolicyId("");
policyConfig.setTarget(new TargetType());
policyObject.policyAdapter.setData(policyConfig);
- try {
- policyObject.policyAdapter
- .setParentPath(IOUtils.toString(classLoader.getResourceAsStream("Config_SampleTest1206.1.xml")));
- } catch (Exception e2) {
- fail();
- }
+ policyObject.policyAdapter.setParentPath(IOUtils.toString(
+ ConsoleAndApiServiceTest.class.getClassLoader().getResourceAsStream("Config_SampleTest1206.1.xml")));
PolicyDBDaoTransaction transaction = dbd.getNewTransaction();
- try {
- transaction.createPolicy(policyObject, API);
- transaction.commitTransaction();
- } catch (Exception e) {
- transaction.rollbackTransaction();
- Assert.fail();
- }
+ transaction.createPolicy(policyObject, API);
+ transaction.commitTransaction();
}
}
diff --git a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/HandleIncomingNotificationsTest.java b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/HandleIncomingNotificationsTest.java
index f979d1efa..436ff7fc8 100644
--- a/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/HandleIncomingNotificationsTest.java
+++ b/ONAP-PAP-REST/src/test/java/org/onap/policy/pap/xacml/rest/components/HandleIncomingNotificationsTest.java
@@ -20,30 +20,39 @@
package org.onap.policy.pap.xacml.rest.components;
-import static org.junit.Assert.fail;
+import com.att.research.xacml.api.pap.PAPException;
import com.att.research.xacml.util.XACMLProperties;
-import java.nio.file.Path;
-import java.nio.file.Paths;
+import java.io.File;
+import java.io.IOException;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.PolicyType;
import oasis.names.tc.xacml._3_0.core.schema.wd_17.TargetType;
import org.apache.commons.io.IOUtils;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
-import org.junit.Assert;
+import org.junit.Before;
import org.junit.BeforeClass;
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
import org.onap.policy.rest.adapter.PolicyRestAdapter;
+import org.onap.policy.rest.dao.PolicyDBException;
import org.onap.policy.rest.jpa.GroupEntity;
import org.onap.policy.rest.jpa.PdpEntity;
import org.onap.policy.xacml.std.pap.StdEngine;
public class HandleIncomingNotificationsTest {
+ private static final String API = "API";
+ private static final String TWO = "2";
+ private static final String PDP = "pdp";
+ private static final String GROUP = "group";
+ private static final String ONE = "1";
private static PolicyDBDao dbd;
- private static Path repository;
private static StdEngine stdEngine = null;
private static SessionFactory sessionFactory = null;
private static HandleIncomingNotifications handleIncomingNotifications;
private static GroupEntity groupEntity;
+ @Rule
+ public TemporaryFolder folder = new TemporaryFolder();
/**
* Sets the up before class.
@@ -53,59 +62,63 @@ public class HandleIncomingNotificationsTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
System.setProperty(XACMLProperties.XACML_PROPERTIES_NAME, "src/test/resources/xacml.pap.properties");
- try {
- sessionFactory = PolicyDBDaoTest.setupH2DbDaoImpl("testHandleIncoming");
- handleIncomingNotifications = new HandleIncomingNotifications(sessionFactory);
- } catch (Exception e) {
- Assert.fail();
- }
-
+ sessionFactory = PolicyDBDaoTest.setupH2DbDaoImpl("testHandleIncoming");
+ handleIncomingNotifications = new HandleIncomingNotifications(sessionFactory);
PolicyDBDao.setJunit(true);
dbd = PolicyDBDao.getPolicyDBDaoInstance();
PolicyDBDao.setJunit(true);
- repository = Paths.get("src/test/resources/pdps");
- stdEngine = new StdEngine(repository);
- dbd.setPapEngine(stdEngine);
populateDb();
}
+ /**
+ * Setup.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ * @throws PAPException the PAP exception
+ */
+ @Before
+ public void setup() throws IOException, PAPException {
+ File tmpGrpDir = folder.newFolder("src", "test", "resources", "pdps", "grpTest");
+ stdEngine = new StdEngine(tmpGrpDir.toPath());
+ dbd.setPapEngine(stdEngine);
+ }
@Test
public void testHandleIncomingHttpNotification() {
- handleIncomingNotifications.handleIncomingHttpNotification(null, "1", "group", null, null);
- handleIncomingNotifications.handleIncomingHttpNotification(null, "1", "group", null, null);
- handleIncomingNotifications.handleIncomingHttpNotification(null, "1", "policy", null, null);
- handleIncomingNotifications.handleIncomingHttpNotification(null, "1", "pdp", null, null);
- populatePdpEntityDb("2", groupEntity);
- handleIncomingNotifications.handleIncomingHttpNotification(null, "2", "pdp", null, null);
+ handleIncomingNotifications.handleIncomingHttpNotification(null, ONE, GROUP, null, null);
+ handleIncomingNotifications.handleIncomingHttpNotification(null, ONE, GROUP, null, null);
+ handleIncomingNotifications.handleIncomingHttpNotification(null, ONE, "policy", null, null);
+ handleIncomingNotifications.handleIncomingHttpNotification(null, ONE, PDP, null, null);
+ populatePdpEntityDb(TWO, groupEntity);
+ handleIncomingNotifications.handleIncomingHttpNotification(null, TWO, PDP, null, null);
}
- private static void populateDb() {
+ private static void populateDb() throws PolicyDBException, IOException {
groupEntity = new GroupEntity();
- groupEntity.setCreatedBy("API");
+ groupEntity.setCreatedBy(API);
groupEntity.setDefaultGroup(false);
groupEntity.setDeleted(false);
groupEntity.setDescription("a test group");
- groupEntity.setGroupId("1");
- groupEntity.setGroupName("1");
+ groupEntity.setGroupId(ONE);
+ groupEntity.setGroupName(ONE);
groupEntity.prePersist();
Session session = sessionFactory.openSession();
session.getTransaction().begin();
session.persist(groupEntity);
session.getTransaction().commit();
session.close();
- populatePdpEntityDb("1", groupEntity);
+ populatePdpEntityDb(ONE, groupEntity);
populatePolicyInDb();
}
private static void populatePdpEntityDb(String pdpId, GroupEntity groupEntity) {
PdpEntity pdpEntity = new PdpEntity();
- pdpEntity.setCreatedBy("API");
+ pdpEntity.setCreatedBy(API);
pdpEntity.setDeleted(false);
pdpEntity.setDescription("test pdp");
pdpEntity.setGroup(groupEntity);
pdpEntity.setJmxPort(9993);
- pdpEntity.setModifiedBy("API");
+ pdpEntity.setModifiedBy(API);
pdpEntity.setPdpId(pdpId);
pdpEntity.setPdpName("grouptest");
pdpEntity.prePersist();
@@ -117,7 +130,7 @@ public class HandleIncomingNotificationsTest {
session.close();
}
- private static void populatePolicyInDb() {
+ private static void populatePolicyInDb() throws PolicyDBException, IOException {
Policy policyObject = new ConfigPolicy();
policyObject.policyAdapter = new PolicyRestAdapter();
policyObject.policyAdapter.setConfigName("testpolicyhandle");
@@ -127,30 +140,23 @@ public class HandleIncomingNotificationsTest {
policyObject.policyAdapter.setConfigType(ConfigPolicy.OTHER_CONFIG);
policyObject.policyAdapter.setPolicyType("Config");
policyObject.policyAdapter.setDomainDir("com");
- policyObject.policyAdapter.setVersion("1");
+ policyObject.policyAdapter.setVersion(ONE);
policyObject.policyAdapter.setHighestVersion(1);
PolicyType policyTypeObject = new PolicyType();
policyObject.policyAdapter.setPolicyData(policyTypeObject);
- ClassLoader classLoader = HandleIncomingNotificationsTest.class.getClassLoader();
+
PolicyType policyConfig = new PolicyType();
- policyConfig.setVersion("1");
+ policyConfig.setVersion(ONE);
policyConfig.setPolicyId("");
policyConfig.setTarget(new TargetType());
policyObject.policyAdapter.setData(policyConfig);
- try {
- policyObject.policyAdapter
- .setParentPath(IOUtils.toString(classLoader.getResourceAsStream("Config_SampleTest1206.1.xml")));
- } catch (Exception e2) {
- fail();
- }
+ ClassLoader classLoader = HandleIncomingNotificationsTest.class.getClassLoader();
+ policyObject.policyAdapter
+ .setParentPath(IOUtils.toString(classLoader.getResourceAsStream("Config_SampleTest1206.1.xml")));
PolicyDBDaoTransaction transaction = dbd.getNewTransaction();
- try {
- transaction.createPolicy(policyObject, "testuser1");
- transaction.commitTransaction();
- } catch (Exception e) {
- transaction.rollbackTransaction();
- Assert.fail();
- }
+ transaction.createPolicy(policyObject, "testuser1");
+ transaction.commitTransaction();
+
}
}
diff --git a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorTest.java b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorTest.java
index 83362fd0d..5182c5329 100644
--- a/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorTest.java
+++ b/PolicyEngineUtils/src/test/java/org/onap/policy/utils/test/BackUpMonitorTest.java
@@ -2,14 +2,14 @@
* ============LICENSE_START=======================================================
* PolicyEngineUtils
* ================================================================================
- * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2017,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.
@@ -24,6 +24,9 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
@@ -31,15 +34,15 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
-
import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import javax.persistence.PersistenceException;
import javax.persistence.Query;
-
+import org.apache.commons.io.FileUtils;
import org.eclipse.persistence.config.PersistenceUnitProperties;
import org.junit.After;
+import org.junit.AfterClass;
import org.junit.Test;
import org.onap.policy.api.NotificationType;
import org.onap.policy.api.UpdateType;
@@ -53,146 +56,151 @@ import org.onap.policy.utils.BackUpMonitor.ResourceNode;
import org.onap.policy.utils.BackUpMonitorException;
import org.onap.policy.utils.PolicyUtils;
-import com.fasterxml.jackson.core.JsonProcessingException;
-
public class BackUpMonitorTest {
+ @Test(expected = PersistenceException.class)
+ public void backUpMonitorTestFail() throws Exception {
+ Properties properties = new Properties();
+ properties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
+ properties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/onap_sdk");
+ properties.setProperty("javax.persistence.jdbc.user", "policy_user");
+ properties.setProperty("javax.persistence.jdbc.password", "");
+ BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test", properties,
+ new DummyBackUpHandler());
+ }
- @Test (expected = PersistenceException.class)
- public void backUpMonitorTestFail() throws Exception{
- Properties properties = new Properties();
- properties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
- properties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/onap_sdk");
- properties.setProperty("javax.persistence.jdbc.user", "policy_user");
- properties.setProperty("javax.persistence.jdbc.password", "");
- BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test" , properties, new DummyBackUpHandler());
- }
-
- @Test
- public void backUpMonitorTestFailNoUser() throws Exception{
- Properties properties = new Properties();
- properties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
- properties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/onap_sdk");
- properties.setProperty("javax.persistence.jdbc.user", "");
- properties.setProperty("javax.persistence.jdbc.password", "password");
- BackUpMonitor bum = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test" , properties, new DummyBackUpHandler());
- assertNull(bum);
- }
-
- @Test
- public void backUpMonitorTestFailNoURL() throws Exception{
- Properties properties = new Properties();
- properties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
- properties.setProperty("javax.persistence.jdbc.url", "");
- properties.setProperty("javax.persistence.jdbc.user", "test");
- properties.setProperty("javax.persistence.jdbc.password", "password");
- properties.setProperty("ping_interval", "500");
- BackUpMonitor bum = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test" , properties, new DummyBackUpHandler());
- assertNull(bum);
- }
-
- @Test
- public void backUpMonitorTestFailNoDriver() throws Exception{
- Properties properties = new Properties();
- properties.setProperty("javax.persistence.jdbc.driver", "");
- properties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/onap_sdk");
- properties.setProperty("javax.persistence.jdbc.user", "test");
- properties.setProperty("javax.persistence.jdbc.password", "password");
- properties.setProperty("ping_interval", "500");
- BackUpMonitor bum = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test" , properties, new DummyBackUpHandler());
- assertNull(bum);
- }
-
- @Test
- public void backUpMonitorTestFailNoNode() throws Exception{
- Properties properties = new Properties();
- properties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
- properties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/onap_sdk");
- properties.setProperty("javax.persistence.jdbc.user", "test");
- properties.setProperty("javax.persistence.jdbc.password", "password");
- properties.setProperty("ping_interval", "");
- BackUpMonitor bum = BackUpMonitor.getInstance(null, "brms_test" , properties, new DummyBackUpHandler());
- assertNull(bum);
- }
-
- @Test
- public void backUpMonitorTestFailNoResource() throws Exception{
- Properties properties = new Properties();
- properties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
- properties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/onap_sdk");
- properties.setProperty("javax.persistence.jdbc.user", "test");
- properties.setProperty("javax.persistence.jdbc.password", "password");
- BackUpMonitor bum = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), null , properties, new DummyBackUpHandler());
- assertNull(bum);
- }
-
- @Test
- public void backUpMonitorTestFailNoProperties() throws Exception{
- BackUpMonitor bum = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test" , null, new DummyBackUpHandler());
- assertNull(bum);
- }
-
- @Test
- public void backUpMonitorTestFailNoHandler() throws Exception{
- Properties properties = new Properties();
- properties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
- properties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/onap_sdk");
- properties.setProperty("javax.persistence.jdbc.user", "test");
- properties.setProperty("javax.persistence.jdbc.password", "password");
- properties.setProperty("ping_interval", "500");
- BackUpMonitor bum = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test" , properties, null);
- assertNull(bum);
- }
-
- @Test
- public void backUpMonitorPingError() throws BackUpMonitorException {
- Properties properties = new Properties();
- properties.setProperty("javax.persistence.jdbc.driver", "org.h2.Driver");
- properties.setProperty("javax.persistence.jdbc.url", "jdbc:h2:file:./sql/xacmlTest");
+ @Test
+ public void backUpMonitorTestFailNoUser() throws Exception {
+ Properties properties = new Properties();
+ properties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
+ properties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/onap_sdk");
+ properties.setProperty("javax.persistence.jdbc.user", "");
+ properties.setProperty("javax.persistence.jdbc.password", "password");
+ BackUpMonitor bum = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test",
+ properties, new DummyBackUpHandler());
+ assertNull(bum);
+ }
+
+ @Test
+ public void backUpMonitorTestFailNoUrl() throws Exception {
+ Properties properties = new Properties();
+ properties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
+ properties.setProperty("javax.persistence.jdbc.url", "");
+ properties.setProperty("javax.persistence.jdbc.user", "test");
+ properties.setProperty("javax.persistence.jdbc.password", "password");
+ properties.setProperty("ping_interval", "500");
+ BackUpMonitor bum = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test",
+ properties, new DummyBackUpHandler());
+ assertNull(bum);
+ }
+
+ @Test
+ public void backUpMonitorTestFailNoDriver() throws Exception {
+ Properties properties = new Properties();
+ properties.setProperty("javax.persistence.jdbc.driver", "");
+ properties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/onap_sdk");
+ properties.setProperty("javax.persistence.jdbc.user", "test");
+ properties.setProperty("javax.persistence.jdbc.password", "password");
+ properties.setProperty("ping_interval", "500");
+ BackUpMonitor bum = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test",
+ properties, new DummyBackUpHandler());
+ assertNull(bum);
+ }
+
+ @Test
+ public void backUpMonitorTestFailNoNode() throws Exception {
+ Properties properties = new Properties();
+ properties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
+ properties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/onap_sdk");
+ properties.setProperty("javax.persistence.jdbc.user", "test");
+ properties.setProperty("javax.persistence.jdbc.password", "password");
+ properties.setProperty("ping_interval", "");
+ BackUpMonitor bum = BackUpMonitor.getInstance(null, "brms_test", properties, new DummyBackUpHandler());
+ assertNull(bum);
+ }
+
+ @Test
+ public void backUpMonitorTestFailNoResource() throws Exception {
+ Properties properties = new Properties();
+ properties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
+ properties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/onap_sdk");
+ properties.setProperty("javax.persistence.jdbc.user", "test");
+ properties.setProperty("javax.persistence.jdbc.password", "password");
+ BackUpMonitor bum = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), null, properties,
+ new DummyBackUpHandler());
+ assertNull(bum);
+ }
+
+ @Test
+ public void backUpMonitorTestFailNoProperties() throws Exception {
+ BackUpMonitor bum = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test", null,
+ new DummyBackUpHandler());
+ assertNull(bum);
+ }
+
+ @Test
+ public void backUpMonitorTestFailNoHandler() throws Exception {
+ Properties properties = new Properties();
+ properties.setProperty("javax.persistence.jdbc.driver", "org.mariadb.jdbc.Driver");
+ properties.setProperty("javax.persistence.jdbc.url", "jdbc:mariadb://localhost:3306/onap_sdk");
+ properties.setProperty("javax.persistence.jdbc.user", "test");
+ properties.setProperty("javax.persistence.jdbc.password", "password");
+ properties.setProperty("ping_interval", "500");
+ BackUpMonitor bum =
+ BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test", properties, null);
+ assertNull(bum);
+ }
+
+ @Test
+ public void backUpMonitorPingError() throws BackUpMonitorException {
+ Properties properties = new Properties();
+ properties.setProperty("javax.persistence.jdbc.driver", "org.h2.Driver");
+ properties.setProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:backUpMonitorPingError");
properties.setProperty("javax.persistence.jdbc.user", "sa");
properties.setProperty("javax.persistence.jdbc.password", "");
properties.setProperty("ping_interval", "123a");
properties.setProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, "META-INF/persistencePUtest.xml");
- BackUpMonitor bum = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test" , properties, new DummyBackUpHandler());
+ BackUpMonitor bum = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test",
+ properties, new DummyBackUpHandler());
assertTrue(bum.getFlag());
- }
-
- @Test
- public void backUpMonitorMasterTest() throws BackUpMonitorException, InterruptedException, JsonProcessingException {
- Properties properties = new Properties();
- // Master Check. Initial Run.
- properties.setProperty("javax.persistence.jdbc.driver", "org.h2.Driver");
- properties.setProperty("javax.persistence.jdbc.url", "jdbc:h2:file:./sql/xacmlTest");
+ }
+
+ @Test
+ public void backUpMonitorMasterTest() throws BackUpMonitorException, InterruptedException, JsonProcessingException {
+ Properties properties = new Properties();
+ // Master Check. Initial Run.
+ properties.setProperty("javax.persistence.jdbc.driver", "org.h2.Driver");
+ properties.setProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:BackupMonitorMasterTest");
properties.setProperty("javax.persistence.jdbc.user", "sa");
properties.setProperty("javax.persistence.jdbc.password", "");
properties.setProperty("ping_interval", "500");
properties.setProperty(PersistenceUnitProperties.ECLIPSELINK_PERSISTENCE_XML, "META-INF/persistencePUtest.xml");
- BackUpMonitor bum = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test" , properties, new DummyBackUpHandler());
+ BackUpMonitor buMonitor = BackUpMonitor.getInstance(BackUpMonitor.ResourceNode.BRMS.toString(), "brms_test",
+ properties, new DummyBackUpHandler());
createPolicyNotification();
- assertTrue(bum.getFlag());
+ assertTrue(buMonitor.getFlag());
// Start a slave check.
startSlave(properties);
updatePolicyNotification();
TimeUnit.MILLISECONDS.sleep(1500);
- assertFalse(bum.getFlag());
+ assertFalse(buMonitor.getFlag());
// Get Back to Master test
TimeUnit.MILLISECONDS.sleep(2000);
- assertTrue(bum.getFlag());
- // No Master check.
- changeALL(properties, "SLAVE");
+ assertTrue(buMonitor.getFlag());
+ // No Master check.
+ changeAll(properties, "SLAVE");
TimeUnit.MILLISECONDS.sleep(2000);
- assertTrue(bum.getFlag());
- // No Master check.
- changeALL(properties, "MASTER");
+ assertTrue(buMonitor.getFlag());
+ // No Master check.
+ changeAll(properties, "MASTER");
TimeUnit.MILLISECONDS.sleep(2000);
- assertTrue(bum.getFlag());
-
- }
-
- private void updatePolicyNotification() {
- StdPDPNotification notification = new StdPDPNotification();
+ assertTrue(buMonitor.getFlag());
+
+ }
+
+ private void updatePolicyNotification() {
+ StdPDPNotification notification = new StdPDPNotification();
notification.setNotificationType(NotificationType.BOTH);
- List<StdLoadedPolicy> loadedPolicies = new ArrayList<>();
StdLoadedPolicy loadedPolicy = new StdLoadedPolicy();
loadedPolicy.setPolicyName("com.testing");
loadedPolicy.setUpdateType(UpdateType.UPDATE);
@@ -200,6 +208,7 @@ public class BackUpMonitorTest {
Map<String, String> matches = new HashMap<>();
matches.put("test", "test");
loadedPolicy.setMatches(matches);
+ List<StdLoadedPolicy> loadedPolicies = new ArrayList<>();
loadedPolicies.add(loadedPolicy);
notification.setLoadedPolicies(loadedPolicies);
List<StdRemovedPolicy> removedPolicies = new ArrayList<>();
@@ -213,7 +222,6 @@ public class BackUpMonitorTest {
private void createPolicyNotification() {
StdPDPNotification notification = new StdPDPNotification();
notification.setNotificationType(NotificationType.UPDATE);
- List<StdLoadedPolicy> loadedPolicies = new ArrayList<>();
StdLoadedPolicy loadedPolicy = new StdLoadedPolicy();
loadedPolicy.setPolicyName("com.testing");
loadedPolicy.setUpdateType(UpdateType.NEW);
@@ -221,19 +229,21 @@ public class BackUpMonitorTest {
Map<String, String> matches = new HashMap<>();
matches.put("test", "test");
loadedPolicy.setMatches(matches);
+ List<StdLoadedPolicy> loadedPolicies = new ArrayList<>();
loadedPolicies.add(loadedPolicy);
notification.setLoadedPolicies(loadedPolicies);
NotificationStore.recordNotification(notification);
}
- private void changeALL(Properties properties, String flag) {
- EntityManager em = Persistence.createEntityManagerFactory("PolicyEngineUtils", properties).createEntityManager();
+ private void changeAll(Properties properties, String flag) {
+ EntityManager em =
+ Persistence.createEntityManagerFactory("PolicyEngineUtils", properties).createEntityManager();
EntityTransaction et = em.getTransaction();
et.begin();
Query query = em.createQuery("select b from BackUpMonitorEntity b where b.resourceNodeName = :nn");
query.setParameter("nn", ResourceNode.BRMS.toString());
- for(Object bMValue: query.getResultList()){
- BackUpMonitorEntity bmEntity = (BackUpMonitorEntity) bMValue;
+ for (Object bmValue : query.getResultList()) {
+ BackUpMonitorEntity bmEntity = (BackUpMonitorEntity) bmValue;
bmEntity.setFlag(flag);
bmEntity.setTimeStamp(new Date());
}
@@ -242,23 +252,23 @@ public class BackUpMonitorTest {
}
private void startSlave(Properties properties) throws JsonProcessingException {
- EntityManager em = Persistence.createEntityManagerFactory("PolicyEngineUtils", properties).createEntityManager();
- EntityTransaction et = em.getTransaction();
- et.begin();
- Query query = em.createQuery("select b from BackUpMonitorEntity b where b.resourceNodeName = :nn");
- query.setParameter("nn", ResourceNode.BRMS.toString());
- List<?> bMList = query.getResultList();
- BackUpMonitorEntity origBM = (BackUpMonitorEntity) bMList.get(0);
- origBM.setFlag("SLAVE");
- origBM.setTimeStamp(new Date());
- BackUpMonitorEntity bMEntity = new BackUpMonitorEntity();
- bMEntity.setResourceNodeName(ResourceNode.BRMS.toString());
- bMEntity.setResourceName("brms_test2");
- bMEntity.setFlag("MASTER");
- bMEntity.setTimeStamp(new Date());
+ EntityManager em =
+ Persistence.createEntityManagerFactory("PolicyEngineUtils", properties).createEntityManager();
+ EntityTransaction et = em.getTransaction();
+ et.begin();
+ Query query = em.createQuery("select b from BackUpMonitorEntity b where b.resourceNodeName = :nn");
+ query.setParameter("nn", ResourceNode.BRMS.toString());
+ List<?> bmList = query.getResultList();
+ BackUpMonitorEntity origBm = (BackUpMonitorEntity) bmList.get(0);
+ origBm.setFlag("SLAVE");
+ origBm.setTimeStamp(new Date());
+ BackUpMonitorEntity bmEntity = new BackUpMonitorEntity();
+ bmEntity.setResourceNodeName(ResourceNode.BRMS.toString());
+ bmEntity.setResourceName("brms_test2");
+ bmEntity.setFlag("MASTER");
+ bmEntity.setTimeStamp(new Date());
StdPDPNotification notification = new StdPDPNotification();
notification.setNotificationType(NotificationType.UPDATE);
- List<StdLoadedPolicy> loadedPolicies = new ArrayList<>();
StdLoadedPolicy loadedPolicy = new StdLoadedPolicy();
loadedPolicy.setPolicyName("com.test");
loadedPolicy.setUpdateType(UpdateType.NEW);
@@ -266,17 +276,18 @@ public class BackUpMonitorTest {
Map<String, String> matches = new HashMap<>();
matches.put("test", "test");
loadedPolicy.setMatches(matches);
+ List<StdLoadedPolicy> loadedPolicies = new ArrayList<>();
loadedPolicies.add(loadedPolicy);
notification.setLoadedPolicies(loadedPolicies);
- bMEntity.setNotificationRecord(PolicyUtils.objectToJsonString(notification));
- em.persist(bMEntity);
- em.persist(origBM);
+ bmEntity.setNotificationRecord(PolicyUtils.objectToJsonString(notification));
+ em.persist(bmEntity);
+ em.persist(origBm);
em.flush();
et.commit();
}
-
+
@Test(expected = BackUpMonitorException.class)
- public void testException() throws InterruptedException, BackUpMonitorException{
+ public void testException() throws InterruptedException, BackUpMonitorException {
BackUpMonitor.stop();
new BackUpMonitorException();
new BackUpMonitorException(new Exception());
@@ -286,7 +297,18 @@ public class BackUpMonitorTest {
}
@After
- public void setup() throws InterruptedException{
- BackUpMonitor.stop();
- }
+ public void setup() throws InterruptedException {
+ BackUpMonitor.stop();
+ }
+
+ /**
+ * Cleanup.
+ *
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ @AfterClass
+ public static void cleanup() throws IOException {
+ FileUtils.deleteQuietly(new File("src/test/resources/META-INF/generatedCreate.ddl"));
+ FileUtils.deleteQuietly(new File("src/test/resources/META-INF/generatedDrop.ddl"));
+ }
}