aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEylon Malin <eylon.malin@intl.att.com>2019-09-01 16:24:41 +0300
committerEylon Malin <eylon.malin@intl.att.com>2019-09-01 16:59:37 +0300
commit03f54a0b7de599e0a012ff6d35d0e74e20ca36c2 (patch)
tree3e70969a2142fc7fe5153cab3adcc451e22b0a9f
parente6c30425575cd76a3955b03ab389150ed74fbb1d (diff)
add getNewestModelVersionByInvariant to controller and service
Also add testGetActiveNetworkList UT Issue-ID: VID-378 Signed-off-by: Eylon Malin <eylon.malin@intl.att.com> Change-Id: I97c2ae029272aba915d5f9699bccff0eb9d49329 Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java7
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AaiService.java3
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java5
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/AaiController2Test.java108
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java8
5 files changed, 131 insertions, 0 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java
index d7d2f85db..e0d211c24 100644
--- a/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java
+++ b/vid-app-common/src/main/java/org/onap/vid/controller/AaiController2.java
@@ -24,6 +24,7 @@ import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;
import org.onap.vid.aai.AaiClientInterface;
import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
+import org.onap.vid.aai.model.ModelVer;
import org.onap.vid.aai.model.Permissions;
import org.onap.vid.model.aaiTree.Network;
import org.onap.vid.model.aaiTree.RelatedVnf;
@@ -116,4 +117,10 @@ public class AaiController2 extends VidRestrictedBaseController {
.filter(network -> StringUtils.equalsIgnoreCase(network.getOrchStatus(), "active"))
.collect(Collectors.toList());
}
+
+ @RequestMapping(value = "/aai_get_newest_model_version_by_invariant/{invariantId}",
+ method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
+ public ModelVer getNewestModelVersionByInvariant(@PathVariable("invariantId") String invariantId) {
+ return aaiService.getNewestModelVersionByInvariantId(invariantId);
+ }
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AaiService.java b/vid-app-common/src/main/java/org/onap/vid/services/AaiService.java
index 31fbe65d8..bc26b5eb0 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/AaiService.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/AaiService.java
@@ -32,6 +32,7 @@ import org.onap.vid.aai.model.AaiGetInstanceGroupsByCloudRegion;
import org.onap.vid.aai.model.AaiGetOperationalEnvironments.OperationalEnvironmentList;
import org.onap.vid.aai.model.AaiGetPnfs.Pnf;
import org.onap.vid.aai.model.AaiGetTenatns.GetTenantsResponse;
+import org.onap.vid.aai.model.ModelVer;
import org.onap.vid.aai.model.PortDetailsTranslator;
import org.onap.vid.asdc.beans.Service;
import org.onap.vid.model.SubscriberList;
@@ -99,4 +100,6 @@ public interface AaiService {
List<VpnBinding> getVpnListByVpnType(String vpnType);
List<Network> getL3NetworksByCloudRegion(String cloudRegionId, String tenantId, String networkRole);
+
+ ModelVer getNewestModelVersionByInvariantId(String modelInvariantId);
}
diff --git a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java
index b50dcc3b5..b6404fa68 100644
--- a/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java
+++ b/vid-app-common/src/main/java/org/onap/vid/services/AaiServiceImpl.java
@@ -702,4 +702,9 @@ public class AaiServiceImpl implements AaiService {
return "{\"start\":\"/cloud-infrastructure/cloud-regions/cloud-region/" + cloudOwner + "/" + cloudRegionId + "\"," +
"\"query\":\"query/l3-networks-by-cloud-region?tenantId=" + tenantId + networkRolePart + "\"}";
}
+
+ @Override
+ public ModelVer getNewestModelVersionByInvariantId(String modelInvariantId){
+ return aaiClient.getLatestVersionByInvariantId(modelInvariantId);
+ }
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/AaiController2Test.java b/vid-app-common/src/test/java/org/onap/vid/controller/AaiController2Test.java
new file mode 100644
index 000000000..3a66a8e77
--- /dev/null
+++ b/vid-app-common/src/test/java/org/onap/vid/controller/AaiController2Test.java
@@ -0,0 +1,108 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 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=========================================================
+ */
+
+package org.onap.vid.controller;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.testng.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Assert;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.onap.vid.aai.AaiClientInterface;
+import org.onap.vid.aai.model.ModelVer;
+import org.onap.vid.model.aaiTree.Network;
+import org.onap.vid.roles.RoleProvider;
+import org.onap.vid.services.AaiService;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+public class AaiController2Test {
+
+ @InjectMocks
+ private AaiController2 aaiController;
+
+ @Mock
+ private AaiService aaiService;
+
+ @Mock
+ private RoleProvider roleProvider;
+
+ @Mock
+ private AaiClientInterface aaiClientInterface;
+
+ @BeforeClass
+ public void initMocks() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testGetActiveNetworkList(){
+
+ Network expected1 = mockNetwork("name6", true, "Active");
+ Network expected2 = mockNetwork("name6", true, "Active");
+
+ List<Network> rawNetworks = new ArrayList<>();
+ rawNetworks.add(mockNetwork("", true, "Active"));
+ rawNetworks.add(mockNetwork(null, true, "Active"));
+ rawNetworks.add(mockNetwork("name", false, "Active"));
+ rawNetworks.add(mockNetwork("name2", true, "Created"));
+ rawNetworks.add(mockNetwork("name3", true, null));
+ rawNetworks.add(mockNetwork("name4", true, ""));
+ rawNetworks.add(expected1);
+ rawNetworks.add(expected2);
+
+ when(aaiService.getL3NetworksByCloudRegion(any(), any(), any())).thenReturn(rawNetworks);
+ List<Network> networks = aaiController.getActiveNetworkList("just", "fake", "params");
+ Assert.assertEquals(2, networks.size());
+ assertThat(networks, containsInAnyOrder(expected1, expected2));
+ }
+
+ private Network mockNetwork(String name, boolean isBoundToVpn, String orchStatus) {
+ Network network = mock(Network.class);
+ when(network.getInstanceName()).thenReturn(name);
+ when(network.isBoundToVpn()).thenReturn(isBoundToVpn);
+ when(network.getOrchStatus()).thenReturn(orchStatus);
+ return network;
+ }
+
+ @Test
+ public void testGetNewestModelVersionByInvariant() {
+
+ String modelInvariantId = "model-invariant-v2.0";
+ String modelVersion ="2.0";
+ ModelVer expectedModelVer = new ModelVer();
+ expectedModelVer.setModelVersion(modelVersion);
+
+ when(aaiService.getNewestModelVersionByInvariantId(modelInvariantId)).thenReturn(expectedModelVer);
+
+ ModelVer actualModelVer = aaiController.getNewestModelVersionByInvariant(modelInvariantId);
+
+ assertEquals (actualModelVer.getModelVersion(),modelVersion);
+
+ }
+}
diff --git a/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java b/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java
index 20409d327..2eae1864f 100644
--- a/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/services/AaiServiceImplTest.java
@@ -791,4 +791,12 @@ public class AaiServiceImplTest {
subscriber.subscriberType = "type-1";
return subscriber;
}
+
+ @Test
+ public void whenGetNewestModelVersionByInvariantId_thenReturnSameValueAsAaiClient() {
+ String modelInvariantId = "123";
+ ModelVer modelVer = mock(ModelVer.class);
+ when(aaiClient.getLatestVersionByInvariantId(eq(modelInvariantId))).thenReturn(modelVer);
+ assertThat(aaiService.getNewestModelVersionByInvariantId(modelInvariantId)).isEqualTo(modelVer);
+ }
}