Handle duplicate DHCP event

Handle case where 2 DHCP events received for same mac addr.  Should use
most recent IP address.

Change-Id: I90399ce3c39e07c2472366c78115812a64e9124b
Issue-ID: CCSDK-142
Signed-off-by: Dan Timoney <dtimoney@att.com>
diff --git a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncDhcpEventConsumer.java b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncDhcpEventConsumer.java
index 666ed68..03560d3 100644
--- a/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncDhcpEventConsumer.java
+++ b/dmaap-listener/src/main/java/org/onap/ccsdk/sli/northbound/dmaapclient/SdncDhcpEventConsumer.java
@@ -124,8 +124,7 @@
 
 		try {
 
-			jdbcDataSource.writeData("INSERT INTO DHCP_MAP(mac_addr, ip_addr) VALUES('" + macAddr + "','" + ipAddr + "')",
-					null, null);
+			jdbcDataSource.writeData("INSERT INTO DHCP_MAP(mac_addr, ip_addr) VALUES('" + macAddr + "','" + ipAddr + "') ON DUPLICATE KEY UPDATE ip_addr = '"+ipAddr+"'", null, null);
 
 		} catch (SQLException e) {
 			LOG.error("Could not insert DHCP event data into the database ", e);
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
index 8c3a839..04f098a 100644
--- 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
@@ -42,6 +42,9 @@
 	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 SECOND_DHCP_EVENT =  "{\"msg_name\":\"DHCPACK\"," +
+		     "\"macaddr\":\"fa:16:3e:8f:ea:68\"," +
+		     "\"yiaddr\":\"10.3.0.3\"}";
 	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\"," +
@@ -104,11 +107,17 @@
 	@Test
 	public void testValid() throws InvalidMessageException, SQLException {
 		consumer.processMsg(VALID_DHCP_EVENT);
+		consumer.processMsg(SECOND_DHCP_EVENT);
 
 		CachedRowSet results = dblibSvc.getData(GET_DHCP_MAPPING, null, null);
 
 		if (!results.next()) {
 			fail("Test query ["+GET_DHCP_MAPPING+"] returned no data");
+		} else {
+			String ipAddr = results.getString("ip_addr");
+			if (!"10.3.0.3".equals(ipAddr)) {
+				fail("Expecting ipAddr to be 10.3.0.3, but was "+ipAddr);
+			}
 		}
 
 	}