From 4cfa2e2d98f6877d54da304ef17f096284430908 Mon Sep 17 00:00:00 2001 From: liamfallon Date: Thu, 13 Sep 2018 15:25:32 +0100 Subject: Sonar/Checkstyle in service/plugins Sonar and Checkstyle changes in plugins and services, and knock on changes Issue-ID: POLICY-1034 Change-Id: Iff7df74e54fce2c661dcc2fae75ae93d4cacfe5b Signed-off-by: liamfallon --- .../policy/apex/examples/aadm/TestAADMModel.java | 85 ---- .../apex/examples/aadm/TestAADMModelCreator.java | 57 --- .../policy/apex/examples/aadm/TestAADMUseCase.java | 455 -------------------- .../policy/apex/examples/aadm/TestAadmDbWrite.java | 2 +- .../policy/apex/examples/aadm/TestAadmModel.java | 85 ++++ .../apex/examples/aadm/TestAadmModelCreator.java | 57 +++ .../policy/apex/examples/aadm/TestAadmUseCase.java | 459 +++++++++++++++++++++ 7 files changed, 602 insertions(+), 598 deletions(-) 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/TestAADMModelCreator.java delete mode 100644 examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAADMUseCase.java create mode 100644 examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAadmModel.java create mode 100644 examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAadmModelCreator.java create mode 100644 examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAadmUseCase.java (limited to 'examples/examples-aadm/src/test/java') 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 ba992b522..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/TestAADMModelCreator.java b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAADMModelCreator.java deleted file mode 100644 index 421a45a15..000000000 --- a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAADMModelCreator.java +++ /dev/null @@ -1,57 +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 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; - -/** - * This class implements Interface TestApexModelCreator to support AADM model. - * @author Liam Fallon (liam.fallon@ericsson.com) - */ -public class TestAADMModelCreator implements TestApexModelCreator { - - @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 deleted file mode 100644 index 21f240ba8..000000000 --- a/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAADMUseCase.java +++ /dev/null @@ -1,455 +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; - -/** - * 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 - 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 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/TestAadmDbWrite.java b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAadmDbWrite.java index b67bb6245..bbcbaab03 100644 --- 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 @@ -44,7 +44,7 @@ public class TestAadmDbWrite { 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()); + testApexModel = new TestApexModel(AxPolicyModel.class, new TestAadmModelCreator()); } @After 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..1ac1e9829 --- /dev/null +++ b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAadmModel.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 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/TestAadmModelCreator.java b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAadmModelCreator.java new file mode 100644 index 000000000..7f34bff59 --- /dev/null +++ b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAadmModelCreator.java @@ -0,0 +1,57 @@ +/*- + * ============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; + +/** + * This class implements Interface TestApexModelCreator to support AADM model. + * @author Liam Fallon (liam.fallon@ericsson.com) + */ +public class TestAadmModelCreator implements TestApexModelCreator { + + @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..579bf3484 --- /dev/null +++ b/examples/examples-aadm/src/test/java/org/onap/policy/apex/examples/aadm/TestAadmUseCase.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 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