summaryrefslogtreecommitdiffstats
path: root/examples/examples-aadm/src/test/java
diff options
context:
space:
mode:
authorramverma <ram.krishna.verma@ericsson.com>2018-07-25 17:26:52 +0100
committerramverma <ram.krishna.verma@ericsson.com>2018-07-25 17:32:29 +0100
commitf8959f5c51e6338b62e23ea503eb86d9c65d7c74 (patch)
tree7a8afbbf61f7091c30aadfc1cace70fb6e65bff9 /examples/examples-aadm/src/test/java
parentdccf9a9e0758be0a926c94bf1599ee625066100d (diff)
Renaming examples in apex-pdp
Renaming the examples as per what the documentation expects them. Otherwise the documents won't work. Change-Id: Ib9e30bf5a4cec0fec981372e1d9f3a0ee5d60f2f Issue-ID: POLICY-861 Signed-off-by: ramverma <ram.krishna.verma@ericsson.com>
Diffstat (limited to 'examples/examples-aadm/src/test/java')
-rw-r--r--examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAADMDBWrite.java60
-rw-r--r--examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAADMModel.java81
-rw-r--r--examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAADMModelCreator.java56
-rw-r--r--examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAADMUseCase.java412
-rw-r--r--examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestApexActionListener.java91
5 files changed, 700 insertions, 0 deletions
diff --git a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAADMDBWrite.java b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAADMDBWrite.java
new file mode 100644
index 000000000..02e6f9179
--- /dev/null
+++ b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAADMDBWrite.java
@@ -0,0 +1,60 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.examples.aadm;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.DriverManager;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.dao.DAOParameters;
+import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+
+public class TestAADMDBWrite {
+ private Connection connection;
+ TestApexModel<AxPolicyModel> testApexModel;
+
+ @Before
+ public void setup() throws Exception {
+ Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
+ connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true");
+
+ testApexModel = new TestApexModel<AxPolicyModel>(AxPolicyModel.class, new TestAADMModelCreator());
+ }
+
+ @After
+ public void teardown() throws Exception {
+ connection.close();
+ new File("derby.log").delete();
+ }
+
+ @Test
+ public void testModelWriteReadJPA() throws Exception {
+ final DAOParameters daoParameters = new DAOParameters();
+ daoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
+ daoParameters.setPersistenceUnit("AADMModelTest");
+
+ testApexModel.testApexModelWriteReadJPA(daoParameters);
+ }
+}
diff --git a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAADMModel.java b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAADMModel.java
new file mode 100644
index 000000000..2c62c4994
--- /dev/null
+++ b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAADMModel.java
@@ -0,0 +1,81 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.examples.aadm;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.sql.Connection;
+import java.sql.DriverManager;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.model.basicmodel.concepts.AxValidationResult;
+import org.onap.policy.apex.model.basicmodel.dao.DAOParameters;
+import org.onap.policy.apex.model.basicmodel.test.TestApexModel;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+
+public class TestAADMModel {
+ private Connection connection;
+ TestApexModel<AxPolicyModel> testApexModel;
+
+ @Before
+ public void setup() throws Exception {
+ Class.forName("org.apache.derby.jdbc.EmbeddedDriver").newInstance();
+ connection = DriverManager.getConnection("jdbc:derby:memory:apex_test;create=true");
+
+ testApexModel = new TestApexModel<AxPolicyModel>(AxPolicyModel.class, new TestAADMModelCreator());
+ }
+
+ @After
+ public void teardown() throws Exception {
+ connection.close();
+ new File("derby.log").delete();
+ }
+
+ @Test
+ public void testModelValid() throws Exception {
+ final AxValidationResult result = testApexModel.testApexModelValid();
+ assertTrue(result.toString().equals(VALID_MODEL_STRING));
+ }
+
+ @Test
+ public void testModelWriteReadXML() throws Exception {
+ testApexModel.testApexModelWriteReadXML();
+ }
+
+ @Test
+ public void testModelWriteReadJSON() throws Exception {
+ testApexModel.testApexModelWriteReadJSON();
+ }
+
+ @Test
+ public void testModelWriteReadJPA() throws Exception {
+ final DAOParameters daoParameters = new DAOParameters();
+ daoParameters.setPluginClass("org.onap.policy.apex.model.basicmodel.dao.impl.DefaultApexDao");
+ daoParameters.setPersistenceUnit("AADMModelTest");
+
+ testApexModel.testApexModelWriteReadJPA(daoParameters);
+ }
+
+ private static final String VALID_MODEL_STRING = "***validation of model successful***";
+}
diff --git a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAADMModelCreator.java b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAADMModelCreator.java
new file mode 100644
index 000000000..9aa2095c7
--- /dev/null
+++ b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAADMModelCreator.java
@@ -0,0 +1,56 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.examples.aadm;
+
+import org.onap.policy.apex.examples.aadm.model.AADMDomainModelFactory;
+import org.onap.policy.apex.model.basicmodel.test.TestApexModelCreator;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+
+/**
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestAADMModelCreator implements TestApexModelCreator<AxPolicyModel> {
+
+ @Override
+ public AxPolicyModel getModel() {
+ return new AADMDomainModelFactory().getAADMPolicyModel();
+ }
+
+ @Override
+ public AxPolicyModel getMalstructuredModel() {
+ return null;
+ }
+
+ @Override
+ public AxPolicyModel getObservationModel() {
+ return null;
+ }
+
+ @Override
+ public AxPolicyModel getWarningModel() {
+ return getModel();
+ }
+
+ @Override
+ public AxPolicyModel getInvalidModel() {
+ return null;
+ }
+}
diff --git a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAADMUseCase.java b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAADMUseCase.java
new file mode 100644
index 000000000..58b1800ba
--- /dev/null
+++ b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAADMUseCase.java
@@ -0,0 +1,412 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.examples.aadm;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.onap.policy.apex.context.ContextAlbum;
+import org.onap.policy.apex.core.engine.EngineParameters;
+import org.onap.policy.apex.core.engine.engine.impl.ApexEngineFactory;
+import org.onap.policy.apex.core.engine.engine.impl.ApexEngineImpl;
+import org.onap.policy.apex.core.engine.event.EnEvent;
+import org.onap.policy.apex.examples.aadm.concepts.ENodeBStatus;
+import org.onap.policy.apex.examples.aadm.model.AADMDomainModelFactory;
+import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
+import org.onap.policy.apex.model.basicmodel.concepts.AxArtifactKey;
+import org.onap.policy.apex.model.eventmodel.concepts.AxEvent;
+import org.onap.policy.apex.model.policymodel.concepts.AxPolicyModel;
+import org.onap.policy.apex.plugins.executor.mvel.MVELExecutorParameters;
+import org.slf4j.ext.XLogger;
+import org.slf4j.ext.XLoggerFactory;
+
+/**
+ * User: Sergey Sachkov Date: 13/10/15
+ */
+public class TestAADMUseCase {
+ private static final XLogger logger = XLoggerFactory.getXLogger(TestAADMUseCase.class);
+
+ /**
+ * Test aadm use case setup.
+ */
+ @Before
+ public void testAADMUseCaseSetup() {}
+
+ /**
+ * Test aadm case.
+ *
+ * @throws ApexException the apex exception
+ * @throws InterruptedException the interrupted exception
+ * @throws IOException Signals that an I/O exception has occurred.
+ */
+ @Test
+ public void testAADMCase() throws ApexException, InterruptedException, IOException {
+ final AxPolicyModel apexPolicyModel = new AADMDomainModelFactory().getAADMPolicyModel();
+ assertNotNull(apexPolicyModel);
+ final AxArtifactKey key = new AxArtifactKey("AADMApexEngine", "0.0.1");
+
+ final EngineParameters parameters = new EngineParameters();
+ parameters.getExecutorParameterMap().put("MVEL", new MVELExecutorParameters());
+
+ final ApexEngineImpl apexEngine = (ApexEngineImpl) new ApexEngineFactory().createApexEngine(key);
+ final TestApexActionListener listener = new TestApexActionListener("Test");
+ apexEngine.addEventListener("listener", listener);
+ apexEngine.updateModel(apexPolicyModel);
+ apexEngine.start();
+
+ final AxEvent axEvent = getTriggerEvent(apexPolicyModel);
+ assertNotNull(axEvent);
+
+ // getting number of connections send it to policy, expecting probe action
+ logger.info("Sending too many connections trigger ");
+ EnEvent event = apexEngine.createEvent(axEvent.getKey());
+ event.put("IMSI", new Long(123456));
+ event.put("IMSI_IP", "101.111.121.131");
+ event.put("ENODEB_ID", new Long(123));
+ event.put("SERVICE_REQUEST_COUNT", 99);
+ event.put("AVG_SUBSCRIBER_SERVICE_REQUEST", 101.0);
+ event.put("UE_IP_ADDRESS", "101.111.121.131");
+ event.put("NUM_SUBSCRIBERS", 101);
+ event.put("ACTTASK", "");
+ event.put("APPLICATION", "");
+ event.put("ATTACH_COUNT", 0);
+ event.put("AVG_SUBSCRIBER_ATTACH", 0D);
+ event.put("DoS", false);
+ event.put("NW_IP", "");
+ event.put("PROBE_ON", false);
+ event.put("SGW_IP_ADDRESS", "");
+ event.put("TCP_ON", false);
+ event.put("TCP_UE_SIDE_AVG_THROUGHPUT", 0D);
+ event.put("TCP_UE_SIDE_MEDIAN_RTT_TX_TO_RX", 0L);
+ event.put("http_host_class", "");
+ event.put("protocol_group", "");
+ apexEngine.handleEvent(event);
+ EnEvent result = listener.getResult();
+ assertTrue(result.getName().startsWith("XSTREAM_AADM_ACT_EVENT"));
+ assertEquals("ExecutionIDs are different", event.getExecutionID(), result.getExecutionID());
+ // no DOS_IN_eNodeB set so return probe action
+ assertTrue(result.get("ACTTASK").equals("probe"));
+ assertTrue((boolean) result.get("TCP_ON"));
+ assertTrue((boolean) result.get("PROBE_ON"));
+ logger.info("Receiving action event with {} action", result.get("ACTTASK"));
+
+ final ContextAlbum eNodeBStatusAlbum = apexEngine.getInternalContext().get("ENodeBStatusAlbum");
+ final ENodeBStatus eNodeBStatus = (ENodeBStatus) eNodeBStatusAlbum.get("123");
+ eNodeBStatus.setDOSCount(101);
+ eNodeBStatusAlbum.put(eNodeBStatus.getENodeB(), eNodeBStatus);
+
+ logger.info("Sending too many connections trigger ");
+ event = apexEngine.createEvent(axEvent.getKey());
+ event.put("IMSI", new Long(123456));
+ event.put("IMSI_IP", "101.111.121.131");
+ event.put("ENODEB_ID", new Long(123));
+ event.put("SERVICE_REQUEST_COUNT", 101);
+ event.put("AVG_SUBSCRIBER_SERVICE_REQUEST", 99.0);
+ event.put("UE_IP_ADDRESS", "101.111.121.131");
+ event.put("NUM_SUBSCRIBERS", 101);
+ event.put("TCP_UE_SIDE_AVG_THROUGHPUT", 101.0);
+ event.put("ACTTASK", "");
+ event.put("APPLICATION", "");
+ event.put("ATTACH_COUNT", 0);
+ event.put("AVG_SUBSCRIBER_ATTACH", 0D);
+ event.put("DoS", false);
+ event.put("NW_IP", "");
+ event.put("PROBE_ON", false);
+ event.put("SGW_IP_ADDRESS", "");
+ event.put("TCP_ON", false);
+ event.put("TCP_UE_SIDE_MEDIAN_RTT_TX_TO_RX", 0L);
+ event.put("http_host_class", "");
+ event.put("protocol_group", "");
+
+ apexEngine.handleEvent(event);
+ result = listener.getResult();
+ assertTrue(result.getName().startsWith("XSTREAM_AADM_ACT_EVENT"));
+ assertEquals("ExecutionIDs are different", event.getExecutionID(), result.getExecutionID());
+ // DOS_IN_eNodeB set to be more than throughput so return act action
+ assertTrue(result.get("ACTTASK").equals("act"));
+ // only one imsi was sent to process, so stop probe and tcp
+ assertTrue(!(boolean) result.get("TCP_ON"));
+ assertTrue(!(boolean) result.get("PROBE_ON"));
+ assertEquals(100, ((ENodeBStatus) eNodeBStatusAlbum.get("123")).getDOSCount());
+ logger.info("Receiving action event with {} action", result.get("ACTTASK"));
+
+ ((ENodeBStatus) eNodeBStatusAlbum.get("123")).setDOSCount(99);
+
+ // getting number of connections send it to policy, expecting probe action
+ logger.info("Sending too many connections trigger ");
+ event = apexEngine.createEvent(axEvent.getKey());
+ event.put("IMSI", new Long(123456));
+ event.put("IMSI_IP", "101.111.121.131");
+ event.put("ENODEB_ID", new Long(123));
+ event.put("SERVICE_REQUEST_COUNT", 99);
+ event.put("AVG_SUBSCRIBER_SERVICE_REQUEST", 101.0);
+ event.put("UE_IP_ADDRESS", "101.111.121.131");
+ event.put("NUM_SUBSCRIBERS", 99);
+ event.put("ACTTASK", "");
+ event.put("APPLICATION", "");
+ event.put("ATTACH_COUNT", 0);
+ event.put("AVG_SUBSCRIBER_ATTACH", 0D);
+ event.put("DoS", false);
+ event.put("NW_IP", "");
+ event.put("PROBE_ON", false);
+ event.put("SGW_IP_ADDRESS", "");
+ event.put("TCP_ON", false);
+ event.put("TCP_UE_SIDE_AVG_THROUGHPUT", 0D);
+ event.put("TCP_UE_SIDE_MEDIAN_RTT_TX_TO_RX", 0L);
+ event.put("http_host_class", "");
+ event.put("protocol_group", "");
+
+ apexEngine.handleEvent(event);
+ result = listener.getResult();
+ assertTrue(result.getName().startsWith("XSTREAM_AADM_ACT_EVENT"));
+ assertEquals("ExecutionIDs are different", event.getExecutionID(), result.getExecutionID());
+ assertTrue(result.get("ACTTASK").equals("probe"));
+ assertTrue((boolean) result.get("TCP_ON"));
+ assertTrue((boolean) result.get("PROBE_ON"));
+ assertEquals(99, ((ENodeBStatus) eNodeBStatusAlbum.get("123")).getDOSCount());
+
+ ((ENodeBStatus) eNodeBStatusAlbum.get("123")).setDOSCount(99);
+
+ // tcp correlation return positive dos
+ logger.info("Receiving action event with {} action", result.get("ACTTASK"));
+ event = apexEngine.createEvent(axEvent.getKey());
+ event.put("IMSI", new Long(123456));
+ event.put("IMSI_IP", "101.111.121.131");
+ event.put("ENODEB_ID", new Long(123));
+ event.put("TCP_UE_SIDE_AVG_THROUGHPUT", 101.0);
+ event.put("ACTTASK", "");
+ event.put("APPLICATION", "");
+ event.put("ATTACH_COUNT", 0);
+ event.put("AVG_SUBSCRIBER_ATTACH", 0D);
+ event.put("AVG_SUBSCRIBER_SERVICE_REQUEST", 0.0);
+ event.put("DoS", false);
+ event.put("NUM_SUBSCRIBERS", 0);
+ event.put("NW_IP", "");
+ event.put("PROBE_ON", false);
+ event.put("SERVICE_REQUEST_COUNT", 0);
+ event.put("SGW_IP_ADDRESS", "");
+ event.put("TCP_ON", false);
+ event.put("TCP_UE_SIDE_MEDIAN_RTT_TX_TO_RX", 0L);
+ event.put("UE_IP_ADDRESS", "");
+ event.put("http_host_class", "");
+ event.put("protocol_group", "");
+
+ apexEngine.handleEvent(event);
+ result = listener.getResult();
+ assertTrue(result.getName().startsWith("XSTREAM_AADM_ACT_EVENT"));
+ assertEquals("ExecutionIDs are different", event.getExecutionID(), result.getExecutionID());
+ assertTrue(result.get("ACTTASK").equals("act"));
+ assertTrue(!(boolean) result.get("TCP_ON"));
+ assertTrue(!(boolean) result.get("PROBE_ON"));
+ assertEquals(98, ((ENodeBStatus) eNodeBStatusAlbum.get("123")).getDOSCount());
+ logger.info("Receiving action event with {} action", result.get("ACTTASK"));
+
+ ((ENodeBStatus) eNodeBStatusAlbum.get("123")).setDOSCount(101);
+
+ // user moving enodeB
+ logger.info("Sending too many connections trigger ");
+ event = apexEngine.createEvent(axEvent.getKey());
+ event.put("IMSI", new Long(123456));
+ event.put("IMSI_IP", "101.111.121.131");
+ event.put("ENODEB_ID", new Long(123));
+ event.put("SERVICE_REQUEST_COUNT", 99);
+ event.put("AVG_SUBSCRIBER_SERVICE_REQUEST", 101.0);
+ event.put("UE_IP_ADDRESS", "101.111.121.131");
+ event.put("NUM_SUBSCRIBERS", 101);
+ event.put("ACTTASK", "");
+ event.put("APPLICATION", "");
+ event.put("ATTACH_COUNT", 0);
+ event.put("AVG_SUBSCRIBER_ATTACH", 0D);
+ event.put("AVG_SUBSCRIBER_SERVICE_REQUEST", 0.0);
+ event.put("DoS", false);
+ event.put("NW_IP", "");
+ event.put("PROBE_ON", false);
+ event.put("SGW_IP_ADDRESS", "");
+ event.put("TCP_ON", false);
+ event.put("TCP_UE_SIDE_AVG_THROUGHPUT", 0D);
+ event.put("TCP_UE_SIDE_MEDIAN_RTT_TX_TO_RX", 0L);
+ event.put("http_host_class", "");
+ event.put("protocol_group", "");
+
+ apexEngine.handleEvent(event);
+ result = listener.getResult();
+ assertTrue(result.getName().startsWith("XSTREAM_AADM_ACT_EVENT"));
+ assertEquals("ExecutionIDs are different", event.getExecutionID(), result.getExecutionID());
+ assertTrue(result.get("ACTTASK").equals("act"));
+ assertTrue(!(boolean) result.get("TCP_ON"));
+ assertTrue(!(boolean) result.get("PROBE_ON"));
+ assertEquals(100, ((ENodeBStatus) eNodeBStatusAlbum.get("123")).getDOSCount());
+ logger.info("Receiving action event with {} action", result.get("ACTTASK"));
+
+ logger.info("Sending too many connections trigger ");
+ event = apexEngine.createEvent(axEvent.getKey());
+ event.put("IMSI", new Long(123456));
+ event.put("ENODEB_ID", new Long(124));
+ event.put("SERVICE_REQUEST_COUNT", 99);
+ event.put("AVG_SUBSCRIBER_SERVICE_REQUEST", 101.0);
+ event.put("UE_IP_ADDRESS", "101.111.121.131");
+ event.put("NUM_SUBSCRIBERS", 101);
+ event.put("ACTTASK", "");
+ event.put("APPLICATION", "");
+ event.put("ATTACH_COUNT", 0);
+ event.put("AVG_SUBSCRIBER_ATTACH", 0D);
+ event.put("DoS", false);
+ event.put("IMSI_IP", "");
+ event.put("NW_IP", "");
+ event.put("PROBE_ON", false);
+ event.put("SGW_IP_ADDRESS", "");
+ event.put("TCP_ON", false);
+ event.put("TCP_UE_SIDE_AVG_THROUGHPUT", 0D);
+ event.put("TCP_UE_SIDE_MEDIAN_RTT_TX_TO_RX", 0L);
+ event.put("http_host_class", "");
+ event.put("protocol_group", "");
+
+ apexEngine.handleEvent(event);
+ result = listener.getResult();
+ assertTrue(result.getName().startsWith("XSTREAM_AADM_ACT_EVENT"));
+ assertEquals("ExecutionIDs are different", event.getExecutionID(), result.getExecutionID());
+ assertTrue(result.get("ACTTASK").equals("probe"));
+ assertTrue((boolean) result.get("TCP_ON"));
+ assertTrue((boolean) result.get("PROBE_ON"));
+ assertEquals(99, ((ENodeBStatus) eNodeBStatusAlbum.get("123")).getDOSCount());
+ assertEquals(1, ((ENodeBStatus) eNodeBStatusAlbum.get("124")).getDOSCount());
+ logger.info("Receiving action event with {} action", result.get("ACTTASK"));
+ // End of user moving enodeB
+
+ ((ENodeBStatus) eNodeBStatusAlbum.get("123")).setDOSCount(101);
+
+ // user becomes non anomalous
+ logger.info("Sending too many connections trigger ");
+ event = apexEngine.createEvent(axEvent.getKey());
+ event.put("IMSI", new Long(123456));
+ event.put("IMSI_IP", "101.111.121.131");
+ event.put("ENODEB_ID", new Long(123));
+ event.put("SERVICE_REQUEST_COUNT", 99);
+ event.put("AVG_SUBSCRIBER_SERVICE_REQUEST", 101.0);
+ event.put("UE_IP_ADDRESS", "101.111.121.131");
+ event.put("NUM_SUBSCRIBERS", 101);
+ event.put("ACTTASK", "");
+ event.put("APPLICATION", "");
+ event.put("ATTACH_COUNT", 0);
+ event.put("AVG_SUBSCRIBER_ATTACH", 0D);
+ event.put("DoS", false);
+ event.put("NW_IP", "");
+ event.put("PROBE_ON", false);
+ event.put("SGW_IP_ADDRESS", "");
+ event.put("TCP_ON", false);
+ event.put("TCP_UE_SIDE_AVG_THROUGHPUT", 0D);
+ event.put("TCP_UE_SIDE_MEDIAN_RTT_TX_TO_RX", 0L);
+ event.put("http_host_class", "");
+ event.put("protocol_group", "");
+
+ apexEngine.handleEvent(event);
+ result = listener.getResult();
+ assertTrue(result.getName().startsWith("XSTREAM_AADM_ACT_EVENT"));
+ assertEquals("ExecutionIDs are different", event.getExecutionID(), result.getExecutionID());
+ assertTrue(result.get("ACTTASK").equals("probe"));
+ assertTrue((boolean) result.get("TCP_ON"));
+ assertTrue((boolean) result.get("PROBE_ON"));
+ assertEquals(102, ((ENodeBStatus) eNodeBStatusAlbum.get("123")).getDOSCount());
+ logger.info("Receiving action event with {} action", result.get("ACTTASK"));
+
+ logger.info("Sending too many connections trigger ");
+ event = apexEngine.createEvent(axEvent.getKey());
+ event.put("IMSI", new Long(123456));
+ event.put("ENODEB_ID", new Long(123));
+ event.put("SERVICE_REQUEST_COUNT", 99);
+ event.put("UE_IP_ADDRESS", "101.111.121.131");
+ event.put("ACTTASK", "");
+ event.put("APPLICATION", "");
+ event.put("ATTACH_COUNT", 0);
+ event.put("AVG_SUBSCRIBER_ATTACH", 0D);
+ event.put("AVG_SUBSCRIBER_SERVICE_REQUEST", 0.0);
+ event.put("DoS", false);
+ event.put("IMSI_IP", "");
+ event.put("NUM_SUBSCRIBERS", 0);
+ event.put("NW_IP", "");
+ event.put("PROBE_ON", false);
+ event.put("SGW_IP_ADDRESS", "");
+ event.put("TCP_ON", false);
+ event.put("TCP_UE_SIDE_AVG_THROUGHPUT", 0D);
+ event.put("TCP_UE_SIDE_MEDIAN_RTT_TX_TO_RX", 0L);
+ event.put("http_host_class", "");
+ event.put("protocol_group", "");
+
+ apexEngine.handleEvent(event);
+ result = listener.getResult();
+ assertTrue(result.getName().startsWith("XSTREAM_AADM_ACT_EVENT"));
+ assertEquals("ExecutionIDs are different", event.getExecutionID(), result.getExecutionID());
+ assertTrue(result.get("ACTTASK").equals("probe"));
+ assertTrue((boolean) result.get("TCP_ON"));
+ assertTrue((boolean) result.get("PROBE_ON"));
+ assertEquals(102, ((ENodeBStatus) eNodeBStatusAlbum.get("123")).getDOSCount());
+ logger.info("Receiving action event with {} action", result.get("ACTTASK"));
+ // End of user becomes non anomalous
+ apexEngine.handleEvent(result);
+ result = listener.getResult();
+ assertTrue(result.getName().startsWith("SAPCBlacklistSubscriberEvent"));
+ assertTrue(result.get("PROFILE").equals("ServiceA"));
+ assertTrue(result.get("BLACKLIST_ON").equals(true));
+
+ event = apexEngine.createEvent(new AxArtifactKey("PeriodicEvent", "0.0.1"));
+ event.put("PERIODIC_EVENT_COUNT", (long) 100);
+ event.put("PERIODIC_DELAY", (long) 1000);
+ event.put("PERIODIC_FIRST_TIME", System.currentTimeMillis());
+ event.put("PERIODIC_CURRENT_TIME", System.currentTimeMillis());
+ event.put("PERIODIC_LAST_TIME", System.currentTimeMillis());
+ apexEngine.handleEvent(event);
+ result = listener.getResult();
+ assertTrue(result.getName().startsWith("SAPCBlacklistSubscriberEvent"));
+ assertEquals("ExecutionIDs are different", event.getExecutionID(), result.getExecutionID());
+ assertEquals(0L, result.get("IMSI"));
+ assertTrue(result.get("PROFILE").equals("ServiceA"));
+ assertTrue(result.get("BLACKLIST_ON").equals(false));
+
+ apexEngine.stop();
+ }
+
+ /**
+ * Test vpn cleardown.
+ */
+ @After
+ public void testAADMCleardown() {}
+
+ /**
+ * Gets the trigger event.
+ *
+ * @param apexModel the apex model
+ * @return the trigger event
+ */
+ private AxEvent getTriggerEvent(final AxPolicyModel apexPolicyModel) {
+ for (final AxEvent axEvent : apexPolicyModel.getEvents().getEventMap().values()) {
+ if (axEvent.getKey().getID().equals("AADMEvent:0.0.1")) {
+ return axEvent;
+ }
+ }
+ return null;
+ }
+}
diff --git a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestApexActionListener.java b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestApexActionListener.java
new file mode 100644
index 000000000..ccf4539aa
--- /dev/null
+++ b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestApexActionListener.java
@@ -0,0 +1,91 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2016-2018 Ericsson. 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.policy.apex.examples.aadm;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.onap.policy.apex.core.engine.engine.EnEventListener;
+import org.onap.policy.apex.core.engine.event.EnEvent;
+import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
+
+/**
+ * The listener interface for receiving testApexAction events. The class that is interested in processing a
+ * testApexAction event implements this interface, and the object created with that class is registered with a component
+ * using the component's <code>addTestApexActionListener</code> method. When the testApexAction event occurs, that
+ * object's appropriate method is invoked.
+ *
+ * @author Liam Fallon (liam.fallon@ericsson.com)
+ */
+public class TestApexActionListener implements EnEventListener {
+ List<EnEvent> resultEvents = new ArrayList<EnEvent>();
+
+ private final String id;
+
+ /**
+ * Instantiates a new test apex action listener.
+ *
+ * @param id the id
+ */
+ public TestApexActionListener(final String id) {
+ this.id = id;
+ }
+
+ /**
+ * Gets the result.
+ *
+ * @return the result
+ */
+ public EnEvent getResult() {
+ while (resultEvents.isEmpty()) {
+ ThreadUtilities.sleep(100);
+ }
+ return resultEvents.remove(0);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.onap.policy.apex.core.engine.engine.EnEventListener#onEnEvent(org.onap.policy.apex.core.engine.event.EnEvent)
+ */
+ @Override
+ public void onEnEvent(final EnEvent actionEvent) {
+ try {
+ Thread.sleep(100);
+ } catch (final InterruptedException e) {
+ e.printStackTrace();
+ }
+ if (actionEvent != null) {
+ System.out.println("Action event from engine:" + actionEvent.getName());
+ resultEvents.add(actionEvent);
+ }
+ }
+
+ /**
+ * Gets the id.
+ *
+ * @return the id
+ */
+ public String getId() {
+ return id;
+ }
+}