Support deletion of archived services in SDC BE
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / components / BaseServiceBusinessLogicTest.java
index 20f7f18..692e8cc 100644 (file)
+/*-
+ * ============LICENSE_START=======================================================
+ * SDC
+ * ================================================================================
+ * Copyright (C) 2017 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=========================================================
+ * Modifications copyright (c) 2019 Nokia
+ * ================================================================================
+ */
 package org.openecomp.sdc.be.components;
 
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.when;
+
 import com.google.common.collect.Sets;
 import fj.data.Either;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import javax.servlet.ServletContext;
 import org.junit.Before;
 import org.mockito.Mockito;
 import org.openecomp.sdc.ElementOperationMock;
 import org.openecomp.sdc.be.auditing.impl.AuditingManager;
+import org.openecomp.sdc.be.components.distribution.engine.IDistributionEngine;
 import org.openecomp.sdc.be.components.impl.ArtifactsBusinessLogic;
+import org.openecomp.sdc.be.components.impl.ComponentInstanceBusinessLogic;
 import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
 import org.openecomp.sdc.be.components.impl.ServiceBusinessLogic;
-import org.openecomp.sdc.be.components.impl.ServiceBusinessLogicTest;
 import org.openecomp.sdc.be.components.impl.generic.GenericTypeBusinessLogic;
-import org.openecomp.sdc.be.config.ConfigurationManager;
+import org.openecomp.sdc.be.components.path.ForwardingPathValidator;
+import org.openecomp.sdc.be.components.utils.ComponentBusinessLogicMock;
+import org.openecomp.sdc.be.components.validation.ServiceDistributionValidation;
 import org.openecomp.sdc.be.dao.api.ActionStatus;
 import org.openecomp.sdc.be.dao.cassandra.AuditCassandraDao;
-import org.openecomp.sdc.be.dao.jsongraph.TitanDao;
+import org.openecomp.sdc.be.dao.janusgraph.JanusGraphDao;
+import org.openecomp.sdc.be.datamodel.utils.UiComponentDataConverter;
 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathDataDefinition;
 import org.openecomp.sdc.be.datatypes.elements.ForwardingPathElementDataDefinition;
 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
 import org.openecomp.sdc.be.impl.ComponentsUtils;
 import org.openecomp.sdc.be.impl.WebAppContextWrapper;
-import org.openecomp.sdc.be.model.*;
+import org.openecomp.sdc.be.model.ArtifactDefinition;
+import org.openecomp.sdc.be.model.Component;
+import org.openecomp.sdc.be.model.ComponentInstance;
+import org.openecomp.sdc.be.model.GroupInstance;
+import org.openecomp.sdc.be.model.Resource;
+import org.openecomp.sdc.be.model.Service;
+import org.openecomp.sdc.be.model.User;
 import org.openecomp.sdc.be.model.category.CategoryDefinition;
-import org.openecomp.sdc.be.model.jsontitan.operations.ForwardingPathOperation;
-import org.openecomp.sdc.be.model.jsontitan.operations.ToscaOperationFacade;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ForwardingPathOperation;
+import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
 import org.openecomp.sdc.be.model.operations.api.IElementOperation;
 import org.openecomp.sdc.be.model.operations.api.StorageOperationStatus;
-import org.openecomp.sdc.be.model.operations.impl.CacheMangerOperation;
 import org.openecomp.sdc.be.model.operations.impl.GraphLockOperation;
+import org.openecomp.sdc.be.model.operations.impl.ModelOperation;
 import org.openecomp.sdc.be.resources.data.auditing.ResourceAdminEvent;
 import org.openecomp.sdc.be.user.Role;
 import org.openecomp.sdc.be.user.UserBusinessLogic;
 import org.openecomp.sdc.common.api.ArtifactGroupTypeEnum;
-import org.openecomp.sdc.common.api.ConfigurationSource;
 import org.openecomp.sdc.common.api.Constants;
 import org.openecomp.sdc.common.datastructure.AuditingFieldsKey;
 import org.openecomp.sdc.common.impl.ExternalConfiguration;
-import org.openecomp.sdc.common.impl.FSConfigurationSource;
 import org.springframework.web.context.WebApplicationContext;
 
