From 62475a30ef2d425fe04df35ef2dac53c7ab5306a Mon Sep 17 00:00:00 2001 From: Parshad Patel Date: Fri, 16 Nov 2018 20:59:14 +0900 Subject: Rename test classes in apex-pdp Make test classes name consistence by putting 'Test' at end Issue-ID: POLICY-1263 Change-Id: I0179388d84826e698276a1995dd8173a40b5fd2b Signed-off-by: Parshad Patel --- .../policy/apex/examples/aadm/AadmDbWriteTest.java | 64 +++ .../policy/apex/examples/aadm/AadmModelTest.java | 85 ++++ .../policy/apex/examples/aadm/AadmUseCaseTest.java | 459 +++++++++++++++++++++ .../policy/apex/examples/aadm/TestAadmDbWrite.java | 64 --- .../policy/apex/examples/aadm/TestAadmModel.java | 85 ---- .../policy/apex/examples/aadm/TestAadmUseCase.java | 459 --------------------- 6 files changed, 608 insertions(+), 608 deletions(-) create mode 100644 examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmDbWriteTest.java create mode 100644 examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmModelTest.java create mode 100644 examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmUseCaseTest.java delete mode 100644 examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAadmDbWrite.java delete mode 100644 examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAadmModel.java delete mode 100644 examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAadmUseCase.java (limited to 'examples/examples-aadm/src/test') diff --git a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmDbWriteTest.java b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmDbWriteTest.java new file mode 100644 index 000000000..1cc379938 --- /dev/null +++ b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmDbWriteTest.java @@ -0,0 +1,64 @@ +/*- + * ============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 AadmDbWriteTest { + private Connection connection; + TestApexModel testApexModel; + + /** + * Sets up embedded Derby database and the Apex AADM model for the tests. + * @throws Exception exception to be thrown while setting up the database connection + */ + @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.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/AadmModelTest.java b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmModelTest.java new file mode 100644 index 000000000..b0aa23949 --- /dev/null +++ b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmModelTest.java @@ -0,0 +1,85 @@ +/*- + * ============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 AadmModelTest { + private Connection connection; + TestApexModel testApexModel; + + /** + * Sets up embedded Derby database and the AADM model for the tests. + * @throws Exception exception to be thrown while setting up the database connection + */ + @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.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/AadmUseCaseTest.java b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmUseCaseTest.java new file mode 100644 index 000000000..fbab071b6 --- /dev/null +++ b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/AadmUseCaseTest.java @@ -0,0 +1,459 @@ +/*- + * ============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.context.impl.schema.java.JavaSchemaHelperParameters; +import org.onap.policy.apex.context.parameters.ContextParameterConstants; +import org.onap.policy.apex.context.parameters.ContextParameters; +import org.onap.policy.apex.context.parameters.SchemaParameters; +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.onap.policy.common.parameters.ParameterService; +import org.slf4j.ext.XLogger; +import org.slf4j.ext.XLoggerFactory; + +// TODO: Auto-generated Javadoc +/** + * This class tests AADM use case. + * @author Sergey Sachkov (sergey.sachkov@ericsson.com) + * + */ +public class AadmUseCaseTest { + private static final XLogger logger = XLoggerFactory.getXLogger(AadmUseCaseTest.class); + + private SchemaParameters schemaParameters; + private ContextParameters contextParameters; + private EngineParameters engineParameters; + + /** + * Test AADM use case setup. + */ + @Before + public void beforeTest() { + schemaParameters = new SchemaParameters(); + + schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); + schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); + + ParameterService.register(schemaParameters); + + contextParameters = new ContextParameters(); + + contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); + contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); + contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); + contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); + + ParameterService.register(contextParameters); + ParameterService.register(contextParameters.getDistributorParameters()); + ParameterService.register(contextParameters.getLockManagerParameters()); + ParameterService.register(contextParameters.getPersistorParameters()); + + engineParameters = new EngineParameters(); + engineParameters.getExecutorParameterMap().put("MVEL", new MvelExecutorParameters()); + ParameterService.register(engineParameters); + } + + /** + * After test. + */ + @After + public void afterTest() { + ParameterService.deregister(engineParameters); + + ParameterService.deregister(contextParameters.getDistributorParameters()); + ParameterService.deregister(contextParameters.getLockManagerParameters()); + ParameterService.deregister(contextParameters.getPersistorParameters()); + ParameterService.deregister(contextParameters); + + ParameterService.deregister(schemaParameters); + } + + /** + * 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 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 apexPolicyModel the apex policy 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/TestAadmDbWrite.java b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAadmDbWrite.java deleted file mode 100644 index bbcbaab03..000000000 --- a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAadmDbWrite.java +++ /dev/null @@ -1,64 +0,0 @@ -/*- - * ============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 testApexModel; - - /** - * Sets up embedded Derby database and the Apex AADM model for the tests. - * @throws Exception exception to be thrown while setting up the database connection - */ - @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.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 deleted file mode 100644 index 1ac1e9829..000000000 --- a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAadmModel.java +++ /dev/null @@ -1,85 +0,0 @@ -/*- - * ============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 testApexModel; - - /** - * Sets up embedded Derby database and the AADM model for the tests. - * @throws Exception exception to be thrown while setting up the database connection - */ - @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.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/TestAadmUseCase.java b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAadmUseCase.java deleted file mode 100644 index 579bf3484..000000000 --- a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAadmUseCase.java +++ /dev/null @@ -1,459 +0,0 @@ -/*- - * ============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.context.impl.schema.java.JavaSchemaHelperParameters; -import org.onap.policy.apex.context.parameters.ContextParameterConstants; -import org.onap.policy.apex.context.parameters.ContextParameters; -import org.onap.policy.apex.context.parameters.SchemaParameters; -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.onap.policy.common.parameters.ParameterService; -import org.slf4j.ext.XLogger; -import org.slf4j.ext.XLoggerFactory; - -// TODO: Auto-generated Javadoc -/** - * This class tests AADM use case. - * @author Sergey Sachkov (sergey.sachkov@ericsson.com) - * - */ -public class TestAadmUseCase { - private static final XLogger logger = XLoggerFactory.getXLogger(TestAadmUseCase.class); - - private SchemaParameters schemaParameters; - private ContextParameters contextParameters; - private EngineParameters engineParameters; - - /** - * Test AADM use case setup. - */ - @Before - public void beforeTest() { - schemaParameters = new SchemaParameters(); - - schemaParameters.setName(ContextParameterConstants.SCHEMA_GROUP_NAME); - schemaParameters.getSchemaHelperParameterMap().put("JAVA", new JavaSchemaHelperParameters()); - - ParameterService.register(schemaParameters); - - contextParameters = new ContextParameters(); - - contextParameters.setName(ContextParameterConstants.MAIN_GROUP_NAME); - contextParameters.getDistributorParameters().setName(ContextParameterConstants.DISTRIBUTOR_GROUP_NAME); - contextParameters.getLockManagerParameters().setName(ContextParameterConstants.LOCKING_GROUP_NAME); - contextParameters.getPersistorParameters().setName(ContextParameterConstants.PERSISTENCE_GROUP_NAME); - - ParameterService.register(contextParameters); - ParameterService.register(contextParameters.getDistributorParameters()); - ParameterService.register(contextParameters.getLockManagerParameters()); - ParameterService.register(contextParameters.getPersistorParameters()); - - engineParameters = new EngineParameters(); - engineParameters.getExecutorParameterMap().put("MVEL", new MvelExecutorParameters()); - ParameterService.register(engineParameters); - } - - /** - * After test. - */ - @After - public void afterTest() { - ParameterService.deregister(engineParameters); - - ParameterService.deregister(contextParameters.getDistributorParameters()); - ParameterService.deregister(contextParameters.getLockManagerParameters()); - ParameterService.deregister(contextParameters.getPersistorParameters()); - ParameterService.deregister(contextParameters); - - ParameterService.deregister(schemaParameters); - } - - /** - * 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 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 apexPolicyModel the apex policy 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; - } -} -- cgit 1.2.3-korg