Add missing agr and iterate on row 41/64741/2
authorAlexis de Talhouët <adetalhouet89@gmail.com>
Wed, 5 Sep 2018 13:18:22 +0000 (09:18 -0400)
committerAlexis de Talhouët <adetalhouet89@gmail.com>
Wed, 5 Sep 2018 17:12:34 +0000 (13:12 -0400)
Change-Id: I65c34d1a059c12ec2c0fd7e76f0119571e175846
Issue-ID: CCSDK-341
Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
netbox-client/provider/src/main/java/org/onap/ccsdk/sli/adaptors/netbox/impl/NetboxClientImpl.java
netbox-client/provider/src/test/java/org/onap/ccsdk/sli/adaptors/netbox/impl/NetboxClientImplTest.java

index e7b5284..b54a35b 100644 (file)
@@ -64,7 +64,7 @@ public class NetboxClientImpl implements NetboxClient {
 
     private static final String ASSIGN_IP_SQL_STATEMENT =
         "INSERT INTO IPAM_IP_ASSIGNEMENT (service_instance_id, vf_module_id, prefix_id, ip_address_id, ip_address, ip_status, ip_response_json, external_key) \n"
-            + "VALUES (?, ?, ?, ?, ?, ?, ?)";
+            + "VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
     private static final String UNASSIGN_IP_SQL_STATEMENT =
         "UPDATE IPAM_IP_ASSIGNEMENT SET ip_status = ? WHERE service_instance_id = ? AND external_key = ?";
     private static final String GET_IP_ADDRESS_ID_SQL_STATEMENT =
@@ -169,7 +169,11 @@ public class NetboxClientImpl implements NetboxClient {
             serviceInstanceId,
             externalKey);
         try (CachedRowSet row = dbLibService.getData(GET_IP_ADDRESS_ID_SQL_STATEMENT, args, null)) {
-            ipAddressId = row.getString("ip_address_id");
+            if (row.next()) {
+                ipAddressId = row.getString("ip_address_id");
+            } else {
+                throw new SQLException("Data not found.");
+            }
         } catch (SQLException e) {
             LOG.error(SQL_EXCEPTION_MESSAGE, e);
             return QueryStatus.FAILURE;
index bc81f0b..624a190 100644 (file)
@@ -147,6 +147,7 @@ public class NetboxClientImplTest {
 
         CachedRowSet crs = mock(CachedRowSet.class);
         doReturn("3").when(crs).getString(eq("ip_address_id"));
+        doReturn(true).when(crs).next();
         doReturn(crs).when(dbLib).getData(anyString(), any(ArrayList.class), eq(null));
 
         QueryStatus status = netboxClientMock
@@ -164,6 +165,7 @@ public class NetboxClientImplTest {
 
         CachedRowSet crs = mock(CachedRowSet.class);
         doReturn("3").when(crs).getString(eq("ip_address_id"));
+        doReturn(true).when(crs).next();
         doReturn(crs).when(dbLib).getData(anyString(), any(ArrayList.class), eq(null));
 
         QueryStatus status = netboxClient.unassignIpAddress(params, svcLogicContext);
@@ -181,6 +183,7 @@ public class NetboxClientImplTest {
         givenThat(delete(urlEqualTo(expectedUrl)).willReturn(created().withBody(response)));
 
         CachedRowSet crs = mock(CachedRowSet.class);
+        doReturn(true).when(crs).next();
         doReturn("3").when(crs).getString(eq("ip_address_id"));
         doReturn(crs).when(dbLib).getData(anyString(), any(ArrayList.class), eq(null));
 
@@ -201,6 +204,7 @@ public class NetboxClientImplTest {
 
         CachedRowSet crs = mock(CachedRowSet.class);
         doReturn("3").when(crs).getString(eq("ip_address_id"));
+        doReturn(true).when(crs).next();
         doReturn(crs).when(dbLib).getData(anyString(), any(ArrayList.class), eq(null));
 
         QueryStatus status = netboxClient.unassignIpAddress(params, svcLogicContext);