aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Sandler <alexey.sandler@intl.att.com>2020-01-08 16:23:27 +0200
committerAlexey Sandler <alexey.sandler@intl.att.com>2020-01-08 17:13:47 +0200
commit34196e69786be3485c5a6afdcfb41bdf548abb4b (patch)
tree7588586e4d16f117578a7be625ea6256f5432d8c
parent0d51682c8db4e9309732e5a773ba45dac66fe5fd (diff)
VidController sets isInstantiationTemplateExists on Browse SDC
Issue-ID: VID-739 Change-Id: I8dea890c8518e3c314e5371eaa982ce7550b27a5 Signed-off-by: Alexey Sandler <alexey.sandler@intl.att.com>
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/controller/VidController.java16
-rw-r--r--vid-app-common/src/test/java/org/onap/vid/controller/VidControllerTest.java62
2 files changed, 52 insertions, 26 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/controller/VidController.java b/vid-app-common/src/main/java/org/onap/vid/controller/VidController.java
index 15bc5ed7c..d257000bf 100644
--- a/vid-app-common/src/main/java/org/onap/vid/controller/VidController.java
+++ b/vid-app-common/src/main/java/org/onap/vid/controller/VidController.java
@@ -21,16 +21,19 @@
package org.onap.vid.controller;
+import java.util.Collection;
import org.onap.portalsdk.core.controller.RestrictedBaseController;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.vid.asdc.AsdcCatalogException;
import org.onap.vid.asdc.beans.SecureServices;
+import org.onap.vid.asdc.beans.Service;
import org.onap.vid.exceptions.VidServiceUnavailableException;
import org.onap.vid.model.PombaInstance.PombaRequest;
import org.onap.vid.model.ServiceModel;
import org.onap.vid.roles.Role;
import org.onap.vid.roles.RoleProvider;
import org.onap.vid.services.AaiService;
+import org.onap.vid.services.InstantiationTemplatesService;
import org.onap.vid.services.PombaService;
import org.onap.vid.services.VidService;
import org.springframework.beans.factory.annotation.Autowired;
@@ -50,14 +53,16 @@ public class VidController extends RestrictedBaseController {
private final AaiService aaiService;
private final RoleProvider roleProvider;
private final PombaService pombaService;
+ private final InstantiationTemplatesService instantiationTemplatesService;
@Autowired
public VidController(VidService vidService, AaiService aaiService, RoleProvider roleProvider,
- PombaService pombaService) {
+ PombaService pombaService, InstantiationTemplatesService instantiationTemplatesService) {
this.vidService = vidService;
this.aaiService = aaiService;
this.roleProvider = roleProvider;
this.pombaService = pombaService;
+ this.instantiationTemplatesService = instantiationTemplatesService;
}
/**
@@ -69,8 +74,15 @@ public class VidController extends RestrictedBaseController {
LOG.info("Start API for browse SDC was called");
SecureServices secureServices = new SecureServices();
List<Role> roles = roleProvider.getUserRoles(request);
- secureServices.setServices(aaiService.getServicesByDistributionStatus());
+
+ Collection<Service> servicesByDistributionStatus = aaiService.getServicesByDistributionStatus();
+
+ Collection<Service> servicesWithTemplatesIndication =
+ instantiationTemplatesService.setOnEachServiceIsTemplateExists(servicesByDistributionStatus);
+
+ secureServices.setServices(servicesWithTemplatesIndication);
secureServices.setReadOnly(roleProvider.userPermissionIsReadOnly(roles));
+
return secureServices;
}
diff --git a/vid-app-common/src/test/java/org/onap/vid/controller/VidControllerTest.java b/vid-app-common/src/test/java/org/onap/vid/controller/VidControllerTest.java
index 484f4a034..da91edb5f 100644
--- a/vid-app-common/src/test/java/org/onap/vid/controller/VidControllerTest.java
+++ b/vid-app-common/src/test/java/org/onap/vid/controller/VidControllerTest.java
@@ -21,9 +21,27 @@
package org.onap.vid.controller;
+import static java.util.stream.Collectors.toMap;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.nullValue;
+import static org.hamcrest.Matchers.not;
+import static org.mockito.BDDMockito.given;
+import static org.mockito.BDDMockito.then;
+import static org.mockito.Mockito.times;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
+import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
+import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
+
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
+import java.util.List;
+import java.util.Map;
+import java.util.UUID;
+import java.util.stream.IntStream;
+import javax.ws.rs.core.MediaType;
import org.apache.log4j.BasicConfigurator;
import org.junit.Assert;
import org.junit.Before;
@@ -35,35 +53,24 @@ import org.mockito.junit.MockitoJUnitRunner;
import org.onap.vid.asdc.AsdcCatalogException;
import org.onap.vid.asdc.beans.SecureServices;
import org.onap.vid.asdc.beans.Service;
-import org.onap.vid.model.*;
+import org.onap.vid.model.CR;
+import org.onap.vid.model.Network;
+import org.onap.vid.model.Node;
import org.onap.vid.model.PombaInstance.PombaRequest;
import org.onap.vid.model.PombaInstance.ServiceInstance;
+import org.onap.vid.model.ServiceModel;
+import org.onap.vid.model.ServiceProxy;
+import org.onap.vid.model.VNF;
+import org.onap.vid.model.VfModule;
+import org.onap.vid.model.VolumeGroup;
import org.onap.vid.roles.RoleProvider;
import org.onap.vid.services.AaiService;
+import org.onap.vid.services.InstantiationTemplatesService;
import org.onap.vid.services.PombaService;
import org.onap.vid.services.VidService;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
-import javax.ws.rs.core.MediaType;
-import java.util.List;
-import java.util.Map;
-import java.util.UUID;
-import java.util.stream.IntStream;
-
-import static java.util.stream.Collectors.toMap;
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.hamcrest.CoreMatchers.is;
-import static org.hamcrest.CoreMatchers.nullValue;
-import static org.hamcrest.Matchers.not;
-import static org.mockito.BDDMockito.given;
-import static org.mockito.BDDMockito.then;
-import static org.mockito.Mockito.times;
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
-import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
-import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
-
@RunWith(MockitoJUnitRunner.class)
public class VidControllerTest {
@@ -79,6 +86,8 @@ public class VidControllerTest {
private RoleProvider roleProvider;
@Mock
private PombaService pombaService;
+ @Mock
+ private InstantiationTemplatesService instantiationTemplatesService;
private VidController vidController;
private MockMvc mockMvc;
@@ -90,7 +99,7 @@ public class VidControllerTest {
@Before
public void setUp() {
- vidController = new VidController(vidService, aaiService, roleProvider, pombaService);
+ vidController = new VidController(vidService, aaiService, roleProvider, pombaService, instantiationTemplatesService);
BasicConfigurator.configure();
mockMvc = MockMvcBuilders.standaloneSetup(vidController).build();
objectMapper = new ObjectMapper();
@@ -102,12 +111,17 @@ public class VidControllerTest {
@Test
public void getServices_shouldReturnService_whenServiceExists() throws Exception {
- List<Service> services = ImmutableList.of(createService(uuid1, 1), createService(uuid2, 2), createService(uuid3, 3));
+ List<Service> services1 = ImmutableList.of(createService(uuid1, 1), createService(uuid2, 2), createService(uuid3, 3));
+ List<Service> services2 = ImmutableList.of(createService(uuid1, 4), createService(uuid2, 5), createService(uuid3, 6));
+
+ given(aaiService.getServicesByDistributionStatus())
+ .willReturn(services1);
- given(aaiService.getServicesByDistributionStatus()).willReturn(services);
+ given(instantiationTemplatesService.setOnEachServiceIsTemplateExists(services1))
+ .willReturn(services2);
SecureServices secureServices = new SecureServices();
- secureServices.setServices(services);
+ secureServices.setServices(services2);
secureServices.setReadOnly(false);
mockMvc.perform(get(REST_MODELS_SERVICES)