-import javax.servlet.ServletContext;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import static org.mockito.ArgumentMatchers.any;
-import static org.mockito.Mockito.when;
-
-public abstract class BaseServiceBusinessLogicTest {
+public abstract class BaseServiceBusinessLogicTest extends ComponentBusinessLogicMock {
     private static final String SERVICE_CATEGORY = "Mobility";
-    final ServletContext servletContext = Mockito.mock(ServletContext.class);
-    UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
-    WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
-    WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
-    ServiceBusinessLogic bl = new ServiceBusinessLogic();
-    ResponseFormatManager responseManager = null;
-    IElementOperation mockElementDao;
-    ComponentsUtils componentsUtils;
-    AuditCassandraDao auditingDao = Mockito.mock(AuditCassandraDao.class);
-    ArtifactsBusinessLogic artifactBl = Mockito.mock(ArtifactsBusinessLogic.class);
-    GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
-    TitanDao mockTitanDao = Mockito.mock(TitanDao.class);
-    ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
-    CacheMangerOperation cacheManager = Mockito.mock(CacheMangerOperation.class);
-    GenericTypeBusinessLogic genericTypeBusinessLogic = Mockito.mock(GenericTypeBusinessLogic.class);
-    ForwardingPathOperation forwardingPathOperation  = Mockito.mock(ForwardingPathOperation.class);
+    private final ServletContext servletContext = Mockito.mock(ServletContext.class);
+    private UserBusinessLogic mockUserAdmin = Mockito.mock(UserBusinessLogic.class);
+    private WebAppContextWrapper webAppContextWrapper = Mockito.mock(WebAppContextWrapper.class);
+    private WebApplicationContext webAppContext = Mockito.mock(WebApplicationContext.class);
+    protected final IDistributionEngine distributionEngine = Mockito.mock(IDistributionEngine.class);
+    protected final ComponentInstanceBusinessLogic componentInstanceBusinessLogic = Mockito.mock(ComponentInstanceBusinessLogic.class);
+    protected final ServiceDistributionValidation serviceDistributionValidation = Mockito.mock(ServiceDistributionValidation.class);
+    protected final ForwardingPathValidator forwardingPathValidator = Mockito.mock(ForwardingPathValidator.class);
+    protected final UiComponentDataConverter uiComponentDataConverter = Mockito.mock(UiComponentDataConverter.class);
+    private ServiceBusinessLogic bl;
+    private ResponseFormatManager responseManager = null;
+    private IElementOperation mockElementDao;
+    private ComponentsUtils componentsUtils;
+    private AuditCassandraDao auditingDao = Mockito.mock(AuditCassandraDao.class);
+    private ArtifactsBusinessLogic artifactBl = Mockito.mock(ArtifactsBusinessLogic.class);
+    private GraphLockOperation graphLockOperation = Mockito.mock(GraphLockOperation.class);
+    private JanusGraphDao mockJanusGraphDao = Mockito.mock(JanusGraphDao.class);
+    private ToscaOperationFacade toscaOperationFacade = Mockito.mock(ToscaOperationFacade.class);
+    private GenericTypeBusinessLogic genericTypeBusinessLogic = Mockito.mock(GenericTypeBusinessLogic.class);
+    private ForwardingPathOperation forwardingPathOperation  = Mockito.mock(ForwardingPathOperation.class);
+    private final ModelOperation modelOperation = Mockito.mock(ModelOperation.class);
 
     User user = null;
     Service serviceResponse = null;
@@ -83,10 +116,6 @@ public abstract class BaseServiceBusinessLogicTest {
     public void setup() {
 
         ExternalConfiguration.setAppName("catalog-be");
-        // init Configuration
-        String appConfigDir = "src/test/resources/config/catalog-be";
-        ConfigurationSource configurationSource = new FSConfigurationSource(ExternalConfiguration.getChangeListener(), appConfigDir);
-        ConfigurationManager configurationManager = new ConfigurationManager(configurationSource);
         componentsUtils = new ComponentsUtils(Mockito.mock(AuditingManager.class));
 
         // Elements
@@ -99,11 +128,11 @@ public abstract class BaseServiceBusinessLogicTest {
         user.setLastName("Hendrix");
         user.setRole(Role.ADMIN.name());
 
-        Either<User, ActionStatus> eitherGetUser = Either.left(user);
-        when(mockUserAdmin.getUser("jh0003", false)).thenReturn(eitherGetUser);
+        when(mockUserAdmin.getUser("jh0003", false)).thenReturn(user);
 
         // Servlet Context attributes
         when(servletContext.getAttribute(Constants.CONFIGURATION_MANAGER_ATTR)).thenReturn(configurationManager);
+//        when(servletContext.getAttribute(Constants.SERVICE_OPERATION_MANAGER)).thenReturn(new ServiceOperation());
         when(servletContext.getAttribute(Constants.WEB_APPLICATION_CONTEXT_WRAPPER_ATTR)).thenReturn(webAppContextWrapper);
         when(webAppContextWrapper.getWebAppContext(servletContext)).thenReturn(webAppContext);
         when(webAppContext.getBean(IElementOperation.class)).thenReturn(mockElementDao);
@@ -133,17 +162,20 @@ public abstract class BaseServiceBusinessLogicTest {
         when(forwardingPathOperation.deleteForwardingPath(any(),any())).thenReturn(Either.left(Sets.newHashSet("Wow-It-Works")));
         when(toscaOperationFacade.getToscaElement("delete_forward_test")).thenReturn(Either.left(createServiceObject(true)));
 
-        bl = new ServiceBusinessLogic();
-        bl.setElementDao(mockElementDao);
+        bl = new ServiceBusinessLogic(elementDao, groupOperation, groupInstanceOperation,
+            groupTypeOperation, groupBusinessLogic, interfaceOperation, interfaceLifecycleTypeOperation,
+            artifactsBusinessLogic, distributionEngine, componentInstanceBusinessLogic,
+            serviceDistributionValidation, forwardingPathValidator, uiComponentDataConverter,
+            artifactToscaOperation, componentContactIdValidator, componentNameValidator,
+            componentTagsValidator, componentValidator, componentIconValidator, componentProjectCodeValidator, componentDescriptionValidator,
+            modelOperation);
         bl.setUserAdmin(mockUserAdmin);
-        bl.setArtifactBl(artifactBl);
         bl.setGraphLockOperation(graphLockOperation);
-        bl.setTitanGenericDao(mockTitanDao);
+        bl.setJanusGraphDao(mockJanusGraphDao);
         bl.setToscaOperationFacade(toscaOperationFacade);
         bl.setGenericTypeBusinessLogic(genericTypeBusinessLogic);
         bl.setComponentsUtils(componentsUtils);
         bl.setCassandraAuditingDao(auditingDao);
-        bl.setCacheManagerOperation(cacheManager);
         bl.setForwardingPathOperation(forwardingPathOperation);
         bl.setToscaOperationFacade(toscaOperationFacade);
         mockAuditingDaoLogic();
@@ -198,8 +230,10 @@ public abstract class BaseServiceBusinessLogicTest {
         createResourceAudit.setStatus("201");
         createResourceAudit.setPrevVersion("");
         createResourceAudit.setAction("Create");
+        // fields.put("TIMESTAMP", "2015-11-22 09:19:12.977");
         createResourceAudit.setPrevState("");
         createResourceAudit.setResourceName("MyTestResource");
+        // createResourceAudit.setFields(fields);
 
         final ResourceAdminEvent checkInResourceAudit = new ResourceAdminEvent();
         checkInResourceAudit.setModifier("Carlos Santana(cs0008)");
@@ -213,6 +247,7 @@ public abstract class BaseServiceBusinessLogicTest {
         checkInResourceAudit.setStatus("200");
         checkInResourceAudit.setPrevVersion("0.1");
         checkInResourceAudit.setAction("Checkin");
+        // fields.put("TIMESTAMP", "2015-11-22 09:25:03.797");
         checkInResourceAudit.setPrevState("NOT_CERTIFIED_CHECKOUT");
         checkInResourceAudit.setResourceName("MyTestResource");
 
@@ -228,8 +263,11 @@ public abstract class BaseServiceBusinessLogicTest {
         checkOutResourceAudit.setStatus("200");
         checkOutResourceAudit.setPrevVersion("0.1");
         checkOutResourceAudit.setAction("Checkout");
+        // fields.put("TIMESTAMP", "2015-11-22 09:39:41.024");
         checkOutResourceAudit.setPrevState("NOT_CERTIFIED_CHECKIN");
         checkOutResourceAudit.setResourceName("MyTestResource");
+        // checkOutResourceAudit.setFields(fields);
+
         List<ResourceAdminEvent> list = new ArrayList<ResourceAdminEvent>() {
             {
                 add(createResourceAudit);
@@ -251,6 +289,7 @@ public abstract class BaseServiceBusinessLogicTest {
         };
         Either<List<ResourceAdminEvent>, ActionStatus> resultCurr = Either.left(listCurr);
         Mockito.when(auditingDao.getAuditByServiceIdAndCurrVersion(Mockito.anyString(), Mockito.anyString())).thenReturn(resultCurr);
+
     }
 
     protected Service createServiceObject(boolean afterCreate) {
@@ -266,7 +305,10 @@ public abstract class BaseServiceBusinessLogicTest {
         List<String> tgs = new ArrayList<>();
         tgs.add(service.getName());
         service.setTags(tgs);
+        // service.setVendorName("Motorola");
+        // service.setVendorRelease("1.0.0");
         service.setIcon("MyIcon");
+        // service.setState(LifecycleStateEnum.NOT_CERTIFIED_CHECKOUT);
         service.setContactId("aa1234");
         service.setProjectCode("12345");