aboutsummaryrefslogtreecommitdiffstats
path: root/netbox-client/provider/src/test/java
diff options
context:
space:
mode:
authorAlexis de Talhouët <adetalhouet89@gmail.com>2018-08-20 15:27:59 -0400
committerAlexis de Talhouët <adetalhouet89@gmail.com>2018-08-24 08:42:14 -0400
commite864171d3d4f378a150466161f7162070368e554 (patch)
tree41bc53f154884b04b47d0db366984be55502307a /netbox-client/provider/src/test/java
parente2b2138f05e9eaf3eb89f9a65859433cf79b9960 (diff)
Add DB update support for IPAM interaction
For assign and unassign scenario, we need to interact with the SDNC DB in order to cache the IP Address information used for a given ServiceInstance / VfModule. Change-Id: Id349338216d12d2dc9efd76cd672b5cc9fdc6192 Issue-ID: CCSDK-462 Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
Diffstat (limited to 'netbox-client/provider/src/test/java')
-rw-r--r--netbox-client/provider/src/test/java/org/onap/ccsdk/sli/adaptors/netbox/impl/NetboxClientImplTest.java34
1 files changed, 25 insertions, 9 deletions
diff --git a/netbox-client/provider/src/test/java/org/onap/ccsdk/sli/adaptors/netbox/impl/NetboxClientImplTest.java b/netbox-client/provider/src/test/java/org/onap/ccsdk/sli/adaptors/netbox/impl/NetboxClientImplTest.java
index 19b178c9..f1eda736 100644
--- a/netbox-client/provider/src/test/java/org/onap/ccsdk/sli/adaptors/netbox/impl/NetboxClientImplTest.java
+++ b/netbox-client/provider/src/test/java/org/onap/ccsdk/sli/adaptors/netbox/impl/NetboxClientImplTest.java
@@ -30,6 +30,9 @@ import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMoc
import static org.apache.http.HttpHeaders.ACCEPT;
import static org.apache.http.HttpHeaders.AUTHORIZATION;
import static org.apache.http.HttpHeaders.CONTENT_TYPE;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
@@ -41,6 +44,9 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.charset.StandardCharsets;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.UUID;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
@@ -50,11 +56,14 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.onap.ccsdk.sli.adaptors.netbox.api.IpamException;
import org.onap.ccsdk.sli.adaptors.netbox.model.IPAddress;
import org.onap.ccsdk.sli.adaptors.netbox.model.Prefix;
import org.onap.ccsdk.sli.adaptors.netbox.model.Status.Values;
+import org.onap.ccsdk.sli.core.dblib.DbLibService;
@RunWith(MockitoJUnitRunner.class)
public class NetboxClientImplTest {
@@ -64,7 +73,12 @@ public class NetboxClientImplTest {
@Rule
public WireMockRule wm = new WireMockRule(wireMockConfig().dynamicPort());
+ @Mock
+ private DbLibService dbLib;
+
private String token = "token";
+ private String serviceInstanceId = UUID.randomUUID().toString();
+ private String vfModuleId = UUID.randomUUID().toString();
private NetboxHttpClient httpClient;
private NetboxClientImpl netboxClient;
@@ -76,7 +90,7 @@ public class NetboxClientImplTest {
httpClient = new NetboxHttpClient(baseUrl, token);
httpClient.init();
- netboxClient = new NetboxClientImpl(httpClient);
+ netboxClient = new NetboxClientImpl(httpClient, dbLib);
wm.addMockServiceRequestListener(
(request, response) -> {
@@ -93,11 +107,11 @@ public class NetboxClientImplTest {
}
@Test
- public void nextAvailableIpInPrefixTestNoId() {
+ public void nextAvailableIpInPrefixTestNoId() throws SQLException {
Prefix prefix = mock(Prefix.class);
doReturn(null).when(prefix).getId();
try {
- netboxClient.assign(prefix);
+ netboxClient.assign(prefix, serviceInstanceId, vfModuleId);
} catch (IpamException e) {
Assert.assertEquals("Id must be set", e.getMessage());
return;
@@ -106,7 +120,7 @@ public class NetboxClientImplTest {
}
@Test
- public void nextAvailableIpInPrefixTest() throws IOException, IpamException {
+ public void nextAvailableIpInPrefixTest() throws IOException, IpamException, SQLException {
Integer id = 3;
Prefix prefix = mock(Prefix.class);
doReturn(id).when(prefix).getId();
@@ -117,16 +131,17 @@ public class NetboxClientImplTest {
String expectedUrl = "/api/ipam/prefixes/" + id + "/available-ips/";
givenThat(post(urlEqualTo(expectedUrl)).willReturn(created().withBody(response)));
- netboxClient.assign(prefix);
+ netboxClient.assign(prefix, serviceInstanceId, vfModuleId);
verify(postRequestedFor(urlEqualTo(expectedUrl))
.withHeader(ACCEPT, equalTo(APPLICATION_JSON))
.withHeader(CONTENT_TYPE, equalTo(APPLICATION_JSON))
.withHeader(AUTHORIZATION, equalTo("Token " + token)));
+ Mockito.verify(dbLib).writeData(anyString(), any(ArrayList.class), eq((null)));
}
@Test
- public void deleteIpTestError500() {
+ public void deleteIpTestError500() throws SQLException {
Integer id = 3;
IPAddress ipAddress = mock(IPAddress.class);
doReturn(id).when(ipAddress).getId();
@@ -134,7 +149,7 @@ public class NetboxClientImplTest {
String expectedUrl = "/api/ipam/ip-addresses/" + id + "/";
givenThat(delete(urlEqualTo(expectedUrl)).willReturn(serverError()));
try {
- netboxClient.unassign(ipAddress);
+ netboxClient.unassign(ipAddress, serviceInstanceId, vfModuleId);
} catch (IpamException e) {
Assert.assertEquals(IllegalStateException.class, e.getCause().getClass());
Assert.assertTrue(e.getMessage().contains(
@@ -145,18 +160,19 @@ public class NetboxClientImplTest {
}
@Test
- public void deleteIpTest() throws IpamException {
+ public void deleteIpTest() throws IpamException, SQLException {
Integer id = 3;
IPAddress ipAddress = mock(IPAddress.class);
doReturn(id).when(ipAddress).getId();
String expectedUrl = "/api/ipam/ip-addresses/" + id + "/";
givenThat(delete(urlEqualTo(expectedUrl)).willReturn(ok()));
- netboxClient.unassign(ipAddress);
+ netboxClient.unassign(ipAddress, serviceInstanceId, vfModuleId);
verify(deleteRequestedFor(urlEqualTo(expectedUrl))
.withHeader(ACCEPT, equalTo(APPLICATION_JSON))
.withHeader(CONTENT_TYPE, equalTo(APPLICATION_JSON))
.withHeader(AUTHORIZATION, equalTo("Token " + token)));
+ Mockito.verify(dbLib).writeData(anyString(), any(ArrayList.class), eq((null)));
}