aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/test/java/org/onap/vid/services/PortDetailsTranslatorTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'vid-app-common/src/test/java/org/onap/vid/services/PortDetailsTranslatorTest.java')
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/PortDetailsTranslatorTest.java261
1 files changed, 114 insertions, 147 deletions
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/PortDetailsTranslatorTest.java b/vid-app-common/src/test/java/org/onap/vid/services/PortDetailsTranslatorTest.java
index cb9eb93d0..004977347 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/PortDetailsTranslatorTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/PortDetailsTranslatorTest.java
@@ -1,19 +1,12 @@
package org.onap.vid.services;
+import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.mockito.InjectMocks;
-import org.mockito.Mock;
-import org.mockito.MockitoAnnotations;
-import org.onap.vid.aai.model.AaiGetPortMirroringSourcePorts;
+import org.onap.vid.aai.model.CustomQuerySimpleResult;
import org.onap.vid.aai.model.PortDetailsTranslator;
import org.onap.vid.aai.model.RelatedTo;
import org.onap.vid.aai.model.SimpleResult;
-import org.onap.vid.properties.Features;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
-import org.togglz.core.manager.FeatureManager;
import java.io.IOException;
import java.util.List;
@@ -25,49 +18,38 @@ import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.collection.IsEmptyCollection.empty;
-import static org.mockito.Mockito.when;
public class PortDetailsTranslatorTest {
private static final ObjectMapper om = new ObjectMapper();
- @InjectMocks
private PortDetailsTranslator portDetailsTranslator = new PortDetailsTranslator();
- @Mock
- private FeatureManager featureManager;
-
- @BeforeMethod
- public void initMocks() throws Exception {
- MockitoAnnotations.initMocks(this);
- when(featureManager.isActive(Features.FLAG_ADVANCED_PORTS_FILTER)).thenReturn(true);
- }
-
@Test
public void extractPortDetailsFromProperties_givenValidAaiResponse() throws IOException {
- final String aaiResponse = "{\n" +
- " \"results\": [\n" +
- " {\n" +
- " \"id\": \"4876980240\",\n" +
- " \"node-type\": \"l-interface\",\n" +
- " \"url\": \"/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/att-aic/rdm5b/tenants/tenant/460f35aeb53542dc9f77105066483e83/vservers/vserver/15e46e2f-4b98-4e06-9644-f0e6e35cc79a/l-interfaces/l-interface/zrdm5bfprbVLBA005-vlbagent_aff_int_pktmirror_1_port-dr5jhyxva5ib\",\n" +
- " \"properties\": {\n" +
- " \"interface-name\": \"zrdm5bfprbVLBA005-vlbagent_aff_int_pktmirror_1_port-dr5jhyxva5ib\",\n" +
- " \"selflink\": \"https://network-aic.rdm5b.cci.att.com:9696/v2.0/ports/6de7bf87-6faa-4984-9492-18d1188b3d4a\",\n" +
- " \"interface-id\": \"6de7bf87-6faa-4984-9492-18d1188b3d4a\",\n" +
- " \"macaddr\": \"02:6d:e7:bf:87:6f\",\n" +
- " \"network-name\": \"APP-C-24595-D-T001-vprobe_int_pktmirror_net_1\",\n" +
- " \"is-port-mirrored\": false,\n" +
- " \"resource-version\": \"1519383879190\",\n" +
- " \"in-maint\": false,\n" +
- " \"is-ip-unnumbered\": false\n" +
- " }\n" +
- " }\n" +
- " ]\n" +
+ final String aaiResponse = "{" +
+ " \"results\": [" +
+ " {" +
+ " \"id\": \"4876980240\"," +
+ " \"node-type\": \"l-interface\"," +
+ " \"url\": \"/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/att-aic/rdm5b/tenants/tenant/460f35aeb53542dc9f77105066483e83/vservers/vserver/15e46e2f-4b98-4e06-9644-f0e6e35cc79a/l-interfaces/l-interface/zrdm5bfprbVLBA005-vlbagent_aff_int_pktmirror_1_port-dr5jhyxva5ib\"," +
+ " \"properties\": {" +
+ " \"interface-name\": \"zrdm5bfprbVLBA005-vlbagent_aff_int_pktmirror_1_port-dr5jhyxva5ib\"," +
+ " \"selflink\": \"https://network-aic.rdm5b.cci.att.com:9696/v2.0/ports/6de7bf87-6faa-4984-9492-18d1188b3d4a\"," +
+ " \"interface-id\": \"6de7bf87-6faa-4984-9492-18d1188b3d4a\"," +
+ " \"macaddr\": \"02:6d:e7:bf:87:6f\"," +
+ " \"network-name\": \"APP-C-24595-D-T001-vprobe_int_pktmirror_net_1\"," +
+ " \"is-port-mirrored\": false," +
+ " \"resource-version\": \"1519383879190\"," +
+ " \"in-maint\": false," +
+ " \"is-ip-unnumbered\": false" +
+ " }" +
+ " }" +
+ " ]" +
"}";
- AaiGetPortMirroringSourcePorts aaiGetPortMirroringSourcePorts = om.readValue(aaiResponse, AaiGetPortMirroringSourcePorts.class);
+ CustomQuerySimpleResult aaiGetPortMirroringSourcePorts = om.readValue(aaiResponse, CustomQuerySimpleResult.class);
PortDetailsTranslator.PortDetails portDetails = PortDetailsTranslator.extractPortDetailsFromProperties(aaiGetPortMirroringSourcePorts.getResults().get(0).getProperties(), aaiResponse);
@@ -82,29 +64,29 @@ public class PortDetailsTranslatorTest {
@Test
public void extractPortDetailsFromProperties_givenAaiResponseWithInstanceNameNull_yieldException() throws IOException {
- final String aaiResponse = "{\n" +
- " \"results\": [\n" +
- " {\n" +
- " \"id\": \"4876980240\",\n" +
- " \"node-type\": \"l-interface\",\n" +
- " \"url\": \"/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/att-aic/rdm5b/tenants/tenant/460f35aeb53542dc9f77105066483e83/vservers/vserver/15e46e2f-4b98-4e06-9644-f0e6e35cc79a/l-interfaces/l-interface/zrdm5bfprbVLBA005-vlbagent_aff_int_pktmirror_1_port-dr5jhyxva5ib\",\n" +
- " \"properties\": {\n" +
- " \"interface-name\": null,\n" +
- " \"selflink\": \"https://network-aic.rdm5b.cci.att.com:9696/v2.0/ports/6de7bf87-6faa-4984-9492-18d1188b3d4a\",\n" +
- " \"interface-id\": \"6de7bf87-6faa-4984-9492-18d1188b3d4a\",\n" +
- " \"macaddr\": \"02:6d:e7:bf:87:6f\",\n" +
- " \"network-name\": \"APP-C-24595-D-T001-vprobe_int_pktmirror_net_1\",\n" +
- " \"is-port-mirrored\": false,\n" +
- " \"resource-version\": \"1519383879190\",\n" +
- " \"in-maint\": false,\n" +
- " \"is-ip-unnumbered\": false\n" +
- " }\n" +
- " }\n" +
- " ]\n" +
+ final String aaiResponse = "{" +
+ " \"results\": [" +
+ " {" +
+ " \"id\": \"4876980240\"," +
+ " \"node-type\": \"l-interface\"," +
+ " \"url\": \"/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/att-aic/rdm5b/tenants/tenant/460f35aeb53542dc9f77105066483e83/vservers/vserver/15e46e2f-4b98-4e06-9644-f0e6e35cc79a/l-interfaces/l-interface/zrdm5bfprbVLBA005-vlbagent_aff_int_pktmirror_1_port-dr5jhyxva5ib\"," +
+ " \"properties\": {" +
+ " \"interface-name\": null," +
+ " \"selflink\": \"https://network-aic.rdm5b.cci.att.com:9696/v2.0/ports/6de7bf87-6faa-4984-9492-18d1188b3d4a\"," +
+ " \"interface-id\": \"6de7bf87-6faa-4984-9492-18d1188b3d4a\"," +
+ " \"macaddr\": \"02:6d:e7:bf:87:6f\"," +
+ " \"network-name\": \"APP-C-24595-D-T001-vprobe_int_pktmirror_net_1\"," +
+ " \"is-port-mirrored\": false," +
+ " \"resource-version\": \"1519383879190\"," +
+ " \"in-maint\": false," +
+ " \"is-ip-unnumbered\": false" +
+ " }" +
+ " }" +
+ " ]" +
"}";
- AaiGetPortMirroringSourcePorts aaiGetPortMirroringSourcePorts = om.readValue(aaiResponse, AaiGetPortMirroringSourcePorts.class);
- PortDetailsTranslator.PortDetails portDetails = PortDetailsTranslator.extractPortDetailsFromProperties(aaiGetPortMirroringSourcePorts.getResults().get(0).getProperties(),aaiResponse);
+ CustomQuerySimpleResult aaiGetPortMirroringSourcePorts = om.readValue(aaiResponse, CustomQuerySimpleResult.class);
+ PortDetailsTranslator.PortDetails portDetails = PortDetailsTranslator.extractPortDetailsFromProperties(aaiGetPortMirroringSourcePorts.getResults().get(0).getProperties(), aaiResponse);
assertThat(portDetails, is(instanceOf(PortDetailsTranslator.PortDetailsError.class)));
@@ -115,29 +97,29 @@ public class PortDetailsTranslatorTest {
@Test
public void extractPortDetailsFromProperties_givenAaiResponseWithInstanceIdNull_yieldException() throws IOException {
- final String aaiResponse = "{\n" +
- " \"results\": [\n" +
- " {\n" +
- " \"id\": \"4876980240\",\n" +
- " \"node-type\": \"l-interface\",\n" +
- " \"url\": \"/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/att-aic/rdm5b/tenants/tenant/460f35aeb53542dc9f77105066483e83/vservers/vserver/15e46e2f-4b98-4e06-9644-f0e6e35cc79a/l-interfaces/l-interface/zrdm5bfprbVLBA005-vlbagent_aff_int_pktmirror_1_port-dr5jhyxva5ib\",\n" +
- " \"properties\": {\n" +
- " \"interface-name\": \"zrdm5bfprbVLBA005-vlbagent_aff_int_pktmirror_1_port-dr5jhyxva5ib\",\n" +
- " \"selflink\": \"https://network-aic.rdm5b.cci.att.com:9696/v2.0/ports/6de7bf87-6faa-4984-9492-18d1188b3d4a\",\n" +
- " \"interface-id\": null,\n" +
- " \"macaddr\": \"02:6d:e7:bf:87:6f\",\n" +
- " \"network-name\": \"APP-C-24595-D-T001-vprobe_int_pktmirror_net_1\",\n" +
- " \"is-port-mirrored\": false,\n" +
- " \"resource-version\": \"1519383879190\",\n" +
- " \"in-maint\": false,\n" +
- " \"is-ip-unnumbered\": false\n" +
- " }\n" +
- " }\n" +
- " ]\n" +
+ final String aaiResponse = "{" +
+ " \"results\": [" +
+ " {" +
+ " \"id\": \"4876980240\"," +
+ " \"node-type\": \"l-interface\"," +
+ " \"url\": \"/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/att-aic/rdm5b/tenants/tenant/460f35aeb53542dc9f77105066483e83/vservers/vserver/15e46e2f-4b98-4e06-9644-f0e6e35cc79a/l-interfaces/l-interface/zrdm5bfprbVLBA005-vlbagent_aff_int_pktmirror_1_port-dr5jhyxva5ib\"," +
+ " \"properties\": {" +
+ " \"interface-name\": \"zrdm5bfprbVLBA005-vlbagent_aff_int_pktmirror_1_port-dr5jhyxva5ib\"," +
+ " \"selflink\": \"https://network-aic.rdm5b.cci.att.com:9696/v2.0/ports/6de7bf87-6faa-4984-9492-18d1188b3d4a\"," +
+ " \"interface-id\": null," +
+ " \"macaddr\": \"02:6d:e7:bf:87:6f\"," +
+ " \"network-name\": \"APP-C-24595-D-T001-vprobe_int_pktmirror_net_1\"," +
+ " \"is-port-mirrored\": false," +
+ " \"resource-version\": \"1519383879190\"," +
+ " \"in-maint\": false," +
+ " \"is-ip-unnumbered\": false" +
+ " }" +
+ " }" +
+ " ]" +
"}";
- AaiGetPortMirroringSourcePorts aaiGetPortMirroringSourcePorts = om.readValue(aaiResponse, AaiGetPortMirroringSourcePorts.class);
- PortDetailsTranslator.PortDetails portDetails = PortDetailsTranslator.extractPortDetailsFromProperties(aaiGetPortMirroringSourcePorts.getResults().get(0).getProperties(),aaiResponse);
+ CustomQuerySimpleResult aaiGetPortMirroringSourcePorts = om.readValue(aaiResponse, CustomQuerySimpleResult.class);
+ PortDetailsTranslator.PortDetails portDetails = PortDetailsTranslator.extractPortDetailsFromProperties(aaiGetPortMirroringSourcePorts.getResults().get(0).getProperties(), aaiResponse);
assertThat(portDetails, is(instanceOf(PortDetailsTranslator.PortDetailsError.class)));
@@ -148,29 +130,29 @@ public class PortDetailsTranslatorTest {
@Test
public void extractPortDetailsFromProperties_givenAaiResponseWithEmptyInstanceId_yieldException() throws IOException {
- final String aaiResponse = "{\n" +
- " \"results\": [\n" +
- " {\n" +
- " \"id\": \"4876980240\",\n" +
- " \"node-type\": \"l-interface\",\n" +
- " \"url\": \"/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/att-aic/rdm5b/tenants/tenant/460f35aeb53542dc9f77105066483e83/vservers/vserver/15e46e2f-4b98-4e06-9644-f0e6e35cc79a/l-interfaces/l-interface/zrdm5bfprbVLBA005-vlbagent_aff_int_pktmirror_1_port-dr5jhyxva5ib\",\n" +
- " \"properties\": {\n" +
- " \"interface-name\": \"\",\n" +
- " \"selflink\": \"https://network-aic.rdm5b.cci.att.com:9696/v2.0/ports/6de7bf87-6faa-4984-9492-18d1188b3d4a\",\n" +
- " \"interface-id\": \"6de7bf87-6faa-4984-9492-18d1188b3d4a\",\n" +
- " \"macaddr\": \"02:6d:e7:bf:87:6f\",\n" +
- " \"network-name\": \"APP-C-24595-D-T001-vprobe_int_pktmirror_net_1\",\n" +
- " \"is-port-mirrored\": false,\n" +
- " \"resource-version\": \"1519383879190\",\n" +
- " \"in-maint\": false,\n" +
- " \"is-ip-unnumbered\": false\n" +
- " }\n" +
- " }\n" +
- " ]\n" +
+ final String aaiResponse = "{" +
+ " \"results\": [" +
+ " {" +
+ " \"id\": \"4876980240\"," +
+ " \"node-type\": \"l-interface\"," +
+ " \"url\": \"/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/att-aic/rdm5b/tenants/tenant/460f35aeb53542dc9f77105066483e83/vservers/vserver/15e46e2f-4b98-4e06-9644-f0e6e35cc79a/l-interfaces/l-interface/zrdm5bfprbVLBA005-vlbagent_aff_int_pktmirror_1_port-dr5jhyxva5ib\"," +
+ " \"properties\": {" +
+ " \"interface-name\": \"\"," +
+ " \"selflink\": \"https://network-aic.rdm5b.cci.att.com:9696/v2.0/ports/6de7bf87-6faa-4984-9492-18d1188b3d4a\"," +
+ " \"interface-id\": \"6de7bf87-6faa-4984-9492-18d1188b3d4a\"," +
+ " \"macaddr\": \"02:6d:e7:bf:87:6f\"," +
+ " \"network-name\": \"APP-C-24595-D-T001-vprobe_int_pktmirror_net_1\"," +
+ " \"is-port-mirrored\": false," +
+ " \"resource-version\": \"1519383879190\"," +
+ " \"in-maint\": false," +
+ " \"is-ip-unnumbered\": false" +
+ " }" +
+ " }" +
+ " ]" +
"}";
- AaiGetPortMirroringSourcePorts aaiGetPortMirroringSourcePorts = om.readValue(aaiResponse, AaiGetPortMirroringSourcePorts.class);
- PortDetailsTranslator.PortDetails portDetails = PortDetailsTranslator.extractPortDetailsFromProperties(aaiGetPortMirroringSourcePorts.getResults().get(0).getProperties(),aaiResponse);
+ CustomQuerySimpleResult aaiGetPortMirroringSourcePorts = om.readValue(aaiResponse, CustomQuerySimpleResult.class);
+ PortDetailsTranslator.PortDetails portDetails = PortDetailsTranslator.extractPortDetailsFromProperties(aaiGetPortMirroringSourcePorts.getResults().get(0).getProperties(), aaiResponse);
assertThat(portDetails, is(instanceOf(PortDetailsTranslator.PortDetailsError.class)));
@@ -181,29 +163,29 @@ public class PortDetailsTranslatorTest {
@Test
public void extractPortDetailsFromProperties_givenAaiResponseWithIsPortMirroredNull_yieldException() throws IOException {
- final String aaiResponse = "{\n" +
- " \"results\": [\n" +
- " {\n" +
- " \"id\": \"4876980240\",\n" +
- " \"node-type\": \"l-interface\",\n" +
- " \"url\": \"/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/att-aic/rdm5b/tenants/tenant/460f35aeb53542dc9f77105066483e83/vservers/vserver/15e46e2f-4b98-4e06-9644-f0e6e35cc79a/l-interfaces/l-interface/zrdm5bfprbVLBA005-vlbagent_aff_int_pktmirror_1_port-dr5jhyxva5ib\",\n" +
- " \"properties\": {\n" +
- " \"interface-name\": \"zrdm5bfprbVLBA005-vlbagent_aff_int_pktmirror_1_port-dr5jhyxva5ib\",\n" +
- " \"selflink\": \"https://network-aic.rdm5b.cci.att.com:9696/v2.0/ports/6de7bf87-6faa-4984-9492-18d1188b3d4a\",\n" +
- " \"interface-id\": \"6de7bf87-6faa-4984-9492-18d1188b3d4a\",\n" +
- " \"macaddr\": \"02:6d:e7:bf:87:6f\",\n" +
- " \"network-name\": \"APP-C-24595-D-T001-vprobe_int_pktmirror_net_1\",\n" +
- " \"is-port-mirrored\": null,\n" +
- " \"resource-version\": \"1519383879190\",\n" +
- " \"in-maint\": false,\n" +
- " \"is-ip-unnumbered\": false\n" +
- " }\n" +
- " }\n" +
- " ]\n" +
+ final String aaiResponse = "{" +
+ " \"results\": [" +
+ " {" +
+ " \"id\": \"4876980240\"," +
+ " \"node-type\": \"l-interface\"," +
+ " \"url\": \"/aai/v12/cloud-infrastructure/cloud-regions/cloud-region/att-aic/rdm5b/tenants/tenant/460f35aeb53542dc9f77105066483e83/vservers/vserver/15e46e2f-4b98-4e06-9644-f0e6e35cc79a/l-interfaces/l-interface/zrdm5bfprbVLBA005-vlbagent_aff_int_pktmirror_1_port-dr5jhyxva5ib\"," +
+ " \"properties\": {" +
+ " \"interface-name\": \"zrdm5bfprbVLBA005-vlbagent_aff_int_pktmirror_1_port-dr5jhyxva5ib\"," +
+ " \"selflink\": \"https://network-aic.rdm5b.cci.att.com:9696/v2.0/ports/6de7bf87-6faa-4984-9492-18d1188b3d4a\"," +
+ " \"interface-id\": \"6de7bf87-6faa-4984-9492-18d1188b3d4a\"," +
+ " \"macaddr\": \"02:6d:e7:bf:87:6f\"," +
+ " \"network-name\": \"APP-C-24595-D-T001-vprobe_int_pktmirror_net_1\"," +
+ " \"is-port-mirrored\": null," +
+ " \"resource-version\": \"1519383879190\"," +
+ " \"in-maint\": false," +
+ " \"is-ip-unnumbered\": false" +
+ " }" +
+ " }" +
+ " ]" +
"}";
- AaiGetPortMirroringSourcePorts aaiGetPortMirroringSourcePorts = om.readValue(aaiResponse, AaiGetPortMirroringSourcePorts.class);
- PortDetailsTranslator.PortDetails portDetails = PortDetailsTranslator.extractPortDetailsFromProperties(aaiGetPortMirroringSourcePorts.getResults().get(0).getProperties(),aaiResponse);
+ CustomQuerySimpleResult aaiGetPortMirroringSourcePorts = om.readValue(aaiResponse, CustomQuerySimpleResult.class);
+ PortDetailsTranslator.PortDetails portDetails = PortDetailsTranslator.extractPortDetailsFromProperties(aaiGetPortMirroringSourcePorts.getResults().get(0).getProperties(), aaiResponse);
assertThat(portDetails, is(instanceOf(PortDetailsTranslator.PortDetailsError.class)));
@@ -221,17 +203,8 @@ public class PortDetailsTranslatorTest {
assertThat("List size if different than expected", result, is(empty()));
}
- @DataProvider
- public static Object[][] trueAndFalse() {
- return new Object[][]{
- { Boolean.TRUE }, { Boolean.FALSE }
- };
- }
-
- @Test(dataProvider = "trueAndFalse")
- public void getFilteredPortList_givenFeatureFlagIsOff_returnAllLInterfaces(Boolean advancedPortsFilterFlag) throws IOException {
- when(featureManager.isActive(Features.FLAG_ADVANCED_PORTS_FILTER)).thenReturn(advancedPortsFilterFlag);
-
+ @Test
+ public void getFilteredPortList_givenFeatureFlagIsOff_returnAllLInterfaces() {
final String relationshipLabelSource = "org.onap.relationships.inventory.Source";
final String nodeTypeLInterface = "l-interface";
@@ -258,22 +231,16 @@ public class PortDetailsTranslatorTest {
List<SimpleResult> result = portDetailsTranslator.getFilteredPortList(input);
- if (advancedPortsFilterFlag) {
- assertThat("List should contain all l-interfaces with a related source", result, containsInAnyOrder(
- lInterfaceWithSource, lInterfaceWithSourceAndMore,
- lInterfaceWithTwoSources));
- } else {
- assertThat("List should contain all l-interfaces", result, containsInAnyOrder(
- lInterfaceWithSource, lInterfaceWithoutSource,
- lInterfaceWithoutRelations, lInterfaceWithSourceAndMore,
- lInterfaceWithTwoSources));
- }
+ assertThat("List should contain all l-interfaces with a related source", result, containsInAnyOrder(
+ lInterfaceWithSource, lInterfaceWithSourceAndMore,
+ lInterfaceWithTwoSources));
+
}
private SimpleResult buildSimpleResult(String nodeType, String... relationshipLabels) {
SimpleResult simpleResult = new SimpleResult();
- simpleResult.setNodeType(nodeType);
- simpleResult.setRelatedTo(Stream.of(relationshipLabels).map(label ->
+ simpleResult.setJsonNodeType(nodeType);
+ simpleResult.setJsonRelatedTo(Stream.of(relationshipLabels).map(label ->
new RelatedTo("my foo id", label, "logical-link", "foo url"))
.collect(Collectors.toList())
);