aboutsummaryrefslogtreecommitdiffstats
path: root/dmaap-listener/src/test
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2017-11-09 15:18:24 -0500
committerDan Timoney <dtimoney@att.com>2017-11-09 16:27:49 -0500
commit292cce64a1a610283306a5f2280c787d8edb916d (patch)
treea1ca7b1de98fe7e8515522152c3fdefe1cc2ceb9 /dmaap-listener/src/test
parent2f9282706b2eaca0c271d6da27b3dbc0692accc2 (diff)
Add dhcp event handler
Add event handler for DHCP event Change-Id: I2e23ace8ae481bf100f236a4e2723d721eec3470 Issue-ID: CCSDK-142 Signed-off-by: Dan Timoney <dtimoney@att.com>
Diffstat (limited to 'dmaap-listener/src/test')
-rw-r--r--dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncDhcpEventConsumer.java130
-rw-r--r--dmaap-listener/src/test/resources/dblib.properties38
2 files changed, 168 insertions, 0 deletions
diff --git a/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncDhcpEventConsumer.java b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncDhcpEventConsumer.java
new file mode 100644
index 00000000..8c3a839c
--- /dev/null
+++ b/dmaap-listener/src/test/java/org/onap/ccsdk/sli/northbound/dmaapclient/TestSdncDhcpEventConsumer.java
@@ -0,0 +1,130 @@
+/**
+ *
+ */
+package org.onap.ccsdk.sli.northbound.dmaapclient;
+
+import static org.junit.Assert.*;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import javax.sql.rowset.CachedRowSet;
+
+import org.junit.After;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.ccsdk.sli.core.dblib.DBResourceManager;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import ch.vorburger.mariadb4j.DB;
+import ch.vorburger.mariadb4j.DBConfigurationBuilder;
+
+/**
+ * @author dt5972
+ *
+ */
+public class TestSdncDhcpEventConsumer {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TestSdncDhcpEventConsumer.class);
+
+
+ private static final String DHCP_MAP_TABLE = "CREATE TABLE `DHCP_MAP` (\n" +
+ " mac_addr varchar(80) NOT NULL,\n" +
+ " ip_addr varchar(80),\n" +
+ " PRIMARY KEY(`mac_addr`)\n" +
+ ")";
+
+
+
+ private static final String VALID_DHCP_EVENT = "{\"msg_name\":\"DHCPACK\"," +
+ "\"macaddr\":\"fa:16:3e:8f:ea:68\"," +
+ "\"yiaddr\":\"10.3.0.2\"}";
+ private static final String MISSING_MSG_NAME_DHCP_EVENT = "{\"macaddr\":\"fa:16:3e:8f:ea:68\"," +
+ "\"yiaddr\":\"10.3.0.2\"}";
+ private static final String MISSING_MAC_ADDR_DHCP_EVENT = "{\"msg_name\":\"DHCPACK\"," +
+ "\"yiaddr\":\"10.3.0.2\"}";
+ private static final String MISSING_IP_ADDR_DHCP_EVENT = "{\"msg_name\":\"DHCPACK\"," +
+ "\"macaddr\":\"fa:16:3e:8f:ea:68\"}";
+
+ private static final String GET_DHCP_MAPPING = "SELECT * FROM DHCP_MAP WHERE mac_addr = 'fa:16:3e:8f:ea:68'";
+
+
+ private static DBResourceManager dblibSvc;
+ private static DB db;
+
+ private static SdncDhcpEventConsumer consumer;
+
+ /**
+ * @throws java.lang.Exception
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+
+ LOG.debug("Setting up DHCP event testing");
+
+ InputStream propStr = TestSdncDhcpEventConsumer.class.getResourceAsStream("/dblib.properties");
+
+ Properties props = new Properties();
+
+ props.load(propStr);
+
+
+ // Start MariaDB4j database
+
+ LOG.debug("Starting MariaDB instance");
+ DBConfigurationBuilder config = DBConfigurationBuilder.newBuilder();
+ config.setPort(0); // 0 => autom. detect free port
+ db = DB.newEmbeddedDB(config.build());
+ db.start();
+
+
+ // Override jdbc URL and database name
+ props.setProperty("org.onap.ccsdk.sli.jdbc.database", "test");
+ props.setProperty("org.onap.ccsdk.sli.jdbc.url", config.getURL("test"));
+
+
+ // Create dblib connection
+
+ LOG.debug("Getting DBResourceManager instance");
+ dblibSvc = new DBResourceManager(props);
+
+ // Create DHCP_MAP table
+ dblibSvc.writeData(DHCP_MAP_TABLE, null, null);
+
+ consumer = new SdncDhcpEventConsumer();
+ consumer.setJdbcDataSource(dblibSvc);
+ LOG.debug("Setup complete");
+
+ }
+
+
+ @Test
+ public void testValid() throws InvalidMessageException, SQLException {
+ consumer.processMsg(VALID_DHCP_EVENT);
+
+ CachedRowSet results = dblibSvc.getData(GET_DHCP_MAPPING, null, null);
+
+ if (!results.next()) {
+ fail("Test query ["+GET_DHCP_MAPPING+"] returned no data");
+ }
+
+ }
+
+ @Test (expected = InvalidMessageException.class)
+ public void testMissingMsgName() throws InvalidMessageException {
+ consumer.processMsg(MISSING_MSG_NAME_DHCP_EVENT);
+ }
+
+ @Test (expected = InvalidMessageException.class)
+ public void testMissingMacAddress() throws InvalidMessageException {
+ consumer.processMsg(MISSING_MAC_ADDR_DHCP_EVENT);
+ }
+
+ @Test (expected = InvalidMessageException.class)
+ public void testMissingIpAddress() throws InvalidMessageException {
+ consumer.processMsg(MISSING_IP_ADDR_DHCP_EVENT);
+ }
+}
diff --git a/dmaap-listener/src/test/resources/dblib.properties b/dmaap-listener/src/test/resources/dblib.properties
new file mode 100644
index 00000000..9506ac8d
--- /dev/null
+++ b/dmaap-listener/src/test/resources/dblib.properties
@@ -0,0 +1,38 @@
+###
+# ============LICENSE_START=======================================================
+# openECOMP : SDN-C
+# ================================================================================
+# Copyright (C) 2017 AT&T Intellectual Property. All rights
+# reserved.
+# ================================================================================
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+# ============LICENSE_END=========================================================
+###
+
+# dblib.properrties
+org.onap.ccsdk.sli.dbtype=jdbc
+
+org.onap.ccsdk.sli.jdbc.hosts=sdnctldb01
+org.onap.ccsdk.sli.jdbc.url=jdbc:mysql://dbhost:3306/sdnctl
+org.onap.ccsdk.sli.jdbc.driver=org.mariadb.jdbc.Driver
+org.onap.ccsdk.sli.jdbc.database=sdnctl
+org.onap.ccsdk.sli.jdbc.user=sdnctl
+org.onap.ccsdk.sli.jdbc.password=gamma
+org.onap.ccsdk.sli.jdbc.connection.name=sdnctldb01
+org.onap.ccsdk.sli.jdbc.connection.timeout=50
+org.onap.ccsdk.sli.jdbc.request.timeout=100
+org.onap.ccsdk.sli.jdbc.limit.init=10
+org.onap.ccsdk.sli.jdbc.limit.min=10
+org.onap.ccsdk.sli.jdbc.limit.max=20
+org.onap.dblib.connection.recovery=false
